diff --git a/docs/deploy/index.rst b/docs/deploy/index.rst index 23337c7d279ce624a22c048c6ffc716c72d89090..13aa36073b9b8385dcfc1a52bcd8be23a18f2e5e 100755 --- a/docs/deploy/index.rst +++ b/docs/deploy/index.rst @@ -9,5 +9,4 @@ export_model.md server/index nvidia-jetson.md - openvino/index paddlelite/index diff --git a/docs/deploy/paddlelite/android.md b/docs/deploy/paddlelite/android.md index ab37ce957f69c27ae33a7dca4fc00577b396b1d5..f932e7c8a3e5c9d2527f347636430b204f85b4aa 100644 --- a/docs/deploy/paddlelite/android.md +++ b/docs/deploy/paddlelite/android.md @@ -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 | 参数 | 说明 | | ---- | ---- | diff --git a/docs/deploy/paddlelite/slim/prune.md b/docs/deploy/paddlelite/slim/prune.md index 17d3c90e16eca13a404d569e8bf8664cdad6597f..f734308e5022d90d99d5b0ace089108f3d170b13 100644 --- a/docs/deploy/paddlelite/slim/prune.md +++ b/docs/deploy/paddlelite/slim/prune.md @@ -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预测速度 | | :-----| :--------| :-------- | :---------- |:---------- | :---------| diff --git a/docs/deploy/server/cpp/linux.md b/docs/deploy/server/cpp/linux.md index f75df4216fb45a0fc6dfbb12d93db7c99ebe9480..ee95a24d7726cf764de18ddb3a3a8bb3c80ac8d7 100644 --- a/docs/deploy/server/cpp/linux.md +++ b/docs/deploy/server/cpp/linux.md @@ -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` diff --git a/docs/deploy/server/cpp/windows.md b/docs/deploy/server/cpp/windows.md index e8c6a7054dd97e34d109930a8fce19dd78fd7638..aab06a9748a806c96b224ad70fce9b571ddbe134 100644 --- a/docs/deploy/server/cpp/windows.md +++ b/docs/deploy/server/cpp/windows.md @@ -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` diff --git a/docs/deploy/server/python.md b/docs/deploy/server/python.md index 50315650a4e808a785e2b5ec266ee2053bf238d2..6fd1a7ccc3c65d8d39640e7ca9e2b22447a2f76a 100644 --- a/docs/deploy/server/python.md +++ b/docs/deploy/server/python.md @@ -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张图片)预测速度才会稳定。 + ## 预测性能对比 ### 测试环境 diff --git a/docs/train/images/mask_predict.jpg b/docs/train/images/mask_predict.jpg new file mode 100644 index 0000000000000000000000000000000000000000..02ffca20ab8dab17655f5bce94712d3a3c5f4703 Binary files /dev/null and b/docs/train/images/mask_predict.jpg differ diff --git a/docs/train/images/yolo_predict.jpg b/docs/train/images/yolo_predict.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ff7eb75358629d53bfc859344697044d6ebce0ca Binary files /dev/null and b/docs/train/images/yolo_predict.jpg differ diff --git a/docs/train/instance_segmentation.md b/docs/train/instance_segmentation.md index bb2d9f3ecac5ca1a5e69edb0650599a2509db27f..4b066997bf83ccfbbbf08e31e6e8b78a8bbd3f9a 100644 --- a/docs/train/instance_segmentation.md +++ b/docs/train/instance_segmentation.md @@ -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 | - | - | 模型精度高,预测速度快,适用于服务端部署 | ## 开始训练 diff --git a/docs/train/object_detection.md b/docs/train/object_detection.md index 26c22679260cfc9ba84f45c909578cd08db59d8f..006a136ff0a8864026e8f80f3bd8127812588acb 100644 --- a/docs/train/object_detection.md +++ b/docs/train/object_detection.md @@ -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 | - | 模型精度高,预测速度快,适用于服务端部署 | ## 开始训练 diff --git a/docs/train/prediction.md b/docs/train/prediction.md index 51aa0833f8447b682929e92fec7fda7301d73880..0a57bff97bd4601654e6f17cd5e23d6b2b632b6a 100644 --- a/docs/train/prediction.md +++ b/docs/train/prediction.md @@ -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`接口可以满足用户一般的模型调研需求,如若为更高性能的预测部署,可以参考如下文档 diff --git a/paddlex/cv/models/mask_rcnn.py b/paddlex/cv/models/mask_rcnn.py index 204b22efd8a7c04d428afd408de8172a56016208..888cd21725b68ea7e467681f2ac42789c2a72d81 100644 --- a/paddlex/cv/models/mask_rcnn.py +++ b/paddlex/cv/models/mask_rcnn.py @@ -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, diff --git a/tutorials/compress/README.md b/tutorials/compress/README.md index 5bfcbd44ea63ac4f03932cb3b476e2a47f054f50..e85b4485143bcaa6b0f8cc7845eaa05ca17e83c8 100644 --- a/tutorials/compress/README.md +++ b/tutorials/compress/README.md @@ -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预先计算好的参数敏感度文件 ``` diff --git a/tutorials/compress/classification/README.md b/tutorials/compress/classification/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e711c1906366ad4d66798ccf9ef95b79804b5805 --- /dev/null +++ b/tutorials/compress/classification/README.md @@ -0,0 +1,3 @@ +# 说明 + +使用方式见[文档](../README.md) diff --git a/tutorials/compress/detection/README.md b/tutorials/compress/detection/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e711c1906366ad4d66798ccf9ef95b79804b5805 --- /dev/null +++ b/tutorials/compress/detection/README.md @@ -0,0 +1,3 @@ +# 说明 + +使用方式见[文档](../README.md) diff --git a/tutorials/compress/segmentation/README.md b/tutorials/compress/segmentation/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e711c1906366ad4d66798ccf9ef95b79804b5805 --- /dev/null +++ b/tutorials/compress/segmentation/README.md @@ -0,0 +1,3 @@ +# 说明 + +使用方式见[文档](../README.md)