Skip to content

Instantly share code, notes, and snippets.

View rohit-gupta's full-sized avatar

Rohit Gupta rohit-gupta

View GitHub Profile
@rohit-gupta
rohit-gupta / shrink_loss.py
Created February 19, 2024 19:46
Shrinkmatch loss
def shrink_loss(pseudo_label, logits_u_s, conf_thresh):
removed_class_idx = []
loss_u_shrink_batch = 0
B, C = pseudo_label.shape
max_probs = pseudo_label.max(dim=-1)[0]
mask = pseudo_label.ge(conf_thresh).float()
sorted_prob_w, sorted_idx = pseudo_label.topk(C, dim=-1, sorted=True)
ps -AF | grep ssh
pkill -t pts/9
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match <$URL$>
// @icon <$ICON$>
// @grant none
// ==/UserScript==
@rohit-gupta
rohit-gupta / dump_photoid_text.sql
Last active March 1, 2023 05:13
dump photoid, url, title and description from yfcc100m metadata file
.open yfcc100m_dataset.sql
.databases
.tables
.schema yfcc100m_dataset
SELECT * from yfcc100m_dataset WHERE photoid=2932067831 LIMIT 1;
.mode csv
.headers on
.out yfcc100m_dump.csv
SELECT photoid, title, description, downloadurl FROM yfcc100m_dataset;
def var_covar_loss(Z, alpha=1.0, beta=0.01):
eps = 1e-5
K = z.shape[1]
# covariance matrix
C = torch.cov(Z.t())
# Push sqrt of diagonal terms to 1 (std dev = 1.0)
@rohit-gupta
rohit-gupta / kinetics_crawler.sh
Last active May 22, 2020 00:30
Downloads Kinetics 700
#!/bin/bash
# TODO might be more missing packages
# TODO Shard train set
# Install dependencies
cd /tmp
wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh
bash Anaconda3-2020.02-Linux-x86_64.sh -b -p $HOME/anaconda3
@rohit-gupta
rohit-gupta / gradient_reversal.py
Created April 7, 2020 20:21
Reverse Gradients in PyTorch
from torch.autograd import Function
class GradientReversal(Function):
@staticmethod
def forward(ctx, x):
ctx.save_for_backward(x)
output = x
return output
@rohit-gupta
rohit-gupta / install_apex.sh
Created December 2, 2019 18:07
Install Nvidia Apex library
# Pascal Titan X, Titan Xp, 1080Ti, 1080, 1070Ti, 1070 ... = 6.1
# Volta Titan V = 7.0
# Turing Titan RTX, 2080Ti ... = 7.5
export TORCH_CUDA_ARCH_LIST="6.1;7.0;7.5" # Pascal, Volta and Turing on CRCV Cluster
git clone https://github.com/NVIDIA/apex
cd apex
pip install --upgrade --force-reinstall -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
@rohit-gupta
rohit-gupta / india_major_cities_constituencies.csv
Last active May 1, 2019 19:06
List of Lok Sabha consituencies in each major Indian city
City State Constituency
Mumbai Maharashtra Bhiwandi
Mumbai Maharashtra Kalyan
Mumbai Maharashtra Thane
Mumbai Maharashtra Mumbai North
Mumbai Maharashtra Mumbai North West
Mumbai Maharashtra Mumbai North East
Mumbai Maharashtra Mumbai North Central
Mumbai Maharashtra Mumbai South Central
Mumbai Maharashtra Mumbai South
@rohit-gupta
rohit-gupta / tf_limit_gpu_memory.py
Created February 8, 2019 09:34
Limit GPU memory usage in Keras
import tensorflow as tf
import keras.backend as K
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.25)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
K.set_session(sess)
## Use normally after this