Skip to content

Instantly share code, notes, and snippets.

@eminorhan
eminorhan / pytorch_multinode_slurm.md
Last active May 7, 2021 09:19
A minimal example demonstrating how to do multi-node distributed training with pytorch on a slurm cluster

The following code is intentionally skeletal. Please feel free to flesh out the details according to your own needs.

import os
import builtins
import argparse
import torch
import torch.distributed as dist
from torchvision.datasets import ImageFolder
from torch.utils.data import DataLoader
@eminorhan
eminorhan / untar_each_to_its_own.sh
Last active May 11, 2021 15:19
(1) go through all tar files in a directory, (2) untar them to their own subdirectory, (3) delete the tar file
for a in `ls -1 *.tar`; do mkdir ${a%.*}; tar -xf $a -C ${a%.*}; rm -f $a; done &
@eminorhan
eminorhan / wget_txt.sh
Last active September 28, 2021 18:19
download all urls in a txt file
wget -i filename.txt
@eminorhan
eminorhan / cocoapi.py
Last active October 8, 2021 16:34
COCO-API cheat sheet
from pycocotools.coco import COCO
import numpy as np
dataDir = '/home/emin/coco'
dataType = 'val2017'
annFile = '{}/annotations/instances_{}.json'.format(dataDir, dataType)
coco = COCO(annFile) # build COCO object
catIds = coco.getCatIds() # category ids (80)
@eminorhan
eminorhan / read_videos.sh
Created November 22, 2021 20:03
Read videos without interruption
nohup python -u /misc/vlgscratch5/LakeGroup/emin/sayavakepicut/read_video.py --save-dir '/misc/vlgscratch5/LakeGroup/emin/sayavakepicut/5fps_300s/ava_trainval' --fps 5 --seg-len 300 '/misc/vlgscratch5/LakeGroup/shared_data/ava_v2/trainval' &
@eminorhan
eminorhan / del_checkpoint.py
Last active January 13, 2022 16:40
delete large memory checkpoint after loading in pytorch
checkpoint = torch.load(CHECKPOINT_PATH)
model.module.load_state_dict(checkpoint['model_state_dict'])
del checkpoint
torch.cuda.empty_cache()
@eminorhan
eminorhan / count_files.sh
Created February 9, 2022 17:58
count files in current directory
ls -1 | wc -l
@eminorhan
eminorhan / git_repo.sh
Created March 2, 2022 22:07
new github repo
git init
git add . && git commit -m "first commit"
git remote add origin REMOTE_GITHUB_REPO_URL
git remote -v
git push origin master
@eminorhan
eminorhan / nohup2.sh
Created June 21, 2022 00:22
pipe nohup output to a file with given name instead of deault nohup.out
nohup python -u script.py &> nohup2.out &
@eminorhan
eminorhan / count_in_tar.sh
Created September 29, 2022 18:06
count number of files in a tar archive without extracting
tar -tf archive.tar | wc -l