Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Shuchen Du shuuchen

🎯
Focusing
Block or report user

Report or block shuuchen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Dijkstra_heap.py
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 / union_find_tree.py
Last active Jun 20, 2019
An implementation of union find tree
View union_find_tree.py
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]
@shuuchen
shuuchen / install_nvidia_driver.txt
Last active Jun 10, 2019
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
View install_nvidia_driver.txt
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 / trie.py
Created May 27, 2019
Implementation of trie
View trie.py
from collections import defaultdict
class TrieNode:
def __init__(self):
self.isWord = False
self.children = defaultdict(TrieNode)
class Trie:
def __init__(self):
@shuuchen
shuuchen / img_augment.py
Last active May 24, 2019
Using PyTorch functional APIs for image data augmentation
View img_augment.py
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 / file0.txt
Last active Sep 10, 2018
Pytorch でシーケンスデータを順番で読込 ref: https://qiita.com/shuuchen/items/466dc7977a146f7f38f2
View file0.txt
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 / file0.txt
Created Aug 14, 2018
pycharm で conda 環境を構築 (windows 版) ref: https://qiita.com/shuuchen/items/0b8b73894bc43aff370c
View file0.txt
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'
View create_prior_box.py
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 / imagenet1000_clsid_to_human.txt
Created Jul 18, 2017 — forked from yrevar/imagenet1000_clsidx_to_labels.txt
text: imagenet 1000 class id to human readable labels
View imagenet1000_clsid_to_human.txt
{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',
You can’t perform that action at this time.