Skip to content

Instantly share code, notes, and snippets.

@travishsu
travishsu / fundamental_op.py
Last active December 9, 2016 13:41
只有 linear transformation 的部分,如果要做到 linear regression 還需要 sum, square 的 node。
import numpy as np
class Add:
def __init__(self):
pass
def forward(self, numlist):
self.numlist = numlist
return np.sum(numlist)
def backward(self, loss):
self.dnumlist = loss * np.ones(len(self.numlist))
@travishsu
travishsu / Dataset.py
Created February 14, 2017 16:00
從 Tensorflow 提供的 MNIST Dataset 修改來的類別,可以加入自己的數據集,並用 next_batch 提取數據集的子集。
import numpy
class DatasetNoLabel(object):
def __init__(self, data):
self._data = data
self._num_examples = data.shape[0]
self._epochs_completed = 0
self._index_in_epoch = 0
@property
def data(self):
return self._data
@travishsu
travishsu / tensorboard_concept_example.py
Last active March 5, 2017 16:10
用 TensorBoard 的好處就是不用在寫 printout 惹~
x = tf.placeholder(.....)
# Scope: 運算區塊
with tf.name_scope("operation_scope"):
weight = ...
l1 = op(x, w)
...
...
tf.summary.histogram("weight", weight) # 可以看 weight 值的分佈,只是我還不清楚分佈是指什麼
class YourDataset(torch.utils.data.Dataset):
def __init__(self, ...):
...
def __len__(self):
...
return num_all_examples
def __getitem__(self, idx):
...
@travishsu
travishsu / coco2labelme.py
Last active July 19, 2024 01:51
Convert COCO format segmentation annotation to LabelMe format
import os
import json
import subprocess
import numpy as np
import pandas as pd
from skimage.measure import find_contours
class CocoDatasetHandler:
def __init__(self, jsonpath, imgpath):
[[runners]]
pre_build_script = "mkdir -p $HOME/.docker/ && echo \"{ \\\"proxies\\\": { \\\"default\\\": { \\\"httpProxy\\\": \\\"$HTTP_PROXY\\\", \\\"httpsProxy\\\": \\\"$HTTPS_PROXY\\\", \\\"noProxy\\\": \\\"$NO_PROXY\\\" } } }\" > $HOME/.docker/config.json"
pre_clone_script = "git config --global http.proxy $HTTP_PROXY; git config --global https.proxy $HTTPS_PROXY"
environment = ["https_proxy=http://docker0_interface_ip:3128", "http_proxy=http://docker0_interface_ip:3128", "HTTPS_PROXY=docker0_interface_ip:3128", "HTTP_PROXY=docker0_interface_ip:3128"]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@travishsu
travishsu / pascal.py
Created November 15, 2022 22:51
Pascal's Triangle
def pascal(n):
L = n + n - 1
rows = []
row = [1]
rows.append(row)
while len(rows) < n:
row_cat = [0] + row + [0]
row = [row_cat[i] + row_cat[i+1] for i in range(len(row_cat)-1)]
rows.append(row)
for row_idx, row in enumerate(rows):
@travishsu
travishsu / compare_dirs.py
Created July 12, 2024 03:07
Qt GUI to show difference between two directories
import os
import glob
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QListWidget, QHBoxLayout, QFileDialog
def compare_folders(dir1, dir2):
files_in_dir1 = [
f.replace('._', '').replace(dir1 + '/', '')
for f in glob.glob(dir1 + '/**/*', recursive=True)