未验证 提交 4c9e2a62 编写于 作者: J Jason 提交者: GitHub

Merge pull request #214 from PaddlePaddle/jason

modify paddlelite docs
......@@ -9,5 +9,4 @@
export_model.md
server/index
nvidia-jetson.md
openvino/index
paddlelite/index
......@@ -11,8 +11,7 @@ PaddleX的安卓端部署由PaddleLite实现,部署的流程如下,首先将
## step 1. 将PaddleX模型导出为inference模型
参考[导出inference模型](../export_model.html)将模型导出为inference格式模型。
**注意:由于PaddleX代码的持续更新,版本低于1.0.0的模型暂时无法直接用于预测部署,参考[模型版本升级](../upgrade_version.md)对模型版本进行升级。**
参考[导出inference模型](../export_model.md)将模型导出为inference格式模型。
## step 2. 将inference模型优化为PaddleLite模型
......@@ -25,8 +24,9 @@ PaddleX的安卓端部署由PaddleLite实现,部署的流程如下,首先将
```bash
pip install paddlelite
python /PaddleX/deploy/lite/export_lite.py --model_dir /path/to/inference_model --save_file /path/to/lite_model_name --place place/to/run
python export_lite.py --model_dir /path/to/inference_model --save_file /path/to/lite_model_name --place place/to/run
```
> 其中`export_lite.py`脚本请至github下载:https://github.com/PaddlePaddle/PaddleX/blob/develop/deploy/lite/export_lite.py
| 参数 | 说明 |
| ---- | ---- |
......
......@@ -28,7 +28,7 @@ PaddleX提供了两种方式:
基于上述两种方案,我们在PaddleX上使用样例数据进行了实验,在Tesla P40上实验指标如下所示:
### 图像分类
实验背景:使用MobileNetV2模型,数据集为蔬菜分类示例数据,使用方法见[使用教程-模型压缩-图像分类](./tutorials/classification.html)
实验背景:使用MobileNetV2模型,数据集为蔬菜分类示例数据,裁剪训练代码见[tutorials/compress/classification](https://github.com/PaddlePaddle/PaddleX/tree/develop/tutorials/compress/classification)
| 模型 | 裁剪情况 | 模型大小 | Top1准确率(%) |GPU预测速度 | CPU预测速度 |
| :-----| :--------| :-------- | :---------- |:---------- |:----------|
......@@ -37,7 +37,7 @@ PaddleX提供了两种方式:
|MobileNetV2 | 方案二(eval_metric_loss=0.10) | 6.0M | 99.58 |5.42ms |29.06ms |
### 目标检测
实验背景:使用YOLOv3-MobileNetV1模型,数据集为昆虫检测示例数据,使用方法见[使用教程-模型压缩-目标检测](./tutorials/detection.html)
实验背景:使用YOLOv3-MobileNetV1模型,数据集为昆虫检测示例数据,裁剪训练代码见[tutorials/compress/detection](https://github.com/PaddlePaddle/PaddleX/tree/develop/tutorials/compress/detection)
| 模型 | 裁剪情况 | 模型大小 | MAP(%) |GPU预测速度 | CPU预测速度 |
| :-----| :--------| :-------- | :---------- |:---------- | :---------|
......@@ -46,7 +46,7 @@ PaddleX提供了两种方式:
|YOLOv3-MobileNetV1 | 方案二(eval_metric_loss=0.05) | 29M | 50.27| 9.43ms |360.46ms |
### 语义分割
实验背景:使用UNet模型,数据集为视盘分割示例数据,使用方法见[使用教程-模型压缩-语义分割](./tutorials/segmentation.html)
实验背景:使用UNet模型,数据集为视盘分割示例数据,裁剪训练代码见[tutorials/compress/segmentation](https://github.com/PaddlePaddle/PaddleX/tree/develop/tutorials/compress/segmentation)
| 模型 | 裁剪情况 | 模型大小 | mIOU(%) |GPU预测速度 | CPU预测速度 |
| :-----| :--------| :-------- | :---------- |:---------- | :---------|
......
......@@ -136,6 +136,8 @@ yaml-cpp.zip文件下载后无需解压,在cmake/yaml.cmake中将`URL https://
可使用[小度熊识别模型](../../export_model.md)中导出的`inference_model`和测试图片进行预测,导出到/root/projects,模型路径为/root/projects/inference_model。
> 关于预测速度的说明:Paddle在部署预测时,由于涉及到内存显存初始化等原因,在模型加载后刚开始预测速度会较慢,一般在模型运行20~50后(即预测20~30张图片)预测速度才会稳定。
`样例一`
不使用`GPU`测试图片 `/root/projects/images/xiaoduxiong.jpeg`
......
......@@ -129,6 +129,8 @@ cd D:\projects\PaddleX\deploy\cpp\out\build\x64-Release
可使用[小度熊识别模型](../../export_model.md)中导出的`inference_model`和测试图片进行预测, 例如导出到D:\projects,模型路径为D:\projects\inference_model。
> 关于预测速度的说明:Paddle在部署预测时,由于涉及到内存显存初始化等原因,在模型加载后刚开始预测速度会较慢,一般在模型运行20~50后(即预测20~30张图片)预测速度才会稳定。
### 样例一:(使用未加密的模型对单张图像做预测)
不使用`GPU`测试图片 `D:\images\xiaoduxiong.jpeg`
......
......@@ -5,8 +5,6 @@ PaddleX已经集成了基于Python的高性能预测接口,在安装PaddleX后
可参考[模型导出](../export_model.md)将模型导出为inference格式的模型。
## 预测部署
**注意:由于PaddleX代码的持续更新,版本低于1.0.0的模型暂时无法直接用于预测部署,参考[模型版本升级](../upgrade_version.md)对模型版本进行升级。**
> 点击下载测试图片 [xiaoduxiong_test_image.tar.gz](https://bj.bcebos.com/paddlex/datasets/xiaoduxiong_test_image.tar.gz)
```
......@@ -15,6 +13,8 @@ predictor = pdx.deploy.Predictor('./inference_model')
result = predictor.predict(image='xiaoduxiong_test_image/JPEGImages/WeChatIMG110.jpeg')
```
> 关于预测速度的说明:采用Paddle的Predictor进行预测时,由于涉及到内存显存初始化等原因,在模型加载后刚开始预测速度会较慢,一般在模型运行20~50后(即预测20~30张图片)预测速度才会稳定。
## 预测性能对比
### 测试环境
......
......@@ -10,9 +10,9 @@ PaddleX目前提供了MaskRCNN实例分割模型结构,多种backbone模型,
| 模型(点击获取代码) | Box MMAP/Seg MMAP | 模型大小 | GPU预测速度 | Arm预测速度 | 备注 |
| :---------------- | :------- | :------- | :--------- | :--------- | :----- |
| [MaskRCNN-ResNet50-FPN](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/instance_segmentation/mask_r50_fpn.py) | 36.5%/32.2% | 170.0MB | 160.185ms | - | 模型精度高,适用于服务端部署 |
| [MaskRCNN-ResNet18-FPN](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/instance_segmentation/mask_r18_fpn.py) | -/- | 120.0MB | - | - | 模型精度高,适用于服务端部署 |
| [MaskRCNN-HRNet-FPN](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/instance_segmentation/mask_hrnet_fpn.py) | -/- | 116.MB | - | - | 模型精度高,预测速度快,适用于服务端部署 |
| [MaskRCNN-ResNet50-FPN](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/instance_segmentation/mask_rcnn_r50_fpn.py) | 36.5%/32.2% | 170.0MB | 160.185ms | - | 模型精度高,适用于服务端部署 |
| [MaskRCNN-ResNet18-FPN](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/instance_segmentation/mask_rcnn_r18_fpn.py) | -/- | 120.0MB | - | - | 模型精度高,适用于服务端部署 |
| [MaskRCNN-HRNet-FPN](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/instance_segmentation/mask_rcnn_hrnet_fpn.py) | -/- | 116.MB | - | - | 模型精度高,预测速度快,适用于服务端部署 |
## 开始训练
......
......@@ -13,9 +13,9 @@ PaddleX目前提供了FasterRCNN和YOLOv3两种检测结构,多种backbone模型
| [YOLOv3-MobileNetV1](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/object_detection/yolov3_mobilenetv1.py) | 29.3% | 99.2MB | 15.442ms | - | 模型小,预测速度快,适用于低性能或移动端设备 |
| [YOLOv3-MobileNetV3](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/object_detection/yolov3_mobilenetv3.py) | 31.6% | 100.7MB | 143.322ms | - | 模型小,移动端上预测速度有优势 |
| [YOLOv3-DarkNet53](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/object_detection/yolov3_darknet53.py) | 38.9 | 249.2MB | 42.672ms | - | 模型较大,预测速度快,适用于服务端 |
| [FasterRCNN-ResNet50-FPN](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/object_detection/faster_r50_fpn.py) | 37.2% | 136.0MB | 197.715ms | - | 模型精度高,适用于服务端部署 |
| [FasterRCNN-ResNet18-FPN](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/object_detection/faster_r18_fpn.py) | - | - | - | - | 模型精度高,适用于服务端部署 |
| [FasterRCNN-HRNet-FPN](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/object_detection/faster_hrnet_fpn.py) | 36.0% | 115.MB | 81.592ms | - | 模型精度高,预测速度快,适用于服务端部署 |
| [FasterRCNN-ResNet50-FPN](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/object_detection/faster_rcnn_r50_fpn.py) | 37.2% | 136.0MB | 197.715ms | - | 模型精度高,适用于服务端部署 |
| [FasterRCNN-ResNet18-FPN](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/object_detection/faster_rcnn_r18_fpn.py) | - | - | - | - | 模型精度高,适用于服务端部署 |
| [FasterRCNN-HRNet-FPN](https://github.com/PaddlePaddle/PaddleX/blob/doc/tutorials/train/object_detection/faster_rcnn_hrnet_fpn.py) | 36.0% | 115.MB | 81.592ms | - | 模型精度高,预测速度快,适用于服务端部署 |
## 开始训练
......
......@@ -3,25 +3,63 @@
PaddleX可以使用`load_model`接口加载模型(包括训练过程中保存的模型,导出的部署模型,量化模型以及裁剪的模型)进行预测,同时PaddleX中也内置了一系列的可视化工具函数,帮助用户方便地检查模型的效果。
## 图像分类
> [点击下载](https://bj.bcebos.com/paddlex/models/mobilenetv3_small_ssld_imagenet.tar.gz)如下示例代码中模型
```
import paddlex as pdx
model = pdx.load_model('./mobilenetv2')
result = model.predict('./mobilenetv2/test.jpg')
test_jpg = 'mobilenetv3_small_ssld_imagenet/test.jpg'
model = pdx.load_model('mobilenetv3_small_ssld_imagenet')
result = model.predict(test_jpg)
print("Predict Result: ", result)
```
结果输入如下
```
Predict Result: [{'category_id': 21, 'category': 'killer_whale', 'score': 0.8262267}]
```
测试图片如下
- 分类模型predict接口[说明文档](../apis/models/classification.html#predict)
## 目标检测
> [点击下载](https://bj.bcebos.com/paddlex/models/yolov3_mobilenetv1_coco.tar.gz)如下示例代码中模型
```
import paddlex as pdx
test_jpg = 'yolov3_mobilenetv1_coco/test.jpg'
model = pdx.load_model('yolov3_mobilenetv1_coco')
# predict接口并未过滤低置信度识别结果,用户根据需求按score值进行过滤
result = model.predict(test_jpg)
## 目标检测和实例分割
# 可视化结果存储在./visualized_test.jpg, 见下图
pdx.det.visualize(test_jpg, result, threshold=0.3, save_dir='./')
```
- YOLOv3模型predict接口[说明文档](../apis/models/detection.html#predict)
- 可视化pdx.det.visualize接口[说明文档](../apis/visualize.html#paddlex-det-visualize)
> 注意:目标检测和实例分割模型在调用`predict`接口得到的结果需用户自行过滤低置信度结果,在`paddlex.det.visualize`接口中,我们提供了`threshold`用于过滤,置信度低于此值的结果将被过滤,不会可视化。
![](./images/yolo_predict.jpg)
## 实例分割
> [点击下载](https://bj.bcebos.com/paddlex/models/mask_r50_fpn_coco.tar.gz)如下示例代码中模型
```
import paddlex as pdx
test_jpg = './xiaoduxiong_epoch_12/test.jpg'
model = pdx.load_model('./xiaoduxiong_epoch_12')
test_jpg = 'mask_r50_fpn_coco/test.jpg'
model = pdx.load_model('mask_r50_fpn_coco')
# predict接口并未过滤低置信度识别结果,用户根据需求按score值进行过滤
result = model.predict(test_jpg)
pdx.det.visualize(test_jpg, result, thresh=0.5, save_dir='./')
# 可视化结果存储在./visualized_test.jpg, 见下图
pdx.det.visualize(test_jpg, result, threshold=0.5, save_dir='./')
```
在上述示例代码中,通过调用`paddlex.det.visualize`可以对目标检测/实例分割的预测结果进行可视化,可视化的结果保存在`save_dir`下。
> 注意:目标检测和实例分割模型在调用`predict`接口得到的结果需用户自行过滤低置信度结果,在`paddlex.det.visualize`接口中,我们提供了`thresh`用于过滤,置信度低于此值的结果将被过滤,不会可视化。
- MaskRCNN模型predict接口[说明文档](../apis/models/instance_segmentation.html#predict)
- 可视化pdx.det.visualize接口[说明文档](../apis/visualize.html#paddlex-det-visualize)
> 注意:目标检测和实例分割模型在调用`predict`接口得到的结果需用户自行过滤低置信度结果,在`paddlex.det.visualize`接口中,我们提供了`threshold`用于过滤,置信度低于此值的结果将被过滤,不会可视化。
![](./images/mask_predict.jpg)
## 语义分割
```
......@@ -31,6 +69,7 @@ model = pdx.load_model('./deeplabv3p_mobilenetv2_coco')
result = model.predict(test_jpg)
pdx.seg.visualize(test_jpg, result, weight=0.0, save_dir='./')
```
在上述示例代码中,通过调用`paddlex.seg.visualize`可以对语义分割的预测结果进行可视化,可视化的结果保存在`save_dir`下。其中`weight`参数用于调整预测结果和原图结果融合展现时的权重,0.0时只展示预测结果mask的可视化,1.0时只展示原图可视化。
......@@ -47,8 +86,8 @@ PaddleX提供了部分公开数据集上训练好的模型,用户可以直接
| 目标检测 | [YOLOv3-DarkNet53](https://bj.bcebos.com/paddlex/models/yolov3_darknet53_coco.tar.gz) | MSCOCO | 266MMB | Box MAP | 34.8% |
| 目标检测 | [YOLOv3-MobileNetV3](https://bj.bcebos.com/paddlex/models/yolov3_mobilenetv3_coco.tar.gz) | MSCOCO | 101MB | Box MAP | 31.6% |
| 实例分割 | [MaskRCNN-ResNet50-FPN](https://bj.bcebos.com/paddlex/models/mask_r50_fpn_coco.tar.gz) | MSCOCO | 193MB | Box MAP/Seg MAP | 38.7% / 34.7% |
| 语义分割 | [DeepLabv3p-Xception65]() | 人像分割 | xxMB | mIoU | - |
| 语义分割 | [HRNet_w18_small]() | 人像分割 | xxMB | mIou | - |
| 语义分割 | DeepLabv3p-Xception65 | 人像分割 | - | mIoU | - |
| 语义分割 | HRNet_w18_small | 人像分割 | - | mIou | - |
PaddleX的`load_model`接口可以满足用户一般的模型调研需求,如若为更高性能的预测部署,可以参考如下文档
......
......@@ -280,9 +280,8 @@ class MaskRCNN(FasterRCNN):
total_steps = math.ceil(eval_dataset.num_samples * 1.0 / batch_size)
results = list()
logging.info(
"Start to evaluating(total_samples={}, total_steps={})...".format(
eval_dataset.num_samples, total_steps))
logging.info("Start to evaluating(total_samples={}, total_steps={})...".
format(eval_dataset.num_samples, total_steps))
for step, data in tqdm.tqdm(
enumerate(data_generator()), total=total_steps):
images = np.array([d[0] for d in data]).astype('float32')
......@@ -326,8 +325,7 @@ class MaskRCNN(FasterRCNN):
zip(['bbox_map', 'segm_map'],
[ap_stats[0][1], ap_stats[1][1]]))
else:
metrics = OrderedDict(
zip(['bbox_map', 'segm_map'], [0.0, 0.0]))
metrics = OrderedDict(zip(['bbox_map', 'segm_map'], [0.0, 0.0]))
elif metric == 'COCO':
if isinstance(ap_stats[0], np.ndarray) and isinstance(ap_stats[1],
np.ndarray):
......@@ -397,7 +395,7 @@ class MaskRCNN(FasterRCNN):
res = {
k: (np.array(v), v.recursive_sequence_lengths())
for k, v in zip(lists(self.test_outputs.keys()), result)
for k, v in zip(list(self.test_outputs.keys()), result)
}
res['im_id'] = (np.array(
[[i] for i in range(len(images))]).astype('int32'), [])
......@@ -431,8 +429,8 @@ class MaskRCNN(FasterRCNN):
if transforms is None:
transforms = self.test_transforms
im, im_resize_info, im_shape = FasterRCNN._preprocess(
img_file_list, transforms, self.model_type,
self.__class__.__name__, thread_num)
img_file_list, transforms, self.model_type, self.__class__.__name__,
thread_num)
with fluid.scope_guard(self.scope):
result = self.exe.run(self.test_prog,
......
......@@ -22,9 +22,9 @@ PaddleX提供了两种裁剪训练方式,
# 训练模型
python classification/mobilenetv2.py
# 计算模型参数敏感度
python classification/cal_sensitivities_file.py --model_dir=output/mobilenetv2/epoch_10 --save_file=./sensitivities.data
python classification/cal_sensitivities_file.py --model_dir=output/mobilenetv2/best_model --save_file=./sensitivities.data
# 裁剪训练
python classification/mobilenetv2.py --model_dir=output/mobilenetv2/epoch_10 --sensitivities_file=./sensitivities.data --eval_metric_loss=0.05
python classification/mobilenetv2.py --model_dir=output/mobilenetv2/best_model --sensitivities_file=./sensitivities.data --eval_metric_loss=0.05
```
2. 第2种方法,使用PaddleX预先计算好的参数敏感度文件
```
......
# 说明
使用方式见[文档](../README.md)
# 说明
使用方式见[文档](../README.md)
# 说明
使用方式见[文档](../README.md)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册