Skip to content

Instantly share code, notes, and snippets.

import argparse
import time
import torch
import numpy as np
def int_list(s):
return [int(x) for x in s.split(',')]
# Installs 375.66 for CUDA 8 on Ubuntu 16.04
wget http://us.download.nvidia.com/tesla/375.66/nvidia-diag-driver-local-repo-ubuntu1604_375.66-1_amd64.deb
sudo dpkg -i nvidia-diag-driver-local-repo-ubuntu1604_375.66-1_amd64.deb
sudo apt-get update
sudo apt-get --allow-unauthenticated --assume-yes install cuda-drivers
sudo reboot now
def bilinear_sample(feats, X, Y, idx):
"""
Perform bilinear sampling on the features in feats using the sampling grid
given by X and Y.
Inputs:
- feats: Tensor (or Variable) holding input feature map, of shape (N, C, H, W)
- X, Y: Tensors (or Variables) holding x and y coordinates of the sampling
grids; both have shape shape (B, HH, WW). Elements in X should be in the
range [0, W - 1] and elements in Y should be in the range [0, H - 1].
import argparse
import torch
import torch.nn as nn
from torch.autograd import Variable
from torch.utils.data import DataLoader
import torchvision
import torchvision.transforms as T
from torchvision.datasets import ImageFolder
from __future__ import print_function
import argparse
import json
from collections import defaultdict
import numpy as np
parser = argparse.ArgumentParser()
parser.add_argument('--questions_file', required=True)
parser.add_argument('--answers_file', required=True)
from __future__ import print_function
import argparse
import json
parser = argparse.ArgumentParser()
parser.add_argument('--questions_file', required=True)
parser.add_argument('--answers_file', required=True)
def index(x, axis, idxs):
"""
Inputs:
- x: torch.Tensor with x.dim() == N
- axis: Integer with 0 <= axis < N
- idxs: List of integers, with 0 <= idxs[i] < x.size(axis)
Returns:
y: torch.Tensor satisfying
STYLE_WEIGHT=5e2
STYLE_SCALE=1.0
th neural_style.lua \
-content_image examples/inputs/hoovertowernight.jpg \
-style_image starry_night_gigapixel.jpg \
-style_scale $STYLE_SCALE \
-print_iter 1 \
-style_weight $STYLE_WEIGHT \
-image_size 256 \
import argparse, os
import numpy as np
from scipy.misc import imread, imsave
parser = argparse.ArgumentParser()
parser.add_argument('--template_dir', required=True) # Low-res images
parser.add_argument('--source_dir', required=True) # Outputs from CNN
parser.add_argument('--output_dir', required=True)
args = parser.parse_args()
import argparse, os
import numpy as np
from scipy.misc import imread, imresize
from skimage.filters import gaussian
import h5py
parser = argparse.ArgumentParser()
parser.add_argument('--train_dir', default='data/yang-91')
parser.add_argument('--val_dir', default='data/set5')