cssclass |
---|
cornell-note |
The Cornell Note-taking System is a popular and effective method for organizing and summarizing information during lectures, readings, or any other form of learning.
# ported from https://github.com/pvigier/perlin-numpy/blob/master/perlin2d.py | |
import torch | |
import math | |
def rand_perlin_2d(shape, res, fade = lambda t: 6*t**5 - 15*t**4 + 10*t**3): | |
delta = (res[0] / shape[0], res[1] / shape[1]) | |
d = (shape[0] // res[0], shape[1] // res[1]) | |
grid = torch.stack(torch.meshgrid(torch.arange(0, res[0], delta[0]), torch.arange(0, res[1], delta[1])), dim = -1) % 1 |
There are several approaches
def extract_patches_2d(img,patch_shape,step=[1.0,1.0],batch_first=False): | |
patch_H, patch_W = patch_shape[0], patch_shape[1] | |
if(img.size(2)<patch_H): | |
num_padded_H_Top = (patch_H - img.size(2))//2 | |
num_padded_H_Bottom = patch_H - img.size(2) - num_padded_H_Top | |
padding_H = nn.ConstantPad2d((0,0,num_padded_H_Top,num_padded_H_Bottom),0) | |
img = padding_H(img) | |
if(img.size(3)<patch_W): | |
num_padded_W_Left = (patch_W - img.size(3))//2 | |
num_padded_W_Right = patch_W - img.size(3) - num_padded_W_Left |
There are several approaches
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
""" | |
Create train, valid, test iterators for CIFAR-10 [1]. | |
Easily extended to MNIST, CIFAR-100 and Imagenet. | |
[1]: https://discuss.pytorch.org/t/feedback-on-pytorch-for-kaggle-competitions/2252/4 | |
""" | |
import torch | |
import numpy as np |
# 2 Dimension Fourier Transform: | |
def FT_2D(X): | |
m, n = X.shape | |
return np.array([ [ sum([ sum([ X[i,j]*np.exp(-1j*2*np.pi*(k_m*i/m + k_n*j/n)) for i in range(m) ]) for j in range(n) ]) for k_n in range(n) ] for k_m in range(m) ]) |
Notes from arXiv:1611.07004v1 [cs.CV] 21 Nov 2016
x
and random noise vector z
to y
: y = f(x, z)
G
is trained to produce outputs that cannot be distinguished from "real" images by an adversarially trained discrimintor, D
which is trained to do as well as possible at detecting the generator's "fakes".D
, learns to classify between real and synthesized pairs. The generator learns to fool the discriminator.