Skip to content

Commit 407d8d4

Browse files
authored
Reorg how_to.md and model_analysis.md (#2205)
1 parent f18d98f commit 407d8d4

File tree

4 files changed

+198
-202
lines changed

4 files changed

+198
-202
lines changed
Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,102 @@
11
# Model Analysis
22

3-
Coming soon.
3+
## Get Model Params & FLOPs
4+
5+
MMPose provides `tools/analysis_tools/get_flops.py` to get model parameters and FLOPs.
6+
7+
```shell
8+
python tools/analysis_tools/get_flops.py ${CONFIG_FILE} [--shape ${INPUT_SHAPE}] [--cfg-options ${CFG_OPTIONS}]
9+
```
10+
11+
Description of all arguments:
12+
13+
`CONFIG_FILE` : The path of a model config file.
14+
15+
`--shape`: The input shape to the model.
16+
17+
`--input-constructor`: If specified as batch, it will generate a batch tensor to calculate FLOPs.
18+
19+
`--batch-size`:If `--input-constructor` is specified as batch, it will generate a random tensor with shape `(batch_size, 3, **input_shape)` to calculate FLOPs.
20+
21+
`--cfg-options`: If specified, the key-value pair optional `cfg` will be merged into config file.
22+
23+
Example:
24+
25+
```shell
26+
python tools/analysis_tools/get_flops.py configs/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-210e_coco-256x192.py
27+
```
28+
29+
We will get the following results:
30+
31+
```text
32+
==============================
33+
Input shape: (1, 3, 256, 192)
34+
Flops: 7.7 GFLOPs
35+
Params: 28.54 M
36+
==============================
37+
```
38+
39+
```{note}
40+
This tool is still experimental and we do not guarantee that the number is absolutely correct. Some operators are not counted into FLOPs like GN and custom operators.
41+
```
42+
43+
## Log Analysis
44+
45+
MMPose provides `tools/analysis_tools/analyze_logs.py` to analyze the training log. The log file can be either a json file or a text file. The json file is recommended, because it is more convenient to parse and visualize.
46+
47+
Currently, the following functions are supported:
48+
49+
- Plot loss/accuracy curves
50+
- Calculate training time
51+
52+
### Plot Loss/Accuracy Curves
53+
54+
The function depends on `seaborn`, please install it first by running `pip install seaborn`.
55+
56+
![log_curve](https://user-images.githubusercontent.com/87690686/188538215-5d985aaa-59f8-44cf-b6f9-10890d599e9c.png)
57+
58+
```shell
59+
python tools/analysis_tools/analyze_logs.py plot_curve ${JSON_LOGS} [--keys ${KEYS}] [--title ${TITLE}] [--legend ${LEGEND}] [--backend ${BACKEND}] [--style ${STYLE}] [--out ${OUT_FILE}]
60+
```
61+
62+
Examples:
63+
64+
- Plot loss curve
65+
66+
```shell
67+
python tools/analysis_tools/analyze_logs.py plot_curve log.json --keys loss_kpt --legend loss_kpt
68+
```
69+
70+
- Plot accuracy curve and export to PDF file
71+
72+
```shell
73+
python tools/analysis_tools/analyze_logs.py plot_curve log.json --keys acc_pose --out results.pdf
74+
```
75+
76+
- Plot multiple log files on the same figure
77+
78+
```shell
79+
python tools/analysis_tools/analyze_logs.py plot_curve log1.json log2.json --keys loss_kpt --legend run1 run2 --title loss_kpt --out loss_kpt.png
80+
```
81+
82+
### Calculate Training Time
83+
84+
```shell
85+
python tools/analysis_tools/analyze_logs.py cal_train_time ${JSON_LOGS} [--include-outliers]
86+
```
87+
88+
Examples:
89+
90+
```shell
91+
python tools/analysis_tools/analyze_logs.py cal_train_time log.json
92+
```
93+
94+
The result is as follows:
95+
96+
```text
97+
-----Analyze train time of hrnet_w32_256x192.json-----
98+
slowest epoch 56, average time is 0.6924
99+
fastest epoch 1, average time is 0.6502
100+
time std over epochs is 0.0085
101+
average iter time: 0.6688 s/iter
102+
```

docs/en/how_to.md

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,5 @@
11
# How to
22

3-
## Log Analysis
4-
5-
MMPose provides `tools/analysis_tools/analyze_logs.py` to analyze the training log. The log file can be either a json file or a text file. The json file is recommended, because it is more convenient to parse and visualize.
6-
7-
Currently, the following functions are supported:
8-
9-
- Plot loss/accuracy curves
10-
- Calculate training time
11-
12-
### Plot Loss/Accuracy Curves
13-
14-
The function depends on `seaborn`, please install it first by running `pip install seaborn`.
15-
16-
![log_curve](https://user-images.githubusercontent.com/87690686/188538215-5d985aaa-59f8-44cf-b6f9-10890d599e9c.png)
17-
18-
```shell
19-
python tools/analysis_tools/analyze_logs.py plot_curve ${JSON_LOGS} [--keys ${KEYS}] [--title ${TITLE}] [--legend ${LEGEND}] [--backend ${BACKEND}] [--style ${STYLE}] [--out ${OUT_FILE}]
20-
```
21-
22-
Examples:
23-
24-
- Plot loss curve
25-
26-
```shell
27-
python tools/analysis_tools/analyze_logs.py plot_curve log.json --keys loss_kpt --legend loss_kpt
28-
```
29-
30-
- Plot accuracy curve and export to PDF file
31-
32-
```shell
33-
python tools/analysis_tools/analyze_logs.py plot_curve log.json --keys acc_pose --out results.pdf
34-
```
35-
36-
- Plot multiple log files on the same figure
37-
38-
```shell
39-
python tools/analysis_tools/analyze_logs.py plot_curve log1.json log2.json --keys loss_kpt --legend run1 run2 --title loss_kpt --out loss_kpt.png
40-
```
41-
42-
### Calculate Training Time
43-
44-
```shell
45-
python tools/analysis_tools/analyze_logs.py cal_train_time ${JSON_LOGS} [--include-outliers]
46-
```
47-
48-
Examples:
49-
50-
```shell
51-
python tools/analysis_tools/analyze_logs.py cal_train_time log.json
52-
```
53-
54-
The result is as follows:
55-
56-
```text
57-
-----Analyze train time of hrnet_w32_256x192.json-----
58-
slowest epoch 56, average time is 0.6924
59-
fastest epoch 1, average time is 0.6502
60-
time std over epochs is 0.0085
61-
average iter time: 0.6688 s/iter
62-
```
63-
64-
## Get Model Params & FLOPs
65-
66-
MMPose provides `tools/analysis_tools/get_flops.py` to get model parameters and FLOPs.
67-
68-
```shell
69-
python tools/analysis_tools/get_flops.py ${CONFIG_FILE} [--shape ${INPUT_SHAPE}] [--cfg-options ${CFG_OPTIONS}]
70-
```
71-
72-
Description of all arguments:
73-
74-
`CONFIG_FILE` : The path of a model config file.
75-
76-
`--shape`: The input shape to the model.
77-
78-
`--input-constructor`: If specified as batch, it will generate a batch tensor to calculate FLOPs.
79-
80-
`--batch-size`:If `--input-constructor` is specified as batch, it will generate a random tensor with shape `(batch_size, 3, **input_shape)` to calculate FLOPs.
81-
82-
`--cfg-options`: If specified, the key-value pair optional `cfg` will be merged into config file.
83-
84-
Example:
85-
86-
```shell
87-
python tools/analysis_tools/get_flops.py configs/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-210e_coco-256x192.py
88-
```
89-
90-
We will get the following results:
91-
92-
```text
93-
==============================
94-
Input shape: (1, 3, 256, 192)
95-
Flops: 7.7 GFLOPs
96-
Params: 28.54 M
97-
==============================
98-
```
99-
100-
```{note}
101-
This tool is still experimental and we do not guarantee that the number is absolutely correct. Some operators are not counted into FLOPs like GN and custom operators.
102-
```
103-
1043
## Print Entire Config
1054

1065
Officially provided config files inherit multiple config files, which can facilitate management and reduce redundant code. But sometimes we want to know what the default parameter values that are not explicitly written in the configuration file are. MMPose provides `tools/analysis_tools/print_config.py` to print the entire configuration information verbatim.
Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,100 @@
11
# Model Analysis
22

3-
Coming soon.
3+
## 统计模型参数量与计算量
4+
5+
MMPose 提供了 `tools/analysis_tools/get_flops.py` 来统计模型的参数量与计算量。
6+
7+
```shell
8+
python tools/analysis_tools/get_flops.py ${CONFIG_FILE} [--shape ${INPUT_SHAPE}] [--cfg-options ${CFG_OPTIONS}]
9+
```
10+
11+
参数说明:
12+
13+
`CONFIG_FILE` : 模型配置文件的路径。
14+
15+
`--shape`: 模型的输入张量形状。
16+
17+
`--input-constructor`: 如果指定为 `batch`,将会生成一个 `batch tensor` 来计算 FLOPs。
18+
19+
`--batch-size`:如果 `--input-constructor` 指定为 `batch`,将会生成一个随机 `tensor`,形状为 `(batch_size, 3, **input_shape)` 来计算 FLOPs。
20+
21+
`--cfg-options`: 如果指定,可选的 `cfg` 的键值对将会被合并到配置文件中。
22+
23+
示例:
24+
25+
```shell
26+
python tools/analysis_tools/get_flops.py configs/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-210e_coco-256x192.py
27+
```
28+
29+
结果如下:
30+
31+
```text
32+
==============================
33+
Input shape: (1, 3, 256, 192)
34+
Flops: 7.7 GFLOPs
35+
Params: 28.54 M
36+
==============================
37+
```
38+
39+
```{note}
40+
目前该工具仍处于实验阶段,我们不能保证统计结果绝对正确,一些算子(比如 GN 或自定义算子)没有被统计到 FLOPs 中。
41+
```
42+
43+
## 分析训练日志
44+
45+
MMPose 提供了 `tools/analysis_tools/analyze_logs.py` 来对训练日志进行简单的分析,包括:
46+
47+
- 将日志绘制成损失和精度曲线图
48+
- 统计训练速度
49+
50+
### 绘制损失和精度曲线图
51+
52+
该功能依赖于 `seaborn`,请先运行 `pip install seaborn` 安装依赖包。
53+
54+
![log_curve](https://user-images.githubusercontent.com/87690686/188538215-5d985aaa-59f8-44cf-b6f9-10890d599e9c.png)
55+
56+
```shell
57+
python tools/analysis_tools/analyze_logs.py plot_curve ${JSON_LOGS} [--keys ${KEYS}] [--title ${TITLE}] [--legend ${LEGEND}] [--backend ${BACKEND}] [--style ${STYLE}] [--out ${OUT_FILE}]
58+
```
59+
60+
示例:
61+
62+
- 绘制损失曲线
63+
64+
```shell
65+
python tools/analysis_tools/analyze_logs.py plot_curve log.json --keys loss_kpt --legend loss_kpt
66+
```
67+
68+
- 绘制精度曲线并导出为 PDF 文件
69+
70+
```shell
71+
python tools/analysis_tools/analyze_logs.py plot_curve log.json --keys acc_pose --out results.pdf
72+
```
73+
74+
- 将多个日志文件绘制在同一张图上
75+
76+
```shell
77+
python tools/analysis_tools/analyze_logs.py plot_curve log1.json log2.json --keys loss_kpt --legend run1 run2 --title loss_kpt --out loss_kpt.png
78+
```
79+
80+
### 统计训练速度
81+
82+
```shell
83+
python tools/analysis_tools/analyze_logs.py cal_train_time ${JSON_LOGS} [--include-outliers]
84+
```
85+
86+
示例:
87+
88+
```shell
89+
python tools/analysis_tools/analyze_logs.py cal_train_time log.json
90+
```
91+
92+
结果如下:
93+
94+
```text
95+
-----Analyze train time of hrnet_w32_256x192.json-----
96+
slowest epoch 56, average time is 0.6924
97+
fastest epoch 1, average time is 0.6502
98+
time std over epochs is 0.0085
99+
average iter time: 0.6688 s/iter
100+
```

0 commit comments

Comments
 (0)