Skip to content

Instantly share code, notes, and snippets.

Tushar Nagarajan Tushar-N

Block or report user

Report or block Tushar-N

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Tushar-N
Tushar-N / csub.sh
Last active Feb 20, 2018
Condor submit script: use csub <cmd> from a submit node
View csub.sh
cmd=$@
# find the location to save files to
cv_dir=`expr "$cmd" : '.*--cv_dir \([^ ]*\).*'`
# make cv_dir and create two files: submit.sh and run.sh
mkdir $cv_dir
cat > $cv_dir/submit.sh << EOF
universe = vanilla
@Tushar-N
Tushar-N / click_heatmap.py
Created Oct 10, 2018
Click on an image to superimpose a heatmap
View click_heatmap.py
import cv2
import numpy as np
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--img', default='image.jpg')
args = parser.parse_args()
def collect_clicks(event, x, y, flags, param):
global points
@Tushar-N
Tushar-N / jpeg_to_h5.py
Created Apr 26, 2019
Save jpeg images as compressed binary data, instead of a dense (C, H, W) uint8 tensor.
View jpeg_to_h5.py
import torch
import io
from PIL import Image
import numpy as np
# Dataset class for extracting binary data from images to store
class ImageDataset:
def __init__(self):
super(ImageDataset, self).__init__()
self.images = [] # some list of PIL images
@Tushar-N
Tushar-N / hook_activations.py
Created Aug 3, 2018
Pytorch code to save activations for specific layers over an entire dataset
View hook_activations.py
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as tmodels
from functools import partial
import collections
# dummy data: 10 batches of images with batch size 16
dataset = [torch.rand(16,3,224,224).cuda() for _ in range(10)]
@Tushar-N
Tushar-N / pad_packed_demo.py
Last active Aug 20, 2019
How to use pad_packed_sequence in pytorch
View pad_packed_demo.py
import torch
import torch.nn as nn
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
seqs = ['gigantic_string','tiny_str','medium_str']
# make <pad> idx 0
vocab = ['<pad>'] + sorted(set(''.join(seqs)))
# make model
You can’t perform that action at this time.