from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor(num_cpus()) as e:
ims = e.map(lambda fname: safely_process(fname), fnames)
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() |
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] |
from queue import deque | |
class tree: | |
def __init__(self, x): | |
self.data = x | |
self.left = None | |
self.right = None | |
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 .. |
""" | |
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 |