Skip to content

Commit f6dca38

Browse files
[Doc] "Model Serving" Chinese doc in useful_tools.md (open-mmlab#761)
* Add Model Serving Chinese docs * Update docs_zh-CN/useful_tools.md Co-authored-by: Junjun2016 <[email protected]> * Update useful_tools.md * fix lint error Co-authored-by: Junjun2016 <[email protected]>
1 parent bfc3cdb commit f6dca38

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

docs/useful_tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ docker run --rm \
292292
mmseg-serve:latest
293293
```
294294

295-
[Read the docs](https://github.com/pytorch/serve/blob/072f5d088cce9bb64b2a18af065886c9b01b317b/docs/rest_api.md) about the Inference (8080), Management (8081) and Metrics (8082) APis
295+
[Read the docs](https://github.com/pytorch/serve/blob/072f5d088cce9bb64b2a18af065886c9b01b317b/docs/rest_api.md) about the Inference (8080), Management (8081) and Metrics (8082) APIs
296296

297297
### 4. Test deployment
298298

docs_zh-CN/useful_tools.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,64 @@ python tools/analyze_logs.py xxx.log.json [--keys ${KEYS}] [--legend ${LEGEND}]
258258
```shell
259259
python tools/analyze_logs.py log.json --keys loss --legend loss
260260
```
261+
262+
## 模型服务
263+
264+
为了用 [`TorchServe`](https://pytorch.org/serve/) 服务 `MMSegmentation` 的模型 , 您可以遵循如下流程:
265+
266+
### 1. 将 model 从 MMSegmentation 转换到 TorchServe
267+
268+
```shell
269+
python tools/mmseg2torchserve.py ${CONFIG_FILE} ${CHECKPOINT_FILE} \
270+
--output-folder ${MODEL_STORE} \
271+
--model-name ${MODEL_NAME}
272+
```
273+
274+
**注意**: ${MODEL_STORE} 需要设置为某个文件夹的绝对路径
275+
276+
### 2. 构建 `mmseg-serve` 容器镜像 (docker image)
277+
278+
```shell
279+
docker build -t mmseg-serve:latest docker/serve/
280+
```
281+
282+
### 3. 运行 `mmseg-serve`
283+
284+
请查阅官方文档: [使用容器运行 TorchServe](https://github.com/pytorch/serve/blob/master/docker/README.md#running-torchserve-in-a-production-docker-environment)
285+
286+
为了在 GPU 环境下使用, 您需要安装 [nvidia-docker](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html). 若在 CPU 环境下使用,您可以忽略添加 `--gpus` 参数。
287+
288+
示例:
289+
290+
```shell
291+
docker run --rm \
292+
--cpus 8 \
293+
--gpus device=0 \
294+
-p8080:8080 -p8081:8081 -p8082:8082 \
295+
--mount type=bind,source=$MODEL_STORE,target=/home/model-server/model-store \
296+
mmseg-serve:latest
297+
```
298+
299+
阅读关于推理 (8080), 管理 (8081) 和指标 (8082) APIs 的 [文档](https://github.com/pytorch/serve/blob/072f5d088cce9bb64b2a18af065886c9b01b317b/docs/rest_api.md)
300+
301+
### 4. 测试部署
302+
303+
```shell
304+
curl -O https://raw.githubusercontent.com/open-mmlab/mmsegmentation/master/resources/3dogs.jpg
305+
curl http://127.0.0.1:8080/predictions/${MODEL_NAME} -T 3dogs.jpg -o 3dogs_mask.png
306+
```
307+
308+
得到的响应将是一个 ".png" 的分割掩码.
309+
310+
您可以按照如下方法可视化输出:
311+
312+
```python
313+
import matplotlib.pyplot as plt
314+
import mmcv
315+
plt.imshow(mmcv.imread("3dogs_mask.png", "grayscale"))
316+
plt.show()
317+
```
318+
319+
看到的东西将会和下图类似:
320+
321+
![3dogs_mask](../resources/3dogs_mask.png)

0 commit comments

Comments
 (0)