0%

Guide

multi_gpu_model

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import tensorflow as tf
from keras.applications import Xception
from keras.utils import multi_gpu_model
import numpy as np

G = 8
batch_size_per_gpu = 32
batch_size = batch_size_per_gpu * G

num_samples = 1000
height = 224
width = 224
num_classes = 1000

# Instantiate the base model (or "template" model).
# We recommend doing this with under a CPU device scope,
# so that the model's weights are hosted on CPU memory.
# Otherwise they may end up hosted on a GPU, which would
# complicate weight sharing.
with tf.device('/cpu:0'):
model = Xception(weights=None,
input_shape=(height, width, 3),
classes=num_classes)

# Replicates the model on 8 GPUs.
# This assumes that your machine has 8 available GPUs.
parallel_model = multi_gpu_model(model, gpus=G)
parallel_model.compile(loss='categorical_crossentropy',
optimizer='rmsprop')

# Generate dummy data.
x = np.random.random((num_samples, height, width, 3))
y = np.random.random((num_samples, num_classes))

# This `fit` call will be distributed on 8 GPUs.
# Since the batch size is 256, each GPU will process 32 samples.
parallel_model.fit(x, y, epochs=20, batch_size=batch_size)

# Save model via the template model (which shares the same weights):
model.save('my_model.h5')

results

results from Multi-GPU training with Keras, Python, and deep learning on Onepanel.io
To validate this, we trained MiniGoogLeNet on the CIFAR-10 dataset with 4 V100 GPU.

Using a single GPU we were able to obtain 63 second epochs with a total training time of 74m10s.
However, by using multi-GPU training with Keras and Python we decreased training time to 16 second epochs with a total training time of 19m3s.
4x times speedup!

Reference

History

  • 20190910:: created.

Guide

  • version: 4.13.1

install

1
2
3
wget https://github.com/CGAL/cgal/releases/download/releases%2FCGAL-4.13.1/CGAL-4.13.1.zip
cd CGAL-4.13.1
mkdir build && cd build && cmake-gui ..

with options

QT5_DIR            /opt/qt/5.7/gcc_64/lib/cmake/Qt5

compile and install

1
2
make -j8
sudo make install

output

Scanning dependencies of target CGAL
[ 16%] Building CXX object src/CGAL/CMakeFiles/CGAL.dir/all_files.cpp.o
[ 33%] Linking CXX shared library ../../lib/libCGAL.so
[ 33%] Built target CGAL
Scanning dependencies of target CGAL_ImageIO
Scanning dependencies of target CGAL_Core
[ 50%] Building CXX object src/CGAL_Core/CMakeFiles/CGAL_Core.dir/all_files.cpp.o
[ 66%] Building CXX object src/CGAL_ImageIO/CMakeFiles/CGAL_ImageIO.dir/all_files.cpp.o
[ 83%] Linking CXX shared library ../../lib/libCGAL_ImageIO.so
[ 83%] Built target CGAL_ImageIO
[100%] Linking CXX shared library ../../lib/libCGAL_Core.so
[100%] Built target CGAL_Core

CMakeLists.txt

1
2
3
4
5
6
7
8
9
find_package(CGAL REQUIRED)
include(${CGAL_USE_FILE})
MESSAGE( [Main] " CGAL_INCLUDE_DIRS = ${CGAL_INCLUDE_DIRS}")
MESSAGE( [Main] " CGAL_LIBRARIES = ${CGAL_LIBRARIES}")
#[Main] CGAL_INCLUDE_DIRS = /usr/local/include
#[Main] CGAL_LIBRARIES = CGAL::CGAL

add_executable(my_executable my_source_file.cpp)
target_link_libraries(my_executable ${CGAL_LIBRARIES})

CGAL_USE_FILE
CGAL_DIR /usr/local/lib/cmake/CGAL

Reference

History

  • 20190902: created.

Guide

fine-tuning

dogs vs cats

2 classes: binary classification

dog-breed-identification

120 classes

see dog-breed-identification

plant-seedlings-classification

960 unique plants belonging to 12 classes
(植物幼苗分类)
see here

solutions:

cdiscount-image-classification-challenge

超大规模图像分类

Advanced

Data Augmentation

SMOTE

the class_weights argument in model.fit, which you can use to make the model learn more from the minority class.

Other

Reference

History

  • 20190902: created.

Quick Guide

prepare

tools

  • MobaXterm (for windows)
  • ssh + vscode

for windows:
drop files to MobaXterm to upload to server
use zip format

commands

view disk

du -d 1 -h
df -h

gpu and cpu usage

watch -n 1 nvidia-smi
top 

view files and count

wc -l data.csv

# count how many folders
ls -lR | grep '^d' | wc -l
17

# count how many jpg files
ls -lR | grep '.jpg' | wc -l
1360

# view 10 images 
ls train | head
ls test | head

link datasets

# link 
ln -s srt dest
ln -s /data_1/kezunlin/datasets/ dl4cv/datasets

scp

scp -r node17:~/dl4cv  ~/git/
scp -r node17:~/.keras ~/

tmux for background tasks

tmux new -s notebook
tmux ls 
tmux attach -t notebook
tmux detach

wget download

# wget 
# continue donwload
wget -c url 

# background donwload for large file
wget -b -c url
tail -f wget-log

# kill background wget
pkill -9 wget

tips about training large model

terminal 1:

tmux new -s train
conda activate keras

time python train_alexnet.py

terminal 2:

tmux detach

tmux attach -t train

and then close vscode, otherwise bash training process will exit when we close vscode.

cuda driver and toolkits

see cuda-toolkit for cuda driver version

cudatookit version depends on cuda driver version.

install nvidia-drivers

sudo add-apt-repository ppa:graphics-drivers/ppa
sudp apt-get update

sudo apt-cache search nvidia-*
# nvidia-384
# nvidia-396
sudo apt-get -y install nvidia-418

# test 
nvidia-smi
Failed to initialize NVML: Driver/library version mismatch

reboot to test again
https://stackoverflow.com/questions/43022843/nvidia-nvml-driver-library-version-mismatch

install cuda-toolkit(dirvers)

remove all previous nvidia drivers

sudo apt-get -y pruge nvidia-*

go to here and download cuda_10.1

wget -b -c http://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.243_418.87.00_linux.run
sudo sh cuda_10.1.243_418.87.00_linux.run

sudo ./cuda_10.1.243_418.87.00_linux.run

vim .bashrc
# for cuda and cudnn
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

check cuda driver version

> cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module  418.87.00  Thu Aug  8 15:35:46 CDT 2019
GCC version:  gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11) 


>nvidia-smi
Tue Aug 27 17:36:35 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.87.00    Driver Version: 418.87.00    CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+


> nvidia-smi -L
GPU 0: Quadro RTX 8000 (UUID: GPU-acb01c1b-776d-cafb-ea35-430b3580d123)
GPU 1: Quadro RTX 8000 (UUID: GPU-df7f0fb8-1541-c9ce-e0f8-e92bccabf0ef)
GPU 2: Quadro RTX 8000 (UUID: GPU-67024023-20fd-a522-dcda-261063332731)
GPU 3: Quadro RTX 8000 (UUID: GPU-7f9d6a27-01ec-4ae5-0370-f0c356327913)

> nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

install conda

./Anaconda3-2019.03-Linux-x86_64.sh 
[yes]
[yes]

config channels

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

conda config --set show_channel_urls yes

install libraries

conclusions:

  • py37/keras: conda install -y tensorflow-gpu keras==2.2.5
  • py37/torch: conda install -y pytorch torchvision
  • py36/mxnet: conda install -y mxnet

keras 2.2.5 was released on 2019/8/23.
Add new Applications: ResNet101, ResNet152, ResNet50V2, ResNet101V2, ResNet152V2.

common libraries

conda install -y scikit-learn scikit-image pandas matplotlib pillow opencv seaborn
pip install imutils progressbar pydot pylint

pip install imutils to avoid downgrade for tensorflow-gpu

py37

cudatoolkit               10.0.130                  0    
cudnn                     7.6.0                cuda10.0_0    
tensorflow-gpu            1.13.1 

py36

cudatoolkit        anaconda/pkgs/main/linux-64::cudatoolkit-10.1.168-0
cudnn              anaconda/pkgs/main/linux-64::cudnn-7.6.0-cuda10.1_0
tensorboard        anaconda/pkgs/main/linux-64::tensorboard-1.14.0-py36hf484d3e_0
tensorflow         anaconda/pkgs/main/linux-64::tensorflow-1.14.0-gpu_py36h3fb9ad6_0
tensorflow-base    anaconda/pkgs/main/linux-64::tensorflow-base-1.14.0-gpu_py36he45bfe2_0
tensorflow-estima~ anaconda/cloud/conda-forge/linux-64::tensorflow-estimator-1.14.0-py36h5ca1d4c_0
tensorflow-gpu     anaconda/pkgs/main/linux-64::tensorflow-gpu-1.14.0-h0d30ee6_0

imutils only support 36 and 37.
mxnet only support 35 and 36.

details

# remove py35
conda remove -n py35 --all

conda info --envs

conda create -n py37 python==3.7
conda activate py37

# common libraries
conda install -y scikit-learn pandas pillow opencv
pip install imutils

# imutils
conda search imutils  
# py36 and py37

# Name                       Version           Build  Channel             
imutils                        0.5.2          py27_0  anaconda/cloud/conda-forge
imutils                        0.5.2          py36_0  anaconda/cloud/conda-forge
imutils                        0.5.2          py37_0  anaconda/cloud/conda-forge

# tensorflow-gpu and keras
conda install -y tensorflow-gpu keras

# install pytorch
conda install -y pytorch torchvision

# install mxnet
# method 1: pip
pip search mxnet
mxnet-cu80[mkl]/mxnet-cu90[mkl]/mxnet-cu91[mkl]/mxnet-cu92[mkl]/mxnet-cu100[mkl]/mxnet-cu101[mkl]

# method 2: conda
conda install mxnet
# py35 and py36

TensorFlow Object Detection API

home page: home page

download tensorflow models and rename models-master to tfmodels

vim ~/.bashrc

export PYTHONPATH=/home/kezunlin/dl4cv:/data_1/kezunlin/tfmodels/research:$PYTHONPATH

source ~/.bashrc

jupyter notebook

conda activate py37
conda install -y jupyter 

install kernels

python -m ipykernel install --user --name=py37
Installed kernelspec py37 in /home/kezunlin/.local/share/jupyter/kernels/py37

config for server

python -c "import IPython;print(IPython.lib.passwd())"
Enter password: 
Verify password: 
sha1:ef2fb2aacff2:4ea2998699638e58d10d594664bd87f9c3381c04

jupyter notebook --generate-config
Writing default config to: /home/kezunlin/.jupyter/jupyter_notebook_config.py

vim .jupyter/jupyter_notebook_config.py

c.NotebookApp.ip = '*'  
c.NotebookApp.password = u'sha1:xxx:xxx' 
c.NotebookApp.open_browser = False 
c.NotebookApp.port = 8888 
c.NotebookApp.enable_mathjax = True

run jupyter on background

tmux new -s notebook
jupyter notebook
# ctlr+b+d exit session and DO NOT close session
# ctlr+d exit session and close session

access web and input password

test

py37

import cv2
cv2.__version
import tensorflow as tf
import keras 
import torch
import torchvision

cat .keras/keras.json

{
    "epsilon": 1e-07,
    "floatx": "float32",
    "backend": "tensorflow",
    "image_data_format": "channels_last"
}

py36

import mxnet

train demo

export

# use CPU only
export CUDA_VISIBLE_DEVICES=""

# use gpu 0 1
export CUDA_VISIBLE_DEVICES="0,1"

code

import os
os.environ['CUDA_VISIBLE_DEVICES'] = "0,1"

start train

python train.py

./keras folder

view keras models and datasets

ls .keras/
datasets  keras.json  models

models saved to /home/kezunlin/.keras/models/
datasets saved to /home/kezunlin/.keras/datasets/

models lists

xxx_kernels_notop.h5 for include_top = False
xxx_kernels.h5 for include_top = True

Datasets

mnist

cifar10

to skip download

wget http://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
mv ~/Download/cifar-10-python.tar.gz ~/.keras/datasets/cifar-10-batches-py.tar.gz

to load data

(x_train, y_train), (x_test, y_test) = cifar10.load_data()

flowers-17

animals

panda images are WRONG !!!

counts

ls -lR animals/cat | grep ".jpg" | wc -l
1000
ls -lR animals/dog | grep ".jpg" | wc -l
1000
ls -lR animals/panda | grep ".jpg" | wc -l
1000

kaggle cats vs dogs

caltech101

download background

wget -b -c http://www.vision.caltech.edu/Image_Datasets/Caltech101/101_ObjectCategories.tar.gz

Kaggle API

install and config

see kaggle-api

conda activate keras
conda install kaggle

# download kaggle.json
mv kaggle.json ~/.kaggle/kaggle.json
chmod 600 ~/.kaggle/kaggle.json

cat kaggle.json
{"username":"xxx","key":"yyy"}

or by export

export KAGGLE_USERNAME=xxx
export KAGGLE_KEY=yyy

tips

  1. go to account and select ‘Create API Token’ and keras.json will be downloaded.
  2. Ensure kaggle.json is in the location ~/.kaggle/kaggle.json to use the API.

check version

kaggle --version
Kaggle API 1.5.5

commands overview

commands

kaggle competitions {list, files, download, submit, submissions, leaderboard}
kaggle datasets {list, files, download, create, version, init}
kaggle kernels {list, init, push, pull, output, status}
kaggle config {view, set, unset}

download datasets

kaggle competitions download -c dogs-vs-cats

show leaderboard

kaggle competitions leaderboard dogs-vs-cats --show
teamId  teamName                           submissionDate       score    
------  ---------------------------------  -------------------  -------  
71046  Pierre Sermanet                    2014-02-01 21:43:19  0.98533  
66623  Maxim Milakov                      2014-02-01 18:20:58  0.98293  
72059  Owen                               2014-02-01 17:04:40  0.97973  
74563  Paul Covington                     2014-02-01 23:05:20  0.97946  
74298  we've been in KAIST                2014-02-01 21:15:30  0.97840  
71949  orchid                             2014-02-01 23:52:30  0.97733  

set default competition

kaggle config set --name competition --value dogs-vs-cats
- competition is now set to: dogs-vs-cats

kaggle config set --name competition --value dogs-vs-cats-redux-kernels-edition

dogs-vs-cats
dogs-vs-cats-redux-kernels-edition

submit

kaggle c submissions
- Using competition: dogs-vs-cats
- No submissions found

kaggle c submit -f ./submission.csv -m "first submit"

competition has already ended, so can not submit.

Nvidia-docker and containers

install

sudo apt-get -y install docker

# Install nvidia-docker2 and reload the Docker daemon configuration
sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd

restart (optional)

cat /etc/docker/daemon.json

1
2
3
4
5
6
7
8
{
"runtimes": {
"nvidia": {
"path": "nvidia-container-runtime",
"runtimeArgs": []
}
}
}
sudo systemctl enable docker
sudo systemctl start docker

if errors occur:
Job for docker.service failed because the control process exited with error code.
See “systemctl status docker.service” and “journalctl -xe” for details.
check /etc/docker/daemon.json

test

sudo docker run --runtime=nvidia --rm nvidia/cuda:10.1-base nvidia-smi
sudo nvidia-docker run --rm nvidia/cuda:10.1-base nvidia-smi

Thu Aug 29 00:11:32 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.87.00    Driver Version: 418.87.00    CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Quadro RTX 8000     Off  | 00000000:02:00.0 Off |                  Off |
| 43%   67C    P2   136W / 260W |  46629MiB / 48571MiB |     17%      Default |
+-------------------------------+----------------------+----------------------+
|   1  Quadro RTX 8000     Off  | 00000000:03:00.0 Off |                  Off |
| 34%   54C    P0    74W / 260W |      0MiB / 48571MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   2  Quadro RTX 8000     Off  | 00000000:82:00.0 Off |                  Off |
| 34%   49C    P0    73W / 260W |      0MiB / 48571MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   3  Quadro RTX 8000     Off  | 00000000:83:00.0 Off |                  Off |
| 33%   50C    P0    73W / 260W |      0MiB / 48571MiB |      3%      Default |
+-------------------------------+----------------------+----------------------+
                                                                            
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

add user to docker group, and no need to use sudo docker xxx

command refs

sudo nvidia-docker run --rm nvidia/cuda:10.1-base nvidia-smi
sudo nvidia-docker -t -i --privileged nvidia/cuda bash

sudo docker run -it --name kzl -v /home/kezunlin/workspace/:/home/kezunlin/workspace nvidia/cuda

Reference

History

  • 20190821: created.

kaggle

blogs

en

zh

less useful

themed topics

image video processing

Raspberry Pi

NCS(Neural Computing Stick)支持Caffe和Tensorflow框架训练出来的模型。
NCS SDK API提供了Python和C语言的支持。
Intel’s Movidius NCS and OpenVINO toolkit
Movidius APIv1—>Movidius APIv2—> OpenVINO
OpenVINO supports Intel CPUs, GPUs, FPGAs, and VPUs.
Movidius VPU (Vision Processing Unit)

papers

online books

Publisher

free books

specific books

online courses

cs231n

cs231n

github

self-driving cars

GitHub Tools

machine learning

debug

nvidia

mxnet

other

Train Skills

gan训练技巧

pytorch with dail for training

Architectures

basic

  • lenet 1999,alexnet 2012,vggnet 2013,googlenet 2013,inception v1-v4, xception, resnet 2015,
  • squeezenet, densenet, mobilenet, unet
  • rcnn,fast rcnn,faster rcnn,mask rcnn
  • ssd,yolo v1 v2 v3,retinanet(focal loss)

extension

  • ResNeXt: ResNet的优化版ResNeXt,100层相当于resnet200层的精度。一个ResNet打所有,如果不行,那就Stacked Hourglass,还不行就SEResNet。
  • SEResNet
  • yolov3 tiny,yolov3 spp1,yolov3 spp3,slim yolov3 spp3(无人机目标检测)

Classification

Object Detection

anchor-based

  • 《IoU Loss for 2D/3D Object Detection》 注:可提高 2D/3D 目标检测的 mAP
  • IoU-balanced RetinaNet: 专用于Single-stage目标检测的IoU损失函数,如 IoU-balanced RetinaNet 相对于RetinaNet涨点1.1%,特别是高IoU,如涨点2.3% for AP90
  • 上交&中南&南理提出:R3Det 适用于旋转目标的检测网络,综合性能优于RRPN、R2CNN和RetinaNet-R等网络,在航拍图像和场景文本检测数据集上表现SOTA

anchor-free

  • Matrix Net (xNet)

    基于关键点的目标检测器中,18 年提出的 CornerNet 是开山之作,今年又沿着它提出了 CenterNet。这些非常厉害的 single-shot 检测器看起来效果都不如 xNet(matrix net)

Semantic Segmentation

Instance Segmentation

Optimizers

  • lookahead,SGD,RMSProp, Adam基础之上的wrapper optimizer
  • RAdam

    Adam、RMSProp这些算法虽然收敛速度很快,当往往会掉入局部最优解的“陷阱”;原始的SGD方法虽然能收敛到更好的结果,但是训练速度太慢。
    最近,一位来自UIUC的中国博士生Liyuan Liu提出了一个新的优化器RAdam。它兼有Adam和SGD两者的优点,既能保证收敛速度快,也不容易掉入局部最优解,而且收敛结果对学习率的初始值非常不敏感。在较大学习率的情况下,RAdam效果甚至还优于SGD。目前论文作者已将RAdam开源,FastAI现在已经集成了RAdam,只需几行代码即可直接调用。RAdam在图像分类、语言建模,以及机器翻译等等许多任务上,都证明有效。
    上次的adabound出来的时候adam也退休了一波,但是现在还是在用adam。

Normization

Attention

GAN

AutoML

Graph NN

  • pytorch_geometric: 几年来,图神经网络(GNN)在推荐系统、搜索引擎、计算机视觉等领域中都引起了较大的关注。Github有大量开源GNN实现,其中pytorch_geometric是最优秀的实现之一,曾被Yann LeCun推荐

Self-Driving

New Ideas

  • 国内首发Nature子刊 Machine Intelligence论文:思想精妙,或对DNN有重大改进

    在连续学习的标准任务disjoint MNIST与shuffled MNIST任务中,OWM算法的表现超过了同类的其他算法。并且,随着学习的任务数目增加,OWM算法的性能优势会进一步加大。
    代码 OWM 22stars 8-9

  • multi-Grained Cascade Forest(gcForest): 周志华教授指出了深度学习的另一方案,介绍了他们研究的技术 gcForest (multi-Grained Cascade Forest),借鉴 DNN 的特征表示学习,以及集成学习,利用决策树森林的方法,去达到深度模型的效果。

  • HSIC-Bottleneck: 研究者介绍了用于训练深度神经网络的希尔伯特·施密特独立准则(Hilbert-Schmidt independence criterion,HSIC)Bottleneck,用它来代替反向传播简直非常美妙了。表示,HSIC-Bottleneck 的表现在 MNIST/FashionMNIST/CIFAR10 分类中的表现与具有交叉熵目标函数的反向传播算法相当。

  • 基于知识图谱的因果推理: Judea Pearl的因果革命,后面的突破口应该在基于知识图谱的因果推理上面。

Other

  • 基于深度学习的推荐系统,代码数据集缺失,大多数结果无法复现。其次,效果也不如传统推荐算法。
  • 视觉计数(Visual Counting): From Open Set to Closed Set: Counting Objects by Spatial Divide-and-Conquer

    本算法在人群计数,车辆计数和植物计数这3个数据集上进行测试,表现SOTA。 From 华中科技&阿德莱德大学

geoai

ml for fiance

ml for football/sports

football with ml

best

关于赔率时间序列的dataset和其中的一个kernel

github repo

History

  • 20190821: created.

Guide

server

1
sudo apt-get install openssh-server

local

  1. install ssh-client on local machine.
  2. download VSCodeUserSetup-x64-1.36.1.exe from here and install.
  3. start vscode and install Remote Development extension.
  4. ctrl+shift+p and enter remote-ssh and configure for ssh.

edit ~/.ssh/config

1
2
3
4
5
6
7
8
9
Host node08
HostName 192.168.100.08
User root
ForwardX11 yes

Host node09
HostName 192.168.100.09
User root
ForwardX11 yes

use ssh-keygen instead of username and password
copy local ~/.ssh/id_rsa.pub to remote ~/.ssh/authorized_keys

1
2
3
4
5
6
ssh-keygen 
ls .ssh/
id_rsa id_rsa.pub known_hosts

ssh-copy-id node08
ssh-copy-id node09

OK. Now we can ssh without password like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
# usage 
ssh node08
ssh node09
```

### ssh without terminal closed

```bash
# on server
vim /etc/ssh/sshd_config
# 每隔30s向客户端发送一次,确保terminal不会断开
ClientAliveInterval 30
sudo service sshd reload

debug python with vscode

Ctrl+Shift+P 
Python: Select Interpreter

~/anaconda3/envs/torch/bin/python

Debug shortcuts

F11 step in
F10 step over
F5 continue

Reference

History

  • 20190729: created.

Notes

7 knn

  • no paramter, with training data as model
  • test not fast

    no learn anything

8 parameterized learning

  • with parameters W,b as model
  • test very fast

    learn parameters

multi-class svm loss/hinge loss

svm with hinge loss

hinge loss

  • hinge loss
  • squared hinge loss

hinge loss example

L1 = 0, correct predict
L2 = 5.96, incorrect predict
L3 = 5.20, incorrect predict

cross-entropy loss and softmax classifiers

Softmax classifiers give you probabilities for each class label while hinge loss gives you the
margin.

cross-entropy loss example

9 optimization

GD and SGD

  • basic gradient descent(GD): predict all training data and update weights per epoch
  • stochastic gradient descent(SGD): predict only batch training data and update weights per batch

GD
SGD

Extensions to SGD

  • Momentum based SGD
  • Nesterov acceration SGD

Momentum based SGD
Nesterov acceration SGD

tips: use Momentum based SGD

regularization

add to original cost

  • L1 regularization
  • L2 regularization(weight decay)
  • Elastic Net regularization

regularization

during training process

  • dropout
  • data argumentation
  • early stopping(no-imporovements-in-N)

Reference

History

  • 20190709: created.

PyTorch for Python

install pytorch from anaconda

1
2
3
4
5
6
7
8
9
10
conda info --envs
conda activate py35

# newest version
# 1.1.0 pytorch/0.3.0 torchvision
conda install pytorch torchvision cudatoolkit=9.0 -c pytorch

# old version [NOT]
# 0.4.1 pytorch/0.2.1 torchvision
conda install pytorch=0.4.1 cuda90 -c pytorch

output

The following NEW packages will be INSTALLED:

  pytorch            pytorch/linux-64::pytorch-1.1.0-py3.5_cuda9.0.176_cudnn7.5.1_0
  torchvision        pytorch/linux-64::torchvision-0.3.0-py35_cu9.0.176_1

download from channel pytorch will cost much time!
下载pytorch/linux-64::pytorch-1.1.0-py3.5_cuda9.0.176_cudnn7.5.1_0速度非常慢!

install pytorch from tsinghua

add tsinghua pytorch channels

1
2
3
4
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
# for legacy win-64
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/
conda config --set show_channel_urls yes

使用anaconda官方pytorch源非常慢,用清华源代替。
see tsinghua anaconda

cat ~/.condarc

1
2
3
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- defaults

install pytorch from tsinghua

1
2
3
4
5
conda create --name torch python==3.7
conda activate torch

conda install -y pytorch torchvision
conda install -y scikit-learn scikit-image pandas matplotlib pillow opencv

The following NEW packages will be INSTALLED:

  pytorch            anaconda/cloud/pytorch/linux-64::pytorch-1.1.0-py3.5_cuda9.0.176_cudnn7.5.1_0
  torchvision        anaconda/cloud/pytorch/linux-64::torchvision-0.3.0-py35_cu9.0.176_1

test pytorch

1
2
3
4
5
6
7
8
import torch
print(torch.__version__)
'1.1.0'
```
or
```bash
python -c 'import torch; print(torch.cuda.is_available())'
#True

pre-trained models

pre-trained model saved to /home/kezunlin/.cache/torch/checkpoints/

Downloading: “https://download.pytorch.org/models/shufflenetv2_x0.5-f707e7126e.pth“ to /home/kezunlin/.cache/torch/checkpoints/shufflenetv2_x0.5-f707e7126e.pth

PyTorch for C++

download LibTorch

download from LibTorch

compile from source

compile pytorch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# method 1
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch

# method 2, if you are updating an existing checkout
git clone https://github.com/pytorch/pytorch
cd pytorch
git submodule sync
git submodule update --init --recursive
```
check tags
```bash
git tag -l

v0.4.0
v0.4.1
v1.0.0
v1.0.1
v1.0rc0
v1.0rc1
v1.1.0

now compile

1
2
git checkout v1.1.0
mkdir build && cd build && cmake-gui ..

with configs

BUILD_PYTHON OFF

be sure to use stable version 1.1.0 from here instead of latest version 20190724 (unstable version 1.2.0)
because error will occurs when load models.

  • for 1.1.0:

    1
    std::shared_ptr<torch::jit::script::Module> module = torch::jit::load("./model.pt");
  • for latest 1.2.0

    1
    torch::jit::script::Module module = torch::jit::load("./model.pt");

    configure output

    ******** Summary ********
    General:
    CMake version : 3.5.1
    CMake command : /usr/bin/cmake
    System : Linux
    C++ compiler : /usr/bin/c++
    C++ compiler id : GNU
    C++ compiler version : 5.4.0
    BLAS : MKL
    CXX flags : -fvisibility-inlines-hidden -fopenmp -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math
    Build type : Release
    Compile definitions : ONNX_ML=1;ONNX_NAMESPACE=onnx_torch;USE_GCC_ATOMICS=1;HAVE_MMAP=1;_FILE_OFFSET_BITS=64;HAVE_SHM_OPEN=1;HAVE_SHM_UNLINK=1;HAVE_MALLOC_USABLE_SIZE=1
    CMAKE_PREFIX_PATH :
    CMAKE_INSTALL_PREFIX : /usr/local

    TORCH_VERSION : 1.1.0
    CAFFE2_VERSION : 1.1.0
    BUILD_CAFFE2_MOBILE : ON
    BUILD_ATEN_ONLY : OFF
    BUILD_BINARY : OFF
    BUILD_CUSTOM_PROTOBUF : ON
    Link local protobuf : ON
    BUILD_DOCS : OFF
    BUILD_PYTHON : OFF
    BUILD_CAFFE2_OPS : ON
    BUILD_SHARED_LIBS : ON
    BUILD_TEST : OFF
    INTERN_BUILD_MOBILE :
    USE_ASAN : OFF
    USE_CUDA : ON
    CUDA static link : OFF
    USE_CUDNN : ON
    CUDA version : 9.2
    cuDNN version : 7.1.4
    CUDA root directory : /usr/local/cuda
    CUDA library : /usr/local/cuda/lib64/stubs/libcuda.so
    cudart library : /usr/local/cuda/lib64/libcudart.so
    cublas library : /usr/local/cuda/lib64/libcublas.so
    cufft library : /usr/local/cuda/lib64/libcufft.so
    curand library : /usr/local/cuda/lib64/libcurand.so
    cuDNN library : /usr/local/cuda/lib64/libcudnn.so
    nvrtc : /usr/local/cuda/lib64/libnvrtc.so
    CUDA include path : /usr/local/cuda/include
    NVCC executable : /usr/local/cuda/bin/nvcc
    CUDA host compiler : /usr/bin/cc
    USE_TENSORRT : OFF
    USE_ROCM : OFF
    USE_EIGEN_FOR_BLAS : ON
    USE_FBGEMM : OFF
    USE_FFMPEG : OFF
    USE_GFLAGS : OFF
    USE_GLOG : OFF
    USE_LEVELDB : OFF
    USE_LITE_PROTO : OFF
    USE_LMDB : OFF
    USE_METAL : OFF
    USE_MKL : OFF
    USE_MKLDNN : OFF
    USE_NCCL : ON
    USE_SYSTEM_NCCL : OFF
    USE_NNPACK : ON
    USE_NUMPY : ON
    USE_OBSERVERS : ON
    USE_OPENCL : OFF
    USE_OPENCV : OFF
    USE_OPENMP : ON
    USE_TBB : OFF
    USE_PROF : OFF
    USE_QNNPACK : ON
    USE_REDIS : OFF
    USE_ROCKSDB : OFF
    USE_ZMQ : OFF
    USE_DISTRIBUTED : ON
    USE_MPI : ON
    USE_GLOO : ON
    USE_GLOO_IBVERBS : OFF
    NAMEDTENSOR_ENABLED : OFF
    Public Dependencies : Threads::Threads
    Private Dependencies : qnnpack;nnpack;cpuinfo;/usr/lib/x86_64-linux-gnu/libnuma.so;fp16;/usr/lib/openmpi/lib/libmpi_cxx.so;/usr/lib/openmpi/lib/libmpi.so;gloo;aten_op_header_gen;foxi_loader;rt;gcc_s;gcc;dl
    Configuring done

install pytorch

now compile and install

1
2
make -j8
sudo make install

output

Install the project...
-- Install configuration: "Release"
-- Old export file "/usr/local/share/cmake/Caffe2/Caffe2Targets.cmake" will be replaced.  Removing files [/usr/local/share/cmake/Caffe2/Caffe2Targets-release.cmake].
-- Set runtime path of "/usr/local/bin/protoc" to "$ORIGIN"
-- Old export file "/usr/local/share/cmake/Gloo/GlooTargets.cmake" will be replaced.  Removing files [/usr/local/share/cmake/Gloo/GlooTargets-release.cmake].
-- Set runtime path of "/usr/local/lib/libonnxifi_dummy.so" to "$ORIGIN"
-- Set runtime path of "/usr/local/lib/libonnxifi.so" to "$ORIGIN"
-- Set runtime path of "/usr/local/lib/libfoxi_dummy.so" to "$ORIGIN"
-- Set runtime path of "/usr/local/lib/libfoxi.so" to "$ORIGIN"
-- Set runtime path of "/usr/local/lib/libc10.so" to "$ORIGIN"
-- Set runtime path of "/usr/local/lib/libc10_cuda.so" to "$ORIGIN:/usr/local/cuda/lib64"
-- Set runtime path of "/usr/local/lib/libthnvrtc.so" to "$ORIGIN:/usr/local/cuda/lib64/stubs:/usr/local/cuda/lib64"
-- Set runtime path of "/usr/local/lib/libtorch.so" to "$ORIGIN:/usr/local/cuda/lib64:/usr/lib/openmpi/lib"
-- Set runtime path of "/usr/local/lib/libcaffe2_detectron_ops_gpu.so" to "$ORIGIN:/usr/local/cuda/lib64"
-- Set runtime path of "/usr/local/lib/libcaffe2_observers.so" to "$ORIGIN:/usr/local/cuda/lib64"

pytorch 1.1.0
compile and install will cost more than 2 hours
lib install to /usr/local/lib/libtorch.so
cmake install to /usr/local/share/cmake/Torch

C++ example

load pytorch model in c++
see load pytorch model in c++

cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <torch/script.h> // One-stop header.

#include <iostream>
#include <memory>

int main(int argc, const char* argv[]) {
if (argc != 2) {
std::cerr << "usage: example-app <path-to-exported-script-module>\n";
return -1;
}

// Deserialize the ScriptModule from a file using torch::jit::load().
std::shared_ptr<torch::jit::script::Module> module = torch::jit::load(argv[1]);

assert(module != nullptr);
std::cout << "ok\n";

// Create a vector of inputs.
std::vector<torch::jit::IValue> inputs;
inputs.push_back(torch::ones({1, 3, 224, 224}));

// Execute the model and turn its output into a tensor.
at::Tensor output = module->forward(inputs).toTensor();

std::cout << output.slice(/*dim=*/1, /*start=*/0, /*end=*/5) << '\n';
}

CMakeLists.txt

1
2
3
4
5
6
7
8
9
10
11
12
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(custom_ops)

# /usr/local/share/cmake/Torch
find_package(Torch REQUIRED)
MESSAGE( [Main] " TORCH_INCLUDE_DIRS = ${TORCH_INCLUDE_DIRS}")
MESSAGE( [Main] " TORCH_LIBRARIES = ${TORCH_LIBRARIES}")
include_directories(${TORCH_INCLUDE_DIRS})

add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 11)

output

Found torch: /usr/local/lib/libtorch.so  
[Main] TORCH_INCLUDE_DIRS = /usr/local/include;/usr/local/include/torch/csrc/api/include
[Main] TORCH_LIBRARIES = torch;torch_library;/usr/local/lib/libc10.so;/usr/local/cuda/lib64/stubs/libcuda.so;/usr/local/cuda/lib64/libnvrtc.so;/usr/local/cuda/lib64/libnvToolsExt.so;/usr/local/cuda/lib64/libcudart.so;/usr/local/lib/libc10_cuda.so
[TOLOWER] ALGORITHM_TARGET = algorithm

make

1
2
3
mkdir build 
cd build && cmake-gui ..
make -j8

set Torch_DIR to /home/kezunlin/program/libtorch/share/cmake/Torch
auto-set Torch_DIR to /usr/local/share/cmake/Torch

run

1
2
./example-app model.pt
-0.2698 -0.0381 0.4023 -0.3010 -0.0448

errors and solutions

compile errors with libtorch

@soumith
You might be building libtorch with a compiler that is incompatible with the compiler building your final app.
For example, you built libtorch with gcc 4.9.2 and your final app with gcc 5.1, and the C++ ABI between both of them is not the same, so you are seeing linker errors like these

@christianperone

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  set(TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0")
endif()

Which forces GCC to use the old C++11 ABI.

@ smth
we have that flag set because we build with gcc 4.9.x, which only has the old ABI.
In GCC 5.1, the ABI for std::string was changed, and binaries compiling with gcc >= 5.1 are not ABI-compatible with binaries build with gcc < 5.1 (like pytorch) unless you set that flag.

resons and solutions

  • Reasons: ** LibTorch compiled with GCC-4.9.X (only has the old ABI), and binaries compiling with gcc >= 5.1 are not ABI-compatible**
  • Solution: compile pytorch from source instead of using LibTroch downloaded from the website.

runtime errors with pytorch

errors

/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0'

which means opencv link against libtiff 4.0.6

ldd check

ldd /usr/local/lib/libopencv_imgcodecs.so.3.1.0
    linux-vdso.so.1 =>  (0x00007ffc92ffc000)
    libopencv_imgproc.so.3.1 => /usr/local/lib/libopencv_imgproc.so.3.1 (0x00007f32afbca000)
    libjpeg.so.8 => /usr/local/lib/libjpeg.so.8 (0x00007f32af948000)
    libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f32af723000)
    libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f32af4ae000)
    

when compile opencv-3.1.0, cmake find /usr/lib/x86_64-linux-gnu/libtiff.so.5

locate libtiff

locate libtiff.so

/home/kezunlin/anaconda3/envs/py35/lib/libtiff.so
/home/kezunlin/anaconda3/envs/py35/lib/libtiff.so.5
/home/kezunlin/anaconda3/envs/py35/lib/libtiff.so.5.4.0
/home/kezunlin/anaconda3/lib/libtiff.so
/home/kezunlin/anaconda3/lib/libtiff.so.5
/home/kezunlin/anaconda3/lib/libtiff.so.5.4.0
/home/kezunlin/anaconda3/pkgs/libtiff-4.0.10-h2733197_2/lib/libtiff.so
/home/kezunlin/anaconda3/pkgs/libtiff-4.0.10-h2733197_2/lib/libtiff.so.5
/home/kezunlin/anaconda3/pkgs/libtiff-4.0.10-h2733197_2/lib/libtiff.so.5.4.0
/opt/MATLAB/R2016b/bin/glnxa64/libtiff.so.5
/opt/MATLAB/R2016b/bin/glnxa64/libtiff.so.5.0.5
/usr/lib/x86_64-linux-gnu/libtiff.so
/usr/lib/x86_64-linux-gnu/libtiff.so.5
/usr/lib/x86_64-linux-gnu/libtiff.so.5.2.4

It seems that my OpenCV was compiled against libtiff 4, but I have libtiff 5, how to solve this problem?

re-compile opencv-3.1.0 again, new errors occur
see here

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_nppi_LIBRARY (ADVANCED)
    linked by target "opencv_cudev" in directory /home/kezunlin/program/opencv-3.1.0/modules/cudev
    linked by target "opencv_cudev" in directory /home/kezunlin/program/opencv-3.1.0/modules/cudev
    linked by target "opencv_test_cudev" in directory /home/kezunlin/program/opencv-3.1.0/modules/cudev/test

solutions:

WITH_CUDA OFF

WITH_VTK OFF
WITH_TIFF OFF
BUILD_PERF_TESTS OFF

for python2, use default /usr/bin/python2.7
for python3, NOT USE anaconda version
编译的过程中,尽量避免使用anaconda目录下的lib

install libwebp

1
sudo apt-get -y install libwebp-dev

Reference

History

  • 20190626: created.

Guide

OpenCL is a framework for writing programs that execute on these heterogenous platforms. The developers of an OpenCL library utilize all OpenCL compatible devices (CPUs, GPUs, DSPs, FPGAs etc) they find on a computer / device and assign the right tasks to the right processor.
Keep in mind that as a user of OpenCV library you are not developing any OpenCL library. In fact you are not even a user of the OpenCL library because all the details are hidden behind the transparent API/TAPI.

config

cmake config by default for compiling OpenCV:

WITH_OPENCL ON

example

Mat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "opencv2/opencv.hpp"
using namespace cv;

int main(int argc, char** argv)
{
Mat img, gray;
img = imread("image.jpg", IMREAD_COLOR);

cvtColor(img, gray, COLOR_BGR2GRAY);
GaussianBlur(gray, gray,Size(7, 7), 1.5);
Canny(gray, gray, 0, 50);

imshow("edges", gray);
waitKey();
return 0;
}

UMat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "opencv2/opencv.hpp"
using namespace cv;

int main(int argc, char** argv)
{
UMat img, gray;
imread("image.jpg", IMREAD_COLOR).copyTo(img);

cvtColor(img, gray, COLOR_BGR2GRAY);
GaussianBlur(gray, gray,Size(7, 7), 1.5);
Canny(gray, gray, 0, 50);

imshow("edges", gray);
waitKey();
return 0;
}

UMat with transparent API/TAPI

Reference

History

  • 20190626: created.

Guide

  • ubuntu 16.04
  • conda 4.6.14
  • python 3.7.3 (default)
  • python 3.5.6 (env)

Install Conda

download Anaconda3-2019.03-Linux-x86_64.sh from here

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
bash ./Anaconda3-2019.03-Linux-x86_64.sh

[/home/kezunlin/anaconda3] >>>
PREFIX=/home/kezunlin/anaconda3
installing: python-3.7.3-h0371630_0 ...
Python 3.7.3
...
installing: scikit-image-0.14.2-py37he6710b0_0 ...
installing: scikit-learn-0.20.3-py37hd81dba3_0 ...
installing: astropy-3.1.2-py37h7b6447c_0 ...
installing: statsmodels-0.9.0-py37h035aef0_0 ...
installing: seaborn-0.9.0-py37_0 ...
installing: anaconda-2019.03-py37_0 ...
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]

If you'd prefer that conda's base environment not be activated on startup,
set the auto_activate_base parameter to false:

conda config --set auto_activate_base false

Thank you for installing Anaconda3!

conda config –set auto_activate_base false

check version

1
2
3
4
5
6
7
conda --version
conda 4.6.11

conda update conda

conda --version
conda 4.6.14

Managing Environments

create new env

When you begin using conda, you already have a default environment named base. You don’t want to put programs into your base environment, though. Create separate environments to keep your programs isolated from each other.

1
2
3
4
5
6
7
8
(base) kezunlin@ke:~$ conda --version
conda 4.6.14

(base) kezunlin@ke:~$ conda create --name snowflakes biopython
(base) kezunlin@ke:~$ conda activate snowflakes
(snowflakes) kezunlin@ke:~$
(snowflakes) kezunlin@ke:~$ conda deactivate
(base) kezunlin@ke:~$

conda activate only works on conda 4.6 and later versions.

list envs

1
2
3
4
5
conda info --envs
# conda environments:
#
base * /home/kezunlin/anaconda3
snowflakes /home/kezunlin/anaconda3/envs/snowflakes

~/.conda/environments.txt

1
2
3
/home/kezunlin/anaconda3
/home/kezunlin/anaconda3/envs/snowflakes
/home/kezunlin/anaconda3/envs/py35

Managing Python

When you create a new environment, conda installs the same Python version you used when you downloaded and installed Anaconda. If you want to use a different version of Python, for example Python 3.5, simply create a new environment and specify the version of Python that you want.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
conda create --name snakes python=3.5
conda activate py35

conda info --envs
# conda environments:
#
base /home/kezunlin/anaconda3
py35 * /home/kezunlin/anaconda3/envs/py35
snowflakes /home/kezunlin/anaconda3/envs/snowflakes

(base) kezunlin@ke:~$ python --version
Python 3.7.3
(base) kezunlin@ke:~$ conda activate py35
(py35) kezunlin@ke:~$ python --version
Python 3.5.6 :: Anaconda, Inc.

Managing packages

list packages

1
2
3
4
5
6
7
8
9
(base) kezunlin@ke:~$ conda activate py35
(py35) kezunlin@ke:~$
(py35) kezunlin@ke:~$ conda list
# packages in environment at /home/kezunlin/anaconda3/envs/py35:
#
# Name Version Build Channel
ca-certificates 2019.1.23 0
certifi 2018.8.24 py35_1
libedit 3.1.20181209 hc058e9b_0
1
2
3
4
5
6
7
8
9
10
conda search beautifulsoup4

...
beautifulsoup4 4.6.3 py27_0 pkgs/main
beautifulsoup4 4.6.3 py35_0 pkgs/main
beautifulsoup4 4.6.3 py36_0 pkgs/main
beautifulsoup4 4.6.3 py37_0 pkgs/main
beautifulsoup4 4.7.1 py27_1 pkgs/main
beautifulsoup4 4.7.1 py36_1 pkgs/main
beautifulsoup4 4.7.1 py37_1 pkgs/main

install

1
conda install beautifulsoup4

conda config

1
2
conda config --set show_channel_urls yes
conda config --show

Tools

Jupyter notebook

install jupyter

1
2
3
conda create -n py35 python=3.5
conda activate py35
conda install jupyter

install kernel

1
2
python -m ipykernel install --user --name=py35
Installed kernelspec py35 in /home/kezunlin/.local/share/jupyter/kernels/py35

jupyter depends on notebook and ipykernel
also see tensorflow jupyter notebook kenel

run jupyter

1
jupyter notebook

now we can see py35 kernel appears.

py35 kernel

tensorflow-gpu/keras

1
2
conda activate py35
conda install tensorflow-gpu keras

test

1
2
3
>>>import tensorflow as tf
>>>import keras as K
Using TensorFlow backend.

.keras/keras.json

1
2
3
4
5
6
{
"epsilon": 1e-07,
"floatx": "float32",
"image_data_format": "channels_last",
"backend": "tensorflow"
}

pytorch

see pytorch tutorial on ubuntu 16.04

Reference

History

  • 20190524: created.