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 /
Created Apr 26, 2019
Save jpeg images as compressed binary data, instead of a dense (C, H, W) uint8 tensor.
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 /
Created Oct 10, 2018
Click on an image to superimpose a heatmap
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 /
Created Aug 3, 2018
Pytorch code to save activations for specific layers over an entire dataset
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 /
Last active Aug 28, 2019
Condor submit script: use csub <cmd> from a submit node
cv_dir=`expr "$cmd" : '.*--cv_dir \([^ ]*\).*'`
mkdir -p $cv_dir
# temporarily create two files: and
cat > $cv_dir/ << EOF
universe = vanilla
Executable = /lusr/bin/bash
Arguments = $cv_dir/
Tushar-N /
Last active Mar 24, 2020
How to use pad_packed_sequence in pytorch<1.1.0
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.