Programming at Deep Learning Field
Tao Ruan2020.11.28

Preliminaries
Essential Skills

SSH(e.g., Putty, Terminal, XShell); Linux Programming(e.g., Shell); Server File Editing(e.g., Vim);
Virtual Environment(e.g., Docker).

Development Tools
0. Local System
Windows, Ubuntu, CentOS, MacOS … Whatever you like.

1. Remote Server + Local Pycharm
Pros: Rather Simple; Interactive-Friendly.

••

使用PyCharm进行远程开发和调试 - 慕课网的文章 - 知乎
https://zhuanlan.zhihu.com/p/35067462
PyCharm+Docker：打造最舒适的深度学习炼丹炉 - 刘震的文章 - 知乎
https://zhuanlan.zhihu.com/p/52827335

Cons: Practically bound with python;
Hard to handle with multi-node clusters.

2. Remote Server + Local VS CodePros: Relatively Simple; Interactive-Friendly;
Multi-Language Supporting.
Cons: Hard to handle with multi-node clusters.

• 使用vscode进行远程炼丹 - 希葛格的韩少君的文章 - 知乎
https://zhuanlan.zhihu.com/p/89662757

3. Remote Server + Docker+ Remote Editor（e.g.，Emacs, Vim）
Pros: Could do whatever you want. (JOKE: Emacs is an operation system)

Cons: Hard to learn.

How to Read Codes
1. Be accustomed to relying on documents.
https://pytorch.org/docs/stable/index.html

2. Reading in a top-down, level-based manner.
3. Reading-by-debugging.

External Files

4. Try things of interest in IPython/Jupyter Notebook.
STARTrun.sh

PHASE1

train.py
PHASE2

Handle data

Build model

test.py
Train
Evaluate&Save

IN
OUT

Load dataIN
OUT Raw ImageIN
OUTTransform

IN
OUT

IN
OUT

IN
OUT

Trained models

CollateIN
OUT

Batched Data

ProcessedImage

How to Write Codes[Recommend] Find a reliable project and just follow it！
https://github.com/open-mmlab/mmdetection
https://github.com/facebookresearch/detectron2
https://github.com/google-research-datasets/Objectron……

[Recommend] Writing comments as more as possible.
https://docs.python.org/3.8/library/pydoc.html#module-pydoc
https://www.python.org/dev/peps/pep-0008/
https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings[Optional] Code Styles and Design patterns.
https://google.github.io/styleguide/pyguide.html
https://github.com/faif/python-patterns

MMDetection —— An Example

Sources
Code Repository: https://github.com/open-mmlab/mmdetection
Documentation: https://mmdetection.readthedocs.io/What to do first?
git clone https://github.com/open-mmlab/mmdetection.git<build & install ([Recommend] Build with docker)>

MMDetection —— An Example[Example Task] Train a Faster R-CNN model upon Pascal VOC dataset.
[Paper] Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
RPN
Box & Cls Loss

Proposals
Box & Cls Loss

Detection Results
Backbone
ROI Pooling[Dataset] Pascal VOC 2007 + 2012 ( http://host.robots.ox.ac.uk/pascal/VOC/ )VOCdevkit
VOC2007
VOC2012JPEGImages
Annotations
ImageSets

2012_004309.jpg

2012_004276.jpg

2012_004267.jpg
2012_004276.xml

MMDetection —— An Example（Faster R-CNN upon VOC）
Find the root(entrance) We follow Train predefined models on standard datasets.

CONFIG_FILE=./configs/pascal_voc/faster_rcnn_r50_fpn_1x_voc0712.py
Data

Config Files

STARTtrain.py

Build metas

Build model

Load dataset

Runtrain_detector()

IN
OUT

IN

cfg:
config instance;
meta: env infos;
logger: keep runtime logs.

OUT

IN

model: Fast R-CNN model.

OUT

IN
OUT

dataset: VOC data pool.

MMDetection —— An Example（Faster R-CNN upon VOC）
Build Model
Data

Config Files
STARTtrain.py

Build metas

Build model

Load dataset

Run
train_detector()

IN
OUT

IN
OUT

IN
OUT

IN
OUT

MMDetection —— An Example（Faster R-CNN upon VOC）
Running the Training
Set breakpoint
Data

Config Files
STARTtrain.py

Build metas

Build model

Load dataset

Run
train_detector()

IN
OUT

Dataloader list

dataset et al.

Visualize a batch

IN
OUT

IN
OUT

IN
OUT

Build Dataloader

Build Optimizer

Build & Run
runnerIN
OUT

Image infos

IN
OUT

IN
OUT

Boxes&class labels

MMDetection —— An Example（Faster R-CNN upon VOC）
Running the Training
Data

Config Files
START

train.py

Build metas

Build model

Load dataset

Run
train_detector()IN
OUT

dataset et al.

IN
OUT

IN
OUT

IN
OUT

Build Dataloader

Build Optimizer

Build & Runrunner

IN
OUT

IN

For more details refer:

OUT

https://github.com/open-mmlab/mmcv/tree/master/mmcv/runner/optimizer

IN
OUT

MMDetection —— An Example（Faster R-CNN upon VOC）
Running the Training
Data

Config Files
START

train.py

Build metas

Build model

Load dataset

Run
train_detector()IN
OUT

dataset et al.

IN
OUT

IN
OUTIN
OUT

Build Dataloader

Build Optimizer

Build & Run
runner

IN
OUT

IN
OUT

IN
OUT

MMDetection —— An Example（Faster R-CNN upon VOC）
Whole Tree

Data

Config Files

START

train.py

Build metas

Build model

Load dataset

Run
train_detector()

IN
OUT

IN

Build Dataloader

IN
OUT

OUT

IN

Build Optimizer

IN
OUT

OUT

IN
OUT

Trained model

Build & Run
runnerIN
OUT

MMDetection —— Fundamental Operations
Registry

Hook

Q&A
Programming at Deep Learning Field
Tao Ruan2020.11.28