This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
F = torch.rand(5, 10, 10) # C, H, W | |
M = torch.randint(8, (10, 10)) # 8 superpixels | |
M1hot = torch.nn.functional.one_hot(M, 8) # H, W, K | |
counts = M1hot.sum(dim=(0, 1)) # counts of pixels per superpixel | |
Favg = M1hot.view(-1, 8).T.float() @ F0.view(5, -1).T # K, C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from torch.distributions.utils import clamp_probs | |
from torch.distributions import RelaxedOneHotCategorical | |
class QuantizeCategorical(torch.autograd.Function): | |
@staticmethod | |
def forward(ctx, soft_value): | |
argmax = soft_value.max(-1)[1] | |
hard_value = torch.zeros_like(soft_value) | |
hard_value._unquantize = soft_value |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh | |
bash Anaconda3-5.1.0-Linux-x86_64.sh | |
conda install pytorch torchvision -c pytorch | |
conda install -c menpo opencv3 | |
pip install dominate tqdm | |
pip install git+https://github.com/pytorch/tnt.git@master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from joblib import Parallel, delayed | |
import Queue | |
import os | |
# Define number of GPUs available | |
N_GPU = 4 | |
# Put indices in queue | |
q = Queue.Queue(maxsize=N_GPU) | |
for i in range(N_GPU): |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ww = approx_int_func_solve(xy_pairs, xmin, xmax, intval, w0, f, lbda) | |
% example: | |
% xy_pairs = [0, 1.32; 33.9, .55]; | |
% xmin = 0; | |
% xmax = 33.9; | |
% intval = 38.985; | |
% w0 = [0.1,-2,2] | |
% ww = approx_int_func_solve(xy_pairs, xmin, xmax, intval, w0); | |
if nargin < 6 |