Skip to content

Instantly share code, notes, and snippets.

View nlml's full-sized avatar

Liam Schoneveld nlml

View GitHub Profile
def neg_squared_euc_dists_1(X):
sum_X = np.sum(np.square(X), 1)
D = np.add(np.add(-2 * np.dot(X, X.T), sum_X).T, sum_X)
return -D
def neg_squared_euc_dists_2(X):
sum_X = np.sum(np.square(X), 1)
D = np.add(np.add(-2 * np.dot(X, X.T), sum_X).T, -sum_X)
return -D
@nlml
nlml / pytorch_convert_ycbcr_rgb_imagenet_conv.py
Last active July 23, 2020 20:36
Convert ycbcr to rgb or imagenet normalized input using Conv2d - useful for coreml input preprocessing
import pylab as plt
import sys
import numpy as np
from PIL import Image
import torch
from torch import nn as nn
def plot_tch(inp):
r = np.clip(inp[0].permute(1, 2, 0).detach().numpy(), 0, 255).astype(