Skip to content

Instantly share code, notes, and snippets.

@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):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[[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"]
@travishsu
travishsu / coco2labelme.py
Last active May 29, 2024 09:13
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):
class YourDataset(torch.utils.data.Dataset):
def __init__(self, ...):
...
def __len__(self):
...
return num_all_examples
def __getitem__(self, idx):
...
@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 值的分佈,只是我還不清楚分佈是指什麼
@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 / 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))