Skip to content

Instantly share code, notes, and snippets.

View pbamotra's full-sized avatar
🎯
Focusing

Pankesh Bamotra pbamotra

🎯
Focusing
View GitHub Profile
@pbamotra
pbamotra / iclr-2020-favorites-pbamotra.txt
Last active April 26, 2020 03:15
ICLR 2020 Favorites - WIP
Calendar: https://iclr.cc/virtual/calendar.html#tab-calendar
Paper search: https://iclr.cc/virtual/papers.html?filter=keywords
Papers:
1. Title:
Tree-Structured Attention with Hierarchical Accumulation
Authority:
Richard Socher
Url:
https://iclr.cc/virtual/poster_HJxK5pEYvr.html
@pbamotra
pbamotra / save-code-to-tarball.py
Last active March 7, 2020 12:35
Save code snapshot to tar file
# Source: https://github.com/opencv/openvino_training_extensions/blob/develop/pytorch_toolkit/nncf/examples/common/utils.py#L86
import tarfile
from pathlib import Path
def create_code_snapshot(root, dst_path, extensions=(".py", ".json", ".cpp", ".cu")):
"""Creates tarball with the source code"""
with tarfile.open(str(dst_path), "w:gz") as tar:
for path in Path(root).rglob("*"):
@pbamotra
pbamotra / dali-1.7.py
Created July 3, 2019 21:13
DALI Post-1.7
from nvidia.dali.plugin.pytorch import DALIGenericIterator
pipe = ExternalSourcePipeline(data_iterator=iterator, batch_size=16, num_threads=2, device_id=0)
pipe.build()
# first parameter is list of pipelines to run
# second pipeline is output_map that maps consecutive outputs to
# corresponding names
# last parameter is the number of iterations - number of examples you
# want to iterate on
@pbamotra
pbamotra / dali-1.6.py
Created July 3, 2019 21:12
DALI Post-1.6
eii = ExternalInputIterator(batch_size=16,
data_file=processed_data_file,
image_dir=images_directory)
iterator = iter(eii)
class ExternalSourcePipeline(Pipeline):
def __init__(self, data_iterator, batch_size, num_threads, device_id):
super(ExternalSourcePipeline, self).__init__(batch_size,
num_threads,
device_id,
@pbamotra
pbamotra / dali-1.5.py
Created July 3, 2019 21:11
DALI Post-1.5
import types
import numpy as np
import collections
import pandas as pd
from random import shuffle
import nvidia.dali.ops as ops
import nvidia.dali.types as types
from nvidia.dali.pipeline import Pipeline
@pbamotra
pbamotra / dali-1.4.py
Created July 3, 2019 21:10
DALI Post-1.4
from os import listdir
from os.path import isfile, join
images_directory = './flower_data/flower_data_flat'
# read names of all image files
image_files = [f for f in listdir(image_dir) if isfile(join(image_dir, f))]
# we create a data frame with the image names and dummy labels - label_1, label_2
data = pd.DataFrame(list(zip(image_files,
list(range(len(image_files))),
@pbamotra
pbamotra / dali-1.3.sh
Created July 3, 2019 21:09
DALI Post-1.3
$ wget -cq https://s3.amazonaws.com/content.udacity-data.com/courses/nd188/flower_data.zip \
&& unzip -qq flower_data.zip \
&& mkdir -p ./flower_data/flower_data_flat \
&& find ./flower_data/train -mindepth 2 -type f -exec mv -t ./flower_data/flower_data_flat -i '{}' +
@pbamotra
pbamotra / dali-1.2.sh
Created July 3, 2019 21:07
DALI Post-1.2
# Find out the cuda version so that we install appropriate DALI binaries
# Find installation instructions at
# https://github.com/NVIDIA/DALI#installing-prebuilt-dali-packages
$ nvcc --version
# sample output
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
@pbamotra
pbamotra / dali-1.1.py
Created July 3, 2019 21:00
DALI-Post-1.1
from torchvision import transforms
def get_image_transforms() -> transforms.Compose:
"""
These transformations meant for data augmentation are a bottleneck
since all the operations are done on CPU and then the tensors are
copied to the GPU device.
"""
return transforms.Compose([
transforms.RandomSizedCrop(224),
@pbamotra
pbamotra / sigsoftmax.py
Created April 10, 2019 04:08
Pytorch implementation of sigsoftmax - https://arxiv.org/pdf/1805.10829.pdf
def logsigsoftmax(logits):
"""
Computes sigsoftmax from the paper - https://arxiv.org/pdf/1805.10829.pdf
"""
max_values = torch.max(logits, 1, keepdim = True)[0]
exp_logits_sigmoided = torch.exp(logits - max_values) * torch.sigmoid(logits)
sum_exp_logits_sigmoided = exp_logits_sigmoided.sum(1, keepdim = True)
log_probs = logits - max_values + torch.log(torch.sigmoid(logits)) - torch.log(sum_exp_logits_sigmoided)
return log_probs