Skip to content

Instantly share code, notes, and snippets.

View achalddave's full-sized avatar

Achal Dave achalddave

View GitHub Profile
@achalddave
achalddave / patch_clip_model.sh
Last active April 27, 2022 06:37
Patch CLIP models to work with torch versions before 1.7
#!/bin/bash
###
# Patch CLIP models to work with PyTorch versions before 1.7.
# This script was tested with PyTorch 1.6 and CUDA 9.2 on the RN-50 and ViT-B-32 models.
###
if [[ "$#" != 1 ]] ; then
echo "Usage: $0 <clip-model-pt>"
echo "Example: $0 $HOME/.cache/clip/RN50.pt"
exit 1
{"id": "lvis", "name": "LVIS", "children": [{"id": 1, "name": "entity.n.01", "children": [{"id": 194, "name": "physical_entity.n.01", "children": [{"id": 459, "name": "object.n.01", "children": [{"id": 2018, "name": "part.n.02", "children": [{"id": 1584, "name": "piece_of_cloth.n.01", "children": [{"id": 1590, "name": "sail.n.01", "children": []}, {"id": 1585, "name": "towel.n.01", "children": [{"id": 508, "name": "bath_towel.n.01", "children": []}, {"id": 1588, "name": "paper_towel.n.01", "children": []}, {"id": 1587, "name": "hand_towel.n.01", "children": []}, {"id": 1586, "name": "dishtowel.n.01", "children": []}]}, {"id": 1592, "name": "bandanna.n.01", "children": []}, {"id": 1589, "name": "dishrag.n.01", "children": []}]}, {"id": 2028, "name": "doorknob.n.01", "children": []}, {"id": 2024, "name": "wall_socket.n.01", "children": []}]}, {"id": 460, "name": "whole.n.02", "children": [{"id": 1986, "name": "natural_object.n.01", "children": [{"id": 2017, "name": "nest.n.01", "children": []}, {"id": 1991, "na
@achalddave
achalddave / main.py
Last active February 13, 2018 01:55
Argparse load config from file
"""Use argparse to load arguments from file before command line.
MIT License
Copyright (c) 2018 Achal Dave
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@achalddave
achalddave / flop_computation_network.ipynb
Created October 11, 2017 18:35
Compute number of flops in a CNN
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@achalddave
achalddave / maptable_clearstate_bug.lua
Created February 20, 2017 17:20
Displays memory 'leak' with nn.MapTable after call to clearState()
--[[ Displays memory 'leak' with nn.MapTable after clearState() ]]--
local nn = require 'nn'
local cunn = require 'cunn'
model = nn.MapTable():add(nn.SpatialConvolution(3, 256, 3, 3, 1, 1, 1, 1, 1))
:cuda()
i = {torch.rand(30, 3, 224, 224):cuda(), torch.rand(30, 3, 224, 224):cuda()}
function check_mem() os.execute('nvidia-smi | grep luajit') end

The default yaml library in lua does not handle YAML booleans correctly.

/tmp ~ th

  ______             __   |  Torch7
 /_  __/__  ________/ /   |  Scientific computing for Lua.
  / / / _ \/ __/ __/ _ \  |  Type ? for help
 /_/  \___/_/  \__/_//_/  |  https://github.com/torch
 | http://torch.ch
@achalddave
achalddave / lyaml-null.md
Last active October 7, 2016 16:34
lyaml library parses null in yaml as a string. See https://github.com/gvvaughan/lyaml/issues/13 for discussion
th> lyaml = require 'lyaml'
                                                                      [0.0016s]
th> out = lyaml.load('key: null')
                                                                      [0.0002s]
th> out.key
null
                                                                      [0.0000s]
th> type(out.key)
string
@achalddave
achalddave / config.log
Last active October 7, 2016 16:20
./configure error for lyaml. See https://github.com/gvvaughan/lyaml/issues/11 for discussion.
configure:13020: checking for yaml.h
configure:13020: result: yes
configure:13032: checking for library containing yaml_document_initialize
configure:13063: gcc -o conftest -g -O2 -I/home/achald/.local/yaml-0.1.7/include -L/home/achald/.local/yaml-0.1.7/lib conftest.c >&5
/tmp/ccmoDgR2.o: In function `main':
/home/achald/scratch/lyaml/lyaml-release-v6.0/conftest.c:36: undefined reference to `yaml_document_initialize'
collect2: error: ld returned 1 exit status
configure:13063: $? = 1
configure: failed program was:
| /* confdefs.h */
--- test_01.lst 2016-09-09 09:31:06.640048422 -0400
+++ test_01_filtered.lst 2016-09-09 16:04:00.939637895 -0400
@@ -526,7 +526,6 @@
/data/achald/UCF101/frames_all/v_ApplyLipstick_g02_c01/ 65 1
/data/achald/UCF101/frames_all/v_ApplyLipstick_g02_c01/ 81 1
/data/achald/UCF101/frames_all/v_ApplyLipstick_g02_c01/ 97 1
-/data/achald/UCF101/frames_all/v_ApplyLipstick_g02_c01/ 113 1
/data/achald/UCF101/frames_all/v_ApplyLipstick_g02_c02/ 1 1
/data/achald/UCF101/frames_all/v_ApplyLipstick_g02_c02/ 17 1
/data/achald/UCF101/frames_all/v_ApplyLipstick_g02_c02/ 33 1
@achalddave
achalddave / test.lua
Last active September 6, 2016 15:05
-- Exhibits differences between torch's image.scale and opencv's resize
-- function.
local cv = require 'cv' -- https://github.com/VisionLabs/torch-opencv
require 'cv.imgcodecs'
require 'cv.imgproc'
require 'image'
local path = './foobar.png'
-- RGB, shape channels * height * width