Skip to content

Instantly share code, notes, and snippets.

@Tushar-N
Tushar-N / click_heatmap.py
Last active March 24, 2022 14:11
Click on an image to superimpose a heatmap
import cv2
import numpy as np
import argparse
'''
usage: python click_heatmap.py <image file>
left-click: add point to heatmap
s: save image (000.png, 001.png, ...)
q: quit
r: reset
@Tushar-N
Tushar-N / hook_activations.py
Created August 3, 2018 00:06
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)]
@duhaime
duhaime / measure_img_similarity.py
Last active March 1, 2023 08:41
Compare image similarity in Python using Structural Similarity, Pixel Comparisons, Wasserstein Distance (Earth Mover's Distance), and SIFT
import warnings
from skimage.measure import compare_ssim
from skimage.transform import resize
from scipy.stats import wasserstein_distance
from scipy.misc import imsave
from scipy.ndimage import imread
import numpy as np
import cv2
##

Papers from Super SloMo references

  • Super SloMo: High Quality Estimation of Multiple Intermediate Frames for Video Interpolation [Paper]
    • Huaizu Jiang, Deqing Sun, Varun Jampani, Ming-Hsuan Yang, Erik Learned-Miller, Jan Kautz
    • CVPR 2018 (splotlight)
  • Video frame synthesis using deep voxel flow [Paper] [Code]
    • Z. Liu, R. Yeh, X. Tang, Y. Liu, and A. Agarwala.
    • ICCV 2017
  • Video frame interpolation via adaptive separable convolution. [Paper] [Code]
@huatangzhi
huatangzhi / get_cars_stanford.py
Created March 18, 2018 04:08 — forked from beeva-albertorincon/get_cars_stanford.py
Stanford cars dataset extraction
# encoding:utf8
from scipy.io import loadmat
import pandas as pd
import numpy as np
mat_train = loadmat('devkit/cars_train_annos.mat')
mat_test = loadmat('devkit/cars_test_annos.mat')
meta = loadmat('devkit/cars_meta.mat')
## GOAL:
## re-create a figure similar to Fig. 2 in Wilson et al. (2018),
## Nature 554: 183-188. Available from:
## https://www.nature.com/articles/nature25479#s1
##
## combines a boxplot (or violin) with the raw data, by splitting each
## category location in two (box on left, raw data on right)
# initial set-up ----------------------------------------------------------
@peteflorence
peteflorence / pytorch_bilinear_interpolation.md
Last active January 16, 2024 14:18
Bilinear interpolation in PyTorch, and benchmarking vs. numpy

Here's a simple implementation of bilinear interpolation on tensors using PyTorch.

I wrote this up since I ended up learning a lot about options for interpolation in both the numpy and PyTorch ecosystems. More generally than just interpolation, too, it's also a nice case study in how PyTorch magically can put very numpy-like code on the GPU (and by the way, do autodiff for you too).

For interpolation in PyTorch, this open issue calls for more interpolation features. There is now a nn.functional.grid_sample() feature but at least at first this didn't look like what I needed (but we'll come back to this later).

In particular I wanted to take an image, W x H x C, and sample it many times at different random locations. Note also that this is different than upsampling which exhaustively samples and also doesn't give us fle

@jdhao
jdhao / calculate_trainset_mean_std.py
Last active September 20, 2023 06:36
This snippet will calculate the per-channel image mean and std in the train image set. It is plain simple and may not be efficient for large scale dataset.
"""
in this script, we calculate the image per channel mean and standard
deviation in the training set, do not calculate the statistics on the
whole dataset, as per here http://cs231n.github.io/neural-networks-2/#datapre
"""
import numpy as np
from os import listdir
from os.path import join, isdir
from glob import glob
@rajshah4
rajshah4 / Quickdraw_to_MNISTformat.ipynb
Created July 14, 2017 20:28
Quickdraw npy files to MNIST test/train dataset with visualization
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shgidi
shgidi / plot_loss+sample.py
Created July 12, 2017 10:30
plots loss in keras, additionally plots segmentation in image
#https://gist.github.com/stared/dfb4dfaf6d9a8501cd1cc8b8cb806d2e
class PlotLosses(keras.callbacks.Callback):
def __init__(self,imgs):
super(PlotLosses, self).__init__()
self.imgs=imgs
def on_train_begin(self, logs={}):
self.i = 0
self.x = []