SlideShare a Scribd company logo
棋靈王,2001
座位分配
• 投影片會出現的網址: https://goo.gl/wDUfBk
windows Mac, Ubuntu, Linux
我
Introduction to
黃子瑋
about me
這兩年做的和深度學習相關的事:
• image processing
• medical image
• predicts human age given brain MRI images
• mechanical engineering
• predicts system friction given environment parameters
• ITRI projects
• 3D object recognition, image deblurring
• 打雜
• GPU cluster management (low cost, but high performance and usability)
• isbi-2017.avi
• isbi-2017.jpg
outline
• 蜻蜓點水比較各個 framework
• 介紹 PyTorch
• 安裝 PyTorch
• 確認環境作動正常
• 介紹 PyTorch 架構
• 實作手寫數字辨識
• 歡迎提問,不懂的不會只有你一個
一定要看!十種網友最推的深度學習環境
• Caffe
• Keras
• MatConvNet
• CNTK
• MXNet
• TensorFlow
• Chainer
• PyTorch
• Theano
一定要看!十種網友最推的深度學習環境
• Keras
• CNTK
• MXNet
• TensorFlow
• Chainer
• PyTorch
Keras
keras
TensorFlow CNTK Theano
Caffe / torch7
• trace code 的好選擇
• 你真的知道 back-propagation 在算什麼嗎?
• Static graph, written in C / C++
• 大量使用 BLAS, CUBLAS library
https://github.com/torch/nn
torch
• lua 很難搞
• lua 的現成 function 很少
• 列出某資料夾的檔案
• 讀取文字檔
• 讀取CSV
• (╯°Д°)╯ ┻━┻
• Tensor 的 index 很醜 [{{},{},{}}]
numpy
• NumPy is the fundamental package for scientific computing with Python.
• PyTorch, Tensorflow, chainer, mxnet, Theano 都可以把資料以 numpy
格式交換
• PIL, matplotlib, scikit-image 也是以 numpy 為交換媒介。
http://www.numpy.org/
Static vs. Dynamic graph frameworks
• Static: define and run
• Caffe
• torch
• Tensorflow
• Dynamic: define by run
• Chainer
• pytorch
compiled language vs. interpreted language
resource allocation
run step by step
speed
debug 不方便
• tensorflow 的 sess.run()
• caffe 的 prototxt
TensorFlow vs. PyTorch /static vs. dynamic
TensorFlow vs. PyTorch 就好比:
Chainer inspires PyTorch
Comparison
udn
小結 (dynamic graph 的特性)
• PyTorch ~= torch + autograd + chainer + numpy
• PyTorch 靈活,適合研究。
• 速度比 caffe2 慢,不適合部署。
answer by Yangqing Jia (creates caffe/caffe2)
cs231n (有名的深度學習線上課程)表示:
學弟表示:
學長 , Tensorflow 怎麼這麼慢啊?
我也不知道耶XD
Install PyTorch
• install anaconda3:(用 python3,世界更美好)
• conda install pytorch torchvision cuda80 -c soumith
• conda install pytorch torchvision -c soumith
without CUDA
anaconda
• 是一種 python 的套件管理程式 (另一個是 pip)
• 不需管理員權限即可安裝想要的套件
• 就算弄壞了也不會害到機器上的其他人
• 安裝完後打開 terminal
• windows:winkey+R 然後輸入 cmd
• Mac:開啟 spotlight, 輸入terminal
• 接著輸入 ipython, 應該會看到 3.6 這個數字
Install PyTorch (in Windows 10)
debug with vscode / PDB / PyCharm / Jupyter
• 以 vscode 為例
• 建立一個專案用的資料夾
• 安裝 extension: Python
• 設定 debugger
• F5 執行到下個中斷點
• F10 執行這一行
打開他
安裝 extension
設定 debugger
或是使用 jupyter (anaconda 有送)
• 啟動 server
• 開啟瀏覽器
notebook 基本操作
enter 是換行,shift-enter 執行 cell
ZZZ
• 休息30分鐘
• 討論時間
• 沒跟上的請舉手
• 蜻蜓點水比較各個 framework
• 介紹 PyTorch
• 安裝 PyTorch
• 確認環境作動正常
• 介紹 PyTorch 架構
• 實作手寫數字辨識
• 歡迎提問,不懂的不會只有你一個
PyTorch modules
torch.autograd dynamic graph 的基礎,負責維持歷
史紀錄
torch.nn nn: Neural Network
torch.util.dataset 負責資料預預處理
single thread
torchvision.dataloader 負責資料讀取以及預處理
multi thread
torchvision 包含一些處理影像的函數, 訓練好
的網路,資料集讀取的類別。
autograd
• ALL history of graph computation is recorded
• in Variable
• Tensor 就是高維矩陣
Variable
torch.Tensor:
input
Var 2Var 1 Var 3
Var 2Var 1 Var 3 L
autograd (forward pass)
• ALL history of graph computation is recorded
• in Variable
• Tensor 就是高維矩陣
Variable
torch.Tensor:
input
pointer to
previous tensor
Var 2Var 1 Var 3
Var 2Var 1 Var 3 L
torch.Tensor:
output
(self)
autograd (backward pass)
• ALL history of graph computation is recorded
• in Variable
• Tensor 就是高維矩陣
Var 2Var 1 Var 3
Var 2Var 1 Var 3 L
Variable
pointer to previous
tensor
torch.Tensor:
output
(self)
torch.Tensor:
input
(previous)
torch.Tensor:
grad_output
autograd (backward pass)
• ALL history of graph computation is recorded
• in Variable
• Tensor 就是高維矩陣
Var 2Var 1 Var 3
Var 2Var 1 Var 3 L
Variable
pointer to previous
tensor
torch.Tensor:
output
(self)
torch.Tensor:
input
(previous)
torch.Tensor:
grad_output
torch.Tensor:
grad_output
nn
• What composes a ReLU layer?
• What composes a Convolutional layer?
• What composes a Linear (FullyConnected) layer?
torch.nn vs. torch.nn.functional
• a bunch of functions/layers:
• ReLU
• Linear
• Conv
• Pooling
• ConvTranspose
• Sigmoid
• LogSoftMax
• …
http://pytorch.org/docs/master/nn.html#torch-nn-functional
Variable
torch.Tensor: input
torch.Tensor:
output
(self)
function
Var 2Var 1
Function object
前一層的輸出
(Linear layer)
Linear (fully connected)
• 𝑌 = 𝑊𝑋 + 𝑏
https://github.com/pytorch/pytorch/blob/master/torch/nn/functional.py
BiasWeight
Function object
前一層的輸出
(這一層的輸入)
(Linear layer)
這一層的輸出
BiasWeight
Function object
前一層的輸出
(這一層的輸入)
(Linear layer)
這一層的輸出
torch.nn.Linear
torch.autograd.variable
torch.nn.functional
Weight
Function object
這一層的梯度
(繼續往回送)
(Linear layer)
前一層的梯度
torch.nn.Linear
torch.autograd.variable
torch.nn.functional
grad_Weight
Bias
grad_Bias
Tensors and Variables
• x = torch.Tensor(3, 5)
• X = Variable(x)
• x.size()
• Z = X+Y
Variable
torch.Tensor:
input
pointer to
previous tensor
torch.Tensor:
output
(self)
a little complex graph: D = B+C, B = A, C = A
B
A D
L
C
B
A D
C
Tensors and Variables
• a = torch.Tensor(3, 5)
• A = Variable(a)
• B = A
• C = A
• D = B+C
• print(D.grad_fn)
create a MNIST network
torchvision.datasets (預-預處理)
• 通常是建立 (filepath, (label/classID/value)) 的成對資訊
• [(‘n1002.png’, 5), (‘n1008.png’, 3), …, (‘n50008.png’, 9),]
torch.utils.data.Dataloader
• 從前一步的 dataset 取得訓練資料
• 真的把檔案從 HDD 讀取出來放到 RAM 裡面
• 預處理(加雜訊 反轉 平移 normalize …)
• 關鍵:num_workers 要大於 0 才會平行處理
• GPU 才不會沒事做
• what are sample, batch, epoch ?
optimization
• 𝑊𝑡+1 = 𝑊𝑡 − 𝜂Δ𝑊
• get all parameter with model.parameters()
• weight, bias, … 都會被抓過來
training loop
• clear previous gradient!!!
• get a batch of data
• forward (output get)
• by sending input tensor to model
• compute loss
• back propagation (gradient get)
• by .backward() call
• update weight
• by optim.step()
save model
• torch.save(model, ‘file.pth’)
• model = torch.load(‘file.pth’)
fine tune / graph surgery / freeze layers
• 假設現在要辨識
• ㄅㄆㄇㄈㄉㄊㄋㄌㄍㄎㄏㄐ
ㄑㄒㄓㄔㄕㄖㄗㄘㄙ ㄧㄨ
ㄩ ㄚㄛㄝ ㄞㄟㄠㄡㄢㄣㄤ
ㄥㄦ
fine tune / graph surgery / freeze layers
• 假設現在要辨識
• ㄅㄆㄇㄈㄉㄊㄋㄌㄍㄎㄏㄐ
ㄑㄒㄓㄔㄕㄖㄗㄘㄙ ㄧㄨ
ㄩ ㄚㄛㄝ ㄞㄟㄠㄡㄢㄣㄤ
ㄥㄦ
numpy indexing
• x[:, :14, :]
• 測試手寫字只看的到上半部辨識的出來嗎?
log training status
• pip install tensorboardX
certified
You can log
• scalar (loss, accuracy)
• image (visualize filter)
• audio
• histogram (of the weight distribution)
• text
• embedding (visualize the result)
• graph structure
http://tensorboard-pytorch.readthedocs.io/en/latest/tensorboard.html
usage
• http://tensorboard-pytorch.readthedocs.io/en/latest/tensorboard.html
一個禮拜之內說明書被看了幾次
https://goo.gl/duUcqs
回家作業
• Fashion MNIST
notes on open source projects
• 當個好人
• 解釋為什麼不能滿足某種 feature request
• 未來實作的可能性/時間表
• 推坑
• Push 到 github 之後:
• 用 Travis-CI 自動化測試
• 用 docstring + readthedocs.io 自動產生文件
Trend
• 像 LLVM 的 NNVM
• intermediate representation
• heterogeneous computing
https://github.com/lanpa/tensorboard-pytorch/issues/7
conclusion
• For research: use Tensorflow or PyTorch
• For deployment: use Tensorflow, MXNet, or Caffe2
thanks
parallel PyTorch (over GPUs)
test
• volatile speed up
dynamic graph
• LSTM

More Related Content

What's hot

Aisanux安装光盘分析
Aisanux安装光盘分析Aisanux安装光盘分析
Aisanux安装光盘分析
Guangyao Cheng
 
cmd injection
cmd injectioncmd injection
cmd injectionhackstuff
 
Java Crash分析(2012-05-10)
Java Crash分析(2012-05-10)Java Crash分析(2012-05-10)
Java Crash分析(2012-05-10)
Kris Mok
 
Open Source from Legend, Business, to Ecosystem
Open Source from Legend, Business, to EcosystemOpen Source from Legend, Business, to Ecosystem
Open Source from Legend, Business, to Ecosystem
National Cheng Kung University
 
Hadoop+spark實作
Hadoop+spark實作Hadoop+spark實作
Hadoop+spark實作
FEG
 
20121111 linux intro
20121111 linux intro20121111 linux intro
20121111 linux introChang Mt
 
Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)
Chu-Siang Lai
 
OpenStack Introduction Ecosystem
OpenStack Introduction EcosystemOpenStack Introduction Ecosystem
OpenStack Introduction Ecosystem
NUTC, imac
 
服务器端性能优化 提升Qps、rt
服务器端性能优化 提升Qps、rt服务器端性能优化 提升Qps、rt
服务器端性能优化 提升Qps、rt锐 张
 
嵌入式平台移植技巧概說
嵌入式平台移植技巧概說嵌入式平台移植技巧概說
嵌入式平台移植技巧概說
Joseph Lu
 
Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)
Chu-Siang Lai
 
Some tips
Some tipsSome tips
Some tips
Wei-Bo Chen
 
Hp刀片机测试
Hp刀片机测试Hp刀片机测试
Hp刀片机测试
alex1x
 
MIUI Dump Bitmap Tool 介绍
MIUI Dump Bitmap Tool 介绍MIUI Dump Bitmap Tool 介绍
MIUI Dump Bitmap Tool 介绍
zhucai1234
 
主库自动切换 V2.0
主库自动切换 V2.0主库自动切换 V2.0
主库自动切换 V2.0
jinqing zhu
 

What's hot (15)

Aisanux安装光盘分析
Aisanux安装光盘分析Aisanux安装光盘分析
Aisanux安装光盘分析
 
cmd injection
cmd injectioncmd injection
cmd injection
 
Java Crash分析(2012-05-10)
Java Crash分析(2012-05-10)Java Crash分析(2012-05-10)
Java Crash分析(2012-05-10)
 
Open Source from Legend, Business, to Ecosystem
Open Source from Legend, Business, to EcosystemOpen Source from Legend, Business, to Ecosystem
Open Source from Legend, Business, to Ecosystem
 
Hadoop+spark實作
Hadoop+spark實作Hadoop+spark實作
Hadoop+spark實作
 
20121111 linux intro
20121111 linux intro20121111 linux intro
20121111 linux intro
 
Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)
 
OpenStack Introduction Ecosystem
OpenStack Introduction EcosystemOpenStack Introduction Ecosystem
OpenStack Introduction Ecosystem
 
服务器端性能优化 提升Qps、rt
服务器端性能优化 提升Qps、rt服务器端性能优化 提升Qps、rt
服务器端性能优化 提升Qps、rt
 
嵌入式平台移植技巧概說
嵌入式平台移植技巧概說嵌入式平台移植技巧概說
嵌入式平台移植技巧概說
 
Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)
 
Some tips
Some tipsSome tips
Some tips
 
Hp刀片机测试
Hp刀片机测试Hp刀片机测试
Hp刀片机测试
 
MIUI Dump Bitmap Tool 介绍
MIUI Dump Bitmap Tool 介绍MIUI Dump Bitmap Tool 介绍
MIUI Dump Bitmap Tool 介绍
 
主库自动切换 V2.0
主库自动切换 V2.0主库自动切换 V2.0
主库自动切换 V2.0
 

Similar to [students AI workshop] Pytorch

以Code igniter為基礎的網頁前端程式設計
以Code igniter為基礎的網頁前端程式設計以Code igniter為基礎的網頁前端程式設計
以Code igniter為基礎的網頁前端程式設計
Amigo 陳兆祥
 
[Python - Deep Learning] Data generator
[Python - Deep Learning] Data generator[Python - Deep Learning] Data generator
[Python - Deep Learning] Data generator
Sean Yu
 
1_大二班_資料視覺化_20221028.pdf
1_大二班_資料視覺化_20221028.pdf1_大二班_資料視覺化_20221028.pdf
1_大二班_資料視覺化_20221028.pdf
FEG
 
Data Analyse Black Horse - ClickHouse
Data Analyse Black Horse - ClickHouseData Analyse Black Horse - ClickHouse
Data Analyse Black Horse - ClickHouse
Jack Gao
 
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
YingSiang Geng
 
张勇 搜搜前端架构
张勇 搜搜前端架构张勇 搜搜前端架构
张勇 搜搜前端架构isnull
 
Docker 基礎介紹與實戰
Docker 基礎介紹與實戰Docker 基礎介紹與實戰
Docker 基礎介紹與實戰
Bo-Yi Wu
 
杜增强 Flash移动开发优化技巧
杜增强 Flash移动开发优化技巧杜增强 Flash移动开发优化技巧
杜增强 Flash移动开发优化技巧
增强 杜
 
Django step0
Django step0Django step0
Django step0
永昇 陳
 
Mesos-based Data Infrastructure @ Douban
Mesos-based Data Infrastructure @ DoubanMesos-based Data Infrastructure @ Douban
Mesos-based Data Infrastructure @ Douban
Zhong Bo Tian
 
服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130
Jinrong Ye
 
LinkIt 7697 IoT tutorial
LinkIt 7697 IoT tutorialLinkIt 7697 IoT tutorial
LinkIt 7697 IoT tutorial
CAVEDU Education
 
调试技术的应用
调试技术的应用调试技术的应用
调试技术的应用延胜 黄
 
Maximize Your Production Effort (Chinese)
Maximize Your Production Effort (Chinese)Maximize Your Production Effort (Chinese)
Maximize Your Production Effort (Chinese)
slantsixgames
 
Node.js在淘宝的应用实践
Node.js在淘宝的应用实践Node.js在淘宝的应用实践
Node.js在淘宝的应用实践taobao.com
 
MySQL压力测试经验
MySQL压力测试经验MySQL压力测试经验
MySQL压力测试经验
Jinrong Ye
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
Angel Boy
 
推薦系統實作
推薦系統實作推薦系統實作
推薦系統實作
FEG
 

Similar to [students AI workshop] Pytorch (20)

以Code igniter為基礎的網頁前端程式設計
以Code igniter為基礎的網頁前端程式設計以Code igniter為基礎的網頁前端程式設計
以Code igniter為基礎的網頁前端程式設計
 
[Python - Deep Learning] Data generator
[Python - Deep Learning] Data generator[Python - Deep Learning] Data generator
[Python - Deep Learning] Data generator
 
Tcfsh bootcamp day2
 Tcfsh bootcamp day2 Tcfsh bootcamp day2
Tcfsh bootcamp day2
 
1_大二班_資料視覺化_20221028.pdf
1_大二班_資料視覺化_20221028.pdf1_大二班_資料視覺化_20221028.pdf
1_大二班_資料視覺化_20221028.pdf
 
Data Analyse Black Horse - ClickHouse
Data Analyse Black Horse - ClickHouseData Analyse Black Horse - ClickHouse
Data Analyse Black Horse - ClickHouse
 
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
 
张勇 搜搜前端架构
张勇 搜搜前端架构张勇 搜搜前端架构
张勇 搜搜前端架构
 
Docker 基礎介紹與實戰
Docker 基礎介紹與實戰Docker 基礎介紹與實戰
Docker 基礎介紹與實戰
 
杜增强 Flash移动开发优化技巧
杜增强 Flash移动开发优化技巧杜增强 Flash移动开发优化技巧
杜增强 Flash移动开发优化技巧
 
Django step0
Django step0Django step0
Django step0
 
Mesos-based Data Infrastructure @ Douban
Mesos-based Data Infrastructure @ DoubanMesos-based Data Infrastructure @ Douban
Mesos-based Data Infrastructure @ Douban
 
服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130
 
LinkIt 7697 IoT tutorial
LinkIt 7697 IoT tutorialLinkIt 7697 IoT tutorial
LinkIt 7697 IoT tutorial
 
调试技术的应用
调试技术的应用调试技术的应用
调试技术的应用
 
Maximize Your Production Effort (Chinese)
Maximize Your Production Effort (Chinese)Maximize Your Production Effort (Chinese)
Maximize Your Production Effort (Chinese)
 
Node.js在淘宝的应用实践
Node.js在淘宝的应用实践Node.js在淘宝的应用实践
Node.js在淘宝的应用实践
 
MySQL压力测试经验
MySQL压力测试经验MySQL压力测试经验
MySQL压力测试经验
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
 
Zabbix in PPTV
Zabbix in PPTVZabbix in PPTV
Zabbix in PPTV
 
推薦系統實作
推薦系統實作推薦系統實作
推薦系統實作
 

[students AI workshop] Pytorch

Editor's Notes

  1. 有問題可以互相幫忙
  2. 找家教,教育訓練 小幫手名額
  3. low cost but high performance
  4. 不能做太準
  5. 我會的東西很雜
  6. 因為程式很簡單 就像寫一般的python一樣 所以重點放在前面 根據經驗 一百人的場子的教學活動。實作會是debug大會
  7. 我隨便寫的 你用過什麼? 有些沒什麼人用了
  8. 你用過什麼?
  9. 先天缺點:必須支援不同的 backend 所以功能有所限制
  10. 簡單的分類法:
  11. tensorflow 的
  12. 幾乎一樣
  13. pytorch is faster and prosperous, for research facebook use caffe2 for production
  14. 原來是做自動駕駛
  15. 買硬體+蓋房子就有300億JPY
  16. dynamic graph
  17. output 就是這個variable 的值
  18. output 就是這個variable 的值 複製 input
  19. 紫+綠 : 這一層要回傳的grad
  20. kernel bias weight, bias
  21. 沒參數的就很方便
  22. 我們來舉一個例子:
  23. F for functional 我假設你用過 其他的framework,python 也夠熟
  24. optim.step()
  25. 這東西原本叫
  26. 不用看說明書也會用
  27. 把他想成是 LLVM 也會有 IR 前後端分離