Skip to content

Instantly share code, notes, and snippets.

View shuuchen's full-sized avatar
🎯
Focusing

Shuchen Du shuuchen

🎯
Focusing
View GitHub Profile
@shuuchen
shuuchen / imagenet1000_clsid_to_human.txt
Created July 18, 2017 05:24 — forked from yrevar/imagenet1000_clsidx_to_labels.txt
text: imagenet 1000 class id to human readable labels
{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',
@shuuchen
shuuchen / create_prior_box.py
Created August 25, 2017 03:16 — forked from codingPingjun/create_prior_box.py
SSD prior box creation
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]},
@shuuchen
shuuchen / file0.txt
Created August 14, 2018 07:16
pycharm で conda 環境を構築 (windows 版) ref: https://qiita.com/shuuchen/items/0b8b73894bc43aff370c
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'
@shuuchen
shuuchen / file0.txt
Last active September 10, 2018 03:41
Pytorch でシーケンスデータを順番で読込 ref: https://qiita.com/shuuchen/items/466dc7977a146f7f38f2
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
@shuuchen
shuuchen / img_augment.py
Last active May 24, 2019 01:55
Using PyTorch functional APIs for image data augmentation
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'))
@shuuchen
shuuchen / trie.py
Created May 27, 2019 08:34
Implementation of trie
from collections import defaultdict
class TrieNode:
def __init__(self):
self.isWord = False
self.children = defaultdict(TrieNode)
class Trie:
def __init__(self):
@shuuchen
shuuchen / install_nvidia_driver.txt
Last active June 10, 2019 09:56
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
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
@shuuchen
shuuchen / union_find_tree.py
Last active June 20, 2019 14:31
An implementation of union find tree
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]
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}
@shuuchen
shuuchen / SiameseNetwork.py
Created March 4, 2020 10:40
Siamese Network
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),