Skip to content

Instantly share code, notes, and snippets.

View raytroop's full-sized avatar
🎯
Focusing

raytroop

🎯
Focusing
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@raytroop
raytroop / mapflat.py
Last active September 16, 2018 04:39
map and flat_map
import tensorflow as tf
# >1
input = [10, 20, 30]
ds = tf.data.Dataset.from_tensor_slices(input)
ds = ds.flat_map(lambda x: tf.data.Dataset.from_tensor_slices([x, x+1, x+2]))
element = ds.make_one_shot_iterator().get_next()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@raytroop
raytroop / vanilla_forward.py
Last active September 18, 2018 04:20
numpy Computing Probabilities on HMM - vanilla method and forward algorithm based on `BinRoot/TensorFlow-Book`
from itertools import product
import numpy as np
# >1 vanilla method, computing expensive
def vanilla(initial_prob, trans_prob, obs_prob, observations):
it = list((product([0, 1], repeat=len(observations))))
it = np.array(it)
# [[0 0 0 0 0]
# [0 0 0 0 1]
# [0 0 0 1 0]
@raytroop
raytroop / btree_yield.py
Last active September 18, 2018 06:25
binary tree traversal generator
from queue import deque
class tree:
def __init__(self, x):
self.data = x
self.left = None
self.right = None
@raytroop
raytroop / opencv_virtualenv.txt
Created September 18, 2018 11:23
opencv install cuda9, conda env
it clone https://github.com/opencv/opencv.git
cd opencv
git checkout 3.4.2
mkdir build && cd build
source activate tpt
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D FORCE_VTK=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_CUBLAS=ON -D CUDA_NVCC_FLAGS="-D_FORCE_INLINES --expt-relaxed-constexpr" -D WITH_GDAL=ON -D WITH_XINE=ON -D BUILD_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.3/modules -DPYTHON3_EXECUTABLE=/home/software/miniconda3/envs/tpt/bin/python3 -DPYTHON_INCLUDE_DIRS=/home/software/miniconda3/envs/tpt/include/python3.6m -DPYTHON_LIBRARIES=/home/software/miniconda3/envs/tpt/lib -DPYTHON3_NUMPY_INCLUDE_DIRS=/home/software/miniconda3/envs/tpt/lib/python3.6/site-packages/numpy/core/include ..
@raytroop
raytroop / bn_pth.py
Last active September 22, 2018 02:20
explore pytorch BatchNorm , the relationship among `track_running_stats`, `eval` and `train` mode
"""
explore the relationship among `track_running_stats`, `eval` and `train` mode
"""
import torch
from torch import nn
import numpy as np
torch.manual_seed(42)
torch.cuda.seed_all()
x = torch.randn(20, 1, 32, 32) * 2 + 3 # mu=3, std=2
@raytroop
raytroop / ThreadPoolExecutor.md
Last active September 30, 2018 05:17
python ThreadPoolExecutor
from concurrent.futures import ThreadPoolExecutor

fastai

with ThreadPoolExecutor(num_cpus()) as e:
  ims = e.map(lambda fname: safely_process(fname), fnames)

dl2

@raytroop
raytroop / clip_in_TensorFlow.ipynb
Last active September 24, 2018 01:53
clip operation in TensorFlow
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@raytroop
raytroop / AdamOptimizer_TensorFlow.ipynb
Last active December 12, 2018 03:13
implement Adam optimzer of TensorFlow
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.