Unverified Commit 9f0cc5a6 authored by jiang1997's avatar jiang1997 Committed by GitHub
Browse files

[WIP] Apply to translate "docs_zh_CN/understand_mmcv/utils.md" (#1232)



* Copy utils.md from docs

* Add Chinese translation of docs_zh_CN/understand_mmcv/utils.md

* recommit with pre-commit hook

* polish

* Update docs_zh_CN/understand_mmcv/utils.md
Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* Update docs_zh_CN/understand_mmcv/utils.md
Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>

* fix path of image

* set priority when build html
Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>
Co-authored-by: default avatarzhouzaida <zhouzaida@163.com>
parent 3168ffa2
...@@ -16,6 +16,7 @@ import sys ...@@ -16,6 +16,7 @@ import sys
from m2r import MdInclude from m2r import MdInclude
from recommonmark.transform import AutoStructify from recommonmark.transform import AutoStructify
from sphinx.builders.html import StandaloneHTMLBuilder
sys.path.insert(0, os.path.abspath('..')) sys.path.insert(0, os.path.abspath('..'))
...@@ -179,6 +180,10 @@ epub_title = project ...@@ -179,6 +180,10 @@ epub_title = project
# A list of files that should not be packed into the epub file. # A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html'] epub_exclude_files = ['search.html']
# set priority when building html
StandaloneHTMLBuilder.supported_image_types = [
'image/svg+xml', 'image/gif', 'image/png', 'image/jpeg'
]
# -- Extension configuration ------------------------------------------------- # -- Extension configuration -------------------------------------------------
......
...@@ -16,6 +16,7 @@ import sys ...@@ -16,6 +16,7 @@ import sys
from m2r import MdInclude from m2r import MdInclude
from recommonmark.transform import AutoStructify from recommonmark.transform import AutoStructify
from sphinx.builders.html import StandaloneHTMLBuilder
sys.path.insert(0, os.path.abspath('..')) sys.path.insert(0, os.path.abspath('..'))
...@@ -179,6 +180,10 @@ epub_title = project ...@@ -179,6 +180,10 @@ epub_title = project
# A list of files that should not be packed into the epub file. # A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html'] epub_exclude_files = ['search.html']
# set priority when building html
StandaloneHTMLBuilder.supported_image_types = [
'image/svg+xml', 'image/gif', 'image/png', 'image/jpeg'
]
# -- Extension configuration ------------------------------------------------- # -- Extension configuration -------------------------------------------------
......
## 辅助函数 ## 辅助函数
欢迎有兴趣的朋友一起翻译 MMCV 文档。如有兴趣,请在 [MMCV issue](https://github.com/open-mmlab/mmcv/issues) 提 issue 确定翻译的文档。 ### 进度条
如果你想跟踪函数批处理任务的进度,可以使用 `track_progress` 。它能以进度条的形式展示任务的完成情况以及剩余任务所需的时间(内部实现为for循环)。
```python
import mmcv
def func(item):
# 执行相关操作
pass
tasks = [item_1, item_2, ..., item_n]
mmcv.track_progress(func, tasks)
```
效果如下
![progress](../../docs/_static/progress.*)
如果你想可视化多进程任务的进度,你可以使用 `track_parallel_progress`
```python
mmcv.track_parallel_progress(func, tasks, 8) # 8 workers
```
![progress](../../docs/_static/parallel_progress.*)
如果你想要迭代或枚举数据列表并可视化进度,你可以使用 `track_iter_progress`
```python
import mmcv
tasks = [item_1, item_2, ..., item_n]
for task in mmcv.track_iter_progress(tasks):
# do something like print
print(task)
for i, task in enumerate(mmcv.track_iter_progress(tasks)):
# do something like print
print(i)
print(task)
```
### 计时器
mmcv提供的 `Timer` 可以很方便地计算代码块的执行时间。
```python
import time
with mmcv.Timer():
# simulate some code block
time.sleep(1)
```
你也可以使用 `since_start()``since_last_check()` 。前者返回计时器启动后的运行时长,后者返回最近一次查看计时器后的运行时长。
```python
timer = mmcv.Timer()
# code block 1 here
print(timer.since_start())
# code block 2 here
print(timer.since_last_check())
print(timer.since_start())
```
...@@ -14,6 +14,6 @@ line_length = 79 ...@@ -14,6 +14,6 @@ line_length = 79
multi_line_output = 0 multi_line_output = 0
known_standard_library = pkg_resources,setuptools,logging,os,warnings,abc known_standard_library = pkg_resources,setuptools,logging,os,warnings,abc
known_first_party = mmcv known_first_party = mmcv
known_third_party = addict,cv2,m2r,numpy,onnx,onnxruntime,packaging,pytest,recommonmark,scipy,tensorrt,torch,torchvision,yaml,yapf known_third_party = addict,cv2,m2r,numpy,onnx,onnxruntime,packaging,pytest,recommonmark,scipy,sphinx,tensorrt,torch,torchvision,yaml,yapf
no_lines_before = STDLIB,LOCALFOLDER no_lines_before = STDLIB,LOCALFOLDER
default_section = THIRDPARTY default_section = THIRDPARTY
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment