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
{0: 'tench, Tinca tinca', | |
1: 'goldfish, Carassius auratus', | |
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias', | |
3: 'tiger shark, Galeocerdo cuvieri', | |
4: 'hammerhead, hammerhead shark', | |
5: 'electric ray, crampfish, numbfish, torpedo', | |
6: 'stingray', | |
7: 'cock', | |
8: 'hen', | |
9: 'ostrich, Struthio camelus', |
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 pickle | |
import numpy as np | |
import pdb | |
img_width, img_height = 300, 300 | |
box_configs = [ | |
{'layer_width': 38, 'layer_height': 38, 'num_prior': 3, 'min_size': 30.0, | |
'max_size': None, 'aspect_ratios': [1.0, 2.0, 1/2.0]}, | |
{'layer_width': 19, 'layer_height': 19, 'num_prior': 6, 'min_size': 60.0, | |
'max_size': 114.0, 'aspect_ratios': [1.0, 1.0, 2.0, 1/2.0, 3.0, 1/3.0]}, |
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
C:\Users\to>python | |
Python 3.6.4 |Anaconda custom (64-bit)| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32 | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import os | |
>>> import sys | |
>>> sys.executable | |
'C:\\Users\\to\\Anaconda3\\python.exe' |
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
class ImageFolderWithPaths(datasets.ImageFolder): | |
"""Custom dataset that includes image file paths. Extends | |
torchvision.datasets.ImageFolder | |
""" | |
# override the __getitem__ method. this is the method dataloader calls | |
def __getitem__(self, index): | |
# this is what ImageFolder normally returns | |
original_tuple = super(ImageFolderWithPaths, self).__getitem__(index) | |
# the image file path |
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 torchvision.transforms.functional as F | |
import numpy as np | |
from PIL import Image | |
import os | |
from matplotlib import pyplot as plt | |
# input images | |
d = '../data/homes/test_input/' | |
img0 = Image.open(os.path.join(d, '352.jpg')) | |
img1 = Image.open(os.path.join(d, '95.jpg')) |
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 collections import defaultdict | |
class TrieNode: | |
def __init__(self): | |
self.isWord = False | |
self.children = defaultdict(TrieNode) | |
class Trie: | |
def __init__(self): |
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
This post shows how to deal with the following error: | |
(base) [dushu@ip-172-20-149-210 ~]$ nvidia-smi | |
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. | |
Make sure that the latest NVIDIA driver is installed and running. | |
Solution | |
Just install the latest nvidia driver. | |
Process |
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
class UT: | |
def __init__(self, n): | |
self.ps = list(range(n)) | |
self.rs = [0] * n | |
def find(self, x): | |
if self.ps[x] != x: | |
self.ps[x] = self.find(self.ps[x]) | |
return self.ps[x] |
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 collections import defaultdict | |
from heapq import * | |
def dijkstra(edges, f, t): | |
g = defaultdict(list) | |
for l, r, c in edges: | |
g[l].append((c, r)) | |
q, seen, mins = [(0, f, ())], set(), {f: 0} |
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
class SiameseNetwork(nn.Module): | |
def __init__(self): | |
super(SiameseNetwork, self).__init__() | |
self.cnn1 = nn.Sequential( | |
nn.ReflectionPad2d(1), | |
nn.Conv2d(1, 4, kernel_size=3), | |
nn.ReLU(inplace=True), | |
nn.BatchNorm2d(4), | |
OlderNewer