Skip to content

Instantly share code, notes, and snippets.

/train/n02112137/n02112137_3351.JPEG 96
/train/n02112137/n02112137_14715.JPEG 96
/train/n02112137/n02112137_8996.JPEG 96
/train/n02112137/n02112137_8952.JPEG 96
/train/n02112137/n02112137_482.JPEG 96
/train/n02112137/n02112137_2023.JPEG 96
/train/n02112137/n02112137_10146.JPEG 96
/train/n02112137/n02112137_13505.JPEG 96
/train/n02112137/n02112137_6212.JPEG 96
/train/n02112137/n02112137_9200.JPEG 96
@rahulvigneswaran
rahulvigneswaran / code-for-moving-average-of-a-tensor.ipynb
Created April 4, 2023 11:33
Code for moving average of a tensor.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rahulvigneswaran
rahulvigneswaran / python2vscode-debugger-args-converter.ipynb
Created March 20, 2023 07:42
python2vscode debugger args converter.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rahulvigneswaran
rahulvigneswaran / label_names_cifar100.py
Created March 20, 2023 05:02
Fine label names for cifar100 dataset
def fine_labels():
fine_labels = [
'apple', # id 0
'aquarium_fish',
'baby',
'bear',
'beaver',
'bed',
'bee',
'beetle',
@rahulvigneswaran
rahulvigneswaran / gpt3_generate.py
Created March 20, 2023 04:59
Routine to generate sentence based on a word. Uses GPT-3. Requires OpenAI's API.
# ========================================================================================================================
import openai
openai.api_key =
# ========================================================================================================================
# >>> len(a[31:60]), len(a[60:])
# (29, 40)
import os
from tqdm import tqdm, trange
@rahulvigneswaran
rahulvigneswaran / save_and_resume_pytorch_boilerplate.py
Created June 2, 2021 23:39
A boilerplate code to save models and resume from it incase the run crashes.
def save_latest(epoch, model_dir, model, optimizer, scheduler=None, wandb_id=None):
"""Saves latest epoch's weights and other necessary things to resume
"""
model_states = {
"epoch": epoch,
"state_dict": model.state_dict(),
"opt_state_dict": optimizer.state_dict(),
"sch_state_dict": scheduler.state_dict() if scheduler != None else None,
"wandb_id_save": wandb_id, #----> Remove this if you don't use wandb for logging
}
import torchvision
model_conv = torchvision.models.resnet18(pretrained=True)
for name, param in model_conv.named_parameters():
if not("fc" in name):
param.requires_grad = False
print(name, param.requires_grad)
@rahulvigneswaran
rahulvigneswaran / color_palatte.py
Created March 16, 2022 11:20
Nice color palattes for plotting
# From Polyfjord - https://youtu.be/Q9IRHmfGDrU?t=17
names = ["gold",
"chilli_pepper",
"crystal_blue",
"aquamarine",
"army_green",
"neon_yellow",
"caramel",
"pumpkin_orange",
@rahulvigneswaran
rahulvigneswaran / cifar100_fine_coarse_labels.py
Last active March 7, 2022 13:30 — forked from adam-dziedzic/cifar100_fine_coarse_labels.py
Mappings between fine (classes) and coarse labels (superclasses) for CIFAR100. Returns coarse2fine, fine2coarse mappings
import pprint as pp
fine_labels = [
'apple', # id 0
'aquarium_fish',
'baby',
'bear',
'beaver',
'bed',
'bee',