Professional Documents
Culture Documents
Environment Setup
&
Deep Learning: A Concise Intro.
HonghuTech 翁啟閎
@NTUST
2022/12/15
Docker KubeRun
Introduction Introduction
User Interface
Docker Command Lines
for Admin. & for User
Deep Learning
Convolutional Neural Network
some Basic Concepts • We aim to give you a good
starting point for AI model
construction / training
Build a ResNet from Scratch
• Theoretical details or recent
developments are not
Distributed Training Principle covered here
and a Demo
ffi
THE ECOSYSTEM OF NVIDIA…
Frameworks
Libraries
NCCL cuDNN
cuBLAS
CUDA
NVIDIA GPUs
Docker vs. Virtual Machine
https://www.hitechnectar.com/blogs/hypervisor-vs-docker/
Docker image: a pile of layers
https://ragin.medium.com/docker-what-it-is-how-images-are-structured-docker-vs-vm-and-some-tips-part-1-d9686303590f?source=post_internal_links---------1----------------------------
Docker and Deep Learning?
https://github.com/NVIDIA/nvidia-docker
Common usage
docker images #看共有哪些Docker images
docker search [possible_image_name] #找image
docker pull [image_name] #抓image
nvidia-docker run [options image_name] #將⼀個image啟動(變成Container)
https://hub.docker.com/
Run containers via docker / nvidia-docker run
FROM tensorflow/tensorflow:2.10.1-gpu-jupyter
MAINTAINER Chi-Hung Weng <chihung@honghutech.com>
RUN apt update && apt install -y vim
RUN pip3 install seaborn polars
' > build_tf/Dockerfile Creat the `Docker le`
# put the instruction file (Dockerfile) into the created folder
fi
fi
https://ngc.nvidia.com/
• Scalable.
w’=5 w’=3
24 有著作權,侵害必究
Computer Vision
• ⽤同⼀組3 x 3 lter掃視整張圖:
表⽰我們假設圖像裡的每個3 x 3
的⼩區塊是有共通性。
• 好處:降低資料量,讓網路容易訓
練。
25 有著作權,侵害必究
fi
fi
fi
Computer Vision
Width (W)
Height (H)
Padding (P)
Stride (SW, SH)
Filter size (FW, FH)
0 W + 2P F
W = +1
W=4 SW
CS231n, Andrej Karpathy & Fei-Fei Li
H=4
W + 2P F
P=0 0
H = +1
SW=SH=2 SH
FW=FH=2
26 有著作權,侵害必究
Computer Vision
model = Sequential()
model.add(Conv2D(filters=96, kernel_size=(3, 3),
strides=(1,1),
padding='valid',
input_shape=(5,5,3)
)
)
print( model.predict(randData).shape ) 27 # 看輸出資料的形狀
Computer Vision
Computer Vision
Feature map 1
Feature map 2
3 X 3 Conv 2 X 2 Conv
(stride=1) (stride=1)
29 有著作權,侵害必究
Computer Vision
Feature map 1
Feature map 2
3 X 3 Conv 2 X 2 Conv
(stride=1) (stride=1)
此濾鏡能感受到
多少原圖視野?
30 有著作權,侵害必究
Computer Vision
Feature map 1
Feature map 2
3 X 3 Conv 2 X 2 Conv
(stride=1) (stride=1)
此濾鏡能感受到
多少原圖視野?
31 有著作權,侵害必究
Computer Vision
第⼆層 lter資訊(已還原⾄圖像空間)
第⼀層 lter樣貌
越後⾯的層能呈現越複雜的圖像 / 機器能夠學會保留對分類有⽤的特徵
fi
fi
fi
AlexNet
Computer Vision
33 有著作權,侵害必究
ff
Computer Vision
https://medium.com/@Lidinwise/the-revolution-of-depth-facf174924f5
34 有著作權,侵害必究
VGGNet
Computer Vision
size: 224 3x3 Conv, 64
3x3 Conv, 64
max pool Karen Simonyan, Andrew Zisserman (2014)
size: 112 3x3 Conv, 128 http://www.robots.ox.ac.uk/~vgg/
3x3 Conv, 128
max pool
size: 56 3x3 Conv, 256
max pool
size: 28 3x3 Conv, 512
max pool
size: 14 3x3 Conv, 512
Dense, 4096
Dense, 1000
35 有著作權,侵害必究
VGGNet
Computer Vision
size: 224 3x3 Conv, 64
3x3 Conv, 64
max pool Karen Simonyan, Andrew Zisserman (2014)
size: 112 3x3 Conv, 128
http://www.robots.ox.ac.uk/~vgg/
3x3 Conv, 128
max pool
size: 56 3x3 Conv, 256
max pool
size: 28 3x3 Conv, 512
max pool
size: 14 3x3 Conv, 512
Dense, 4096
Dense, 1000
Computer Vision
ResNet
Kaiming He et al (2015)
37 有著作權,侵害必究
Computer Vision
ResNet
Kaiming He et al (2015)
38 有著作權,侵害必究
Computer Vision
ResNet
Kaiming He et al (2015)
F(x) x
Conv 3x3
Conv 3x3
39 有著作權,侵害必究
Computer Vision
ResNet
Kaiming He et al (2015)
F(x) x
Conv 3x3
Conv 3x3
40 有著作權,侵害必究
Residual block
有著作權,侵害必究
DEMO
DISTRIBUTED TRAINING
L = l(1) + l(2) + l(3) + l(4)
GPU
L = l(1) + l(2) +
1. 正向傳遞, 得到所有樣本誤差: l(3) + l(4)
Model
43
單卡模型訓練
L = l(1) + l(2) + l(3) + l(4)
GPU
2. 整體誤差倒傳遞, 讓權重w得到梯度
Model @L
gw =
@w
@l(1) @l(2) @l(3) @l(4)
= + + +
X(1), X(2), X(3), X(4)
@w @w @w @w
3. 利⽤w的梯度更新w
w := w ⌘gw
44
多卡模型訓練
CPU1
X(1), X(2), X(3), X(4)
45
多卡模型訓練
GPU1 GPU2
2. 各GPU做倒傳遞, 得到
各⾃的梯度
46
多卡模型訓練
GPU1 GPU2
3. 利⽤allreduce, 使得每張
卡都可以得到完整的w梯度
4. 利⽤w的梯度更新w
w := w ⌘gw
47
Quick DEMO
• https://github.com/horovod/horovod
• https://github.com/horovod/horovod/blob/master/examples/tensor ow2/tensor ow2_keras_mnist.py
48
fl
fl