Skip to content

Instantly share code, notes, and snippets.

@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
##
@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)]
@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