From c0e5ce248d3d557eddd8ceae9d1fc45b677392ce Mon Sep 17 00:00:00 2001 From: huangjianhui <852142024@qq.com> Date: Thu, 18 Aug 2022 13:05:28 +0800 Subject: [PATCH] Create SegmentationResult doc and evaluation functions (#119) * Update README.md * Update README.md * Update README.md * Create README.md * Update README.md * Update README.md * Update README.md * Update README.md * Add evaluation calculate time and fix some bugs * Update classification __init__ * Move to ppseg * Add segmentation doc * Add PaddleClas infer.py * Update PaddleClas infer.py * Delete .infer.py.swp * Add PaddleClas infer.cc * Update README.md * Update README.md * Update README.md * Update infer.py * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Add PaddleSeg doc and infer.cc demo * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Create segmentation_result.md * Update README.md * Update segmentation_result.md * Update segmentation_result.md * Update segmentation_result.md * Update classification and detection evaluation function Co-authored-by: Jason --- .../vision/segmentation/ppseg/ppseg_pybind.cc | 1 - docs/api/vision_results/README.md | 3 +- .../api/vision_results/segmentation_result.md | 32 +++++++++++++++++++ .../classification/paddleclas/cpp/README.md | 2 +- fastdeploy/vision/evaluation/classify.py | 7 +++- fastdeploy/vision/evaluation/detection.py | 3 +- 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 docs/api/vision_results/segmentation_result.md diff --git a/csrc/fastdeploy/vision/segmentation/ppseg/ppseg_pybind.cc b/csrc/fastdeploy/vision/segmentation/ppseg/ppseg_pybind.cc index f2adc3512..3258e52b2 100644 --- a/csrc/fastdeploy/vision/segmentation/ppseg/ppseg_pybind.cc +++ b/csrc/fastdeploy/vision/segmentation/ppseg/ppseg_pybind.cc @@ -24,7 +24,6 @@ void BindPPSeg(pybind11::module& m) { pybind11::array& data) { auto mat = PyArrayToCvMat(data); vision::SegmentationResult* res = new vision::SegmentationResult(); - // self.Predict(&mat, &res); self.Predict(&mat, res); return res; }) diff --git a/docs/api/vision_results/README.md b/docs/api/vision_results/README.md index 64ea4fc67..f5628af6a 100644 --- a/docs/api/vision_results/README.md +++ b/docs/api/vision_results/README.md @@ -4,7 +4,8 @@ FastDeploy根据视觉模型的任务类型,定义了不同的结构体(`csrcs | 结构体 | 文档 | 说明 | 相应模型 | | :----- | :--- | :---- | :------- | -| ClassificationResult | [C++/Python文档](./classification_result.md) | 图像分类返回结果 | ResNet50、MobileNetV3等 | +| ClassifyResult | [C++/Python文档](./classification_result.md) | 图像分类返回结果 | ResNet50、MobileNetV3等 | +| SegmentationResult | [C++/Python文档](./segmentation_result.md) | 图像分割返回结果 | PP-HumanSeg、PP-LiteSeg等 | | DetectionResult | [C++/Python文档](./detection_result.md) | 目标检测返回结果 | PPYOLOE、YOLOv7系列模型等 | | FaceDetectionResult | [C++/Python文档](./face_detection_result.md) | 目标检测返回结果 | SCRFD、RetinaFace系列模型等 | | FaceRecognitionResult | [C++/Python文档](./face_recognition_result.md) | 目标检测返回结果 | ArcFace、CosFace系列模型等 | diff --git a/docs/api/vision_results/segmentation_result.md b/docs/api/vision_results/segmentation_result.md new file mode 100644 index 000000000..7228838e7 --- /dev/null +++ b/docs/api/vision_results/segmentation_result.md @@ -0,0 +1,32 @@ +# SegmentationResult 目标检测结果 + +SegmentationResult代码定义在`csrcs/fastdeploy/vision/common/result.h`中,用于表明图像中每个像素预测出来的分割类别和分割类别的概率值。 + +## C++ 定义 + +`fastdeploy::vision::DetectionResult` + +``` +struct DetectionResult { + std::vector label_map; + std::vector score_map; + std::vector shape; + bool contain_score_map = false; + void Clear(); + std::string Str(); +}; +``` + +- **label_map**: 成员变量,表示单张图片每个像素点的分割类别,`label_map.size()`表示图片像素点的个数 +- **score_map**: 成员变量,与label_map一一对应的所预测的分割类别概率值(当导出模型时指定`without_argmax`)或者经过softmax归一化化后的概率值(当导出模型时指定`without_argmax`以及`with_softmax`或者导出模型时指定`without_argmax`同时模型初始化的时候设置模型[类成员属性](../../../examples/vision/segmentation/paddleseg/cpp/)`with_softmax=True`) +- **shape**: 成员变量,表示输出图片的shape,为H\*W +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## Python 定义 + +`fastdeploy.vision.SegmentationResult` + +- **label_map**(list of int): 成员变量,表示单张图片每个像素点的分割类别 +- **score_map**(list of float): 成员变量,与label_map一一对应的所预测的分割类别概率值(当导出模型时指定`without_argmax`)或者经过softmax归一化化后的概率值(当导出模型时指定`without_argmax`以及`with_softmax`或者导出模型时指定`without_argmax`同时模型初始化的时候设置模型[类成员属性](../../../examples/vision/segmentation/paddleseg/python/)`with_softmax=true`) +- **shape**(list of int): 成员变量,表示输出图片的shape,为H\*W diff --git a/examples/vision/classification/paddleclas/cpp/README.md b/examples/vision/classification/paddleclas/cpp/README.md index 00efaa5bc..990d7cd70 100644 --- a/examples/vision/classification/paddleclas/cpp/README.md +++ b/examples/vision/classification/paddleclas/cpp/README.md @@ -16,7 +16,7 @@ tar xvf fastdeploy-linux-x64-gpu-0.2.0.tgz cd fastdeploy-linux-x64-gpu-0.2.0/examples/vision/classification/paddleclas/cpp mkdir build cd build -cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/../../../../../../fastdeploy-linux-x64-gpu-0.2.0 +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/../../../../../../../fastdeploy-linux-x64-gpu-0.2.0 make -j # 下载ResNet50_vd模型文件和测试图片 diff --git a/fastdeploy/vision/evaluation/classify.py b/fastdeploy/vision/evaluation/classify.py index 1e44f2368..a5c39252d 100644 --- a/fastdeploy/vision/evaluation/classify.py +++ b/fastdeploy/vision/evaluation/classify.py @@ -71,7 +71,12 @@ def eval_classify(model, image_file_path, label_file_path, topk=5): topk_acc_score = topk_accuracy(np.array(result_list), np.array(label_list)) if topk == 1: scores.update({'topk1': topk_acc_score}) + scores.update({ + 'topk1_average_inference_time(s)': average_inference_time + }) elif topk == 5: scores.update({'topk5': topk_acc_score}) - scores.update({'average_inference_time': average_inference_time}) + scores.update({ + 'topk5_average_inference_time(s)': average_inference_time + }) return scores diff --git a/fastdeploy/vision/evaluation/detection.py b/fastdeploy/vision/evaluation/detection.py index c1de8ed19..98c6794fe 100644 --- a/fastdeploy/vision/evaluation/detection.py +++ b/fastdeploy/vision/evaluation/detection.py @@ -28,6 +28,7 @@ def eval_detection(model, from .utils import COCOMetric import cv2 from tqdm import trange + import time if conf_threshold is not None or nms_iou_threshold is not None: assert conf_threshold is not None and nms_iou_threshold is not None, "The conf_threshold and nms_iou_threshold should be setted at the same time" @@ -80,6 +81,6 @@ def eval_detection(model, eval_metric.accumulate() eval_details = eval_metric.details scores.update(eval_metric.get()) - scores.update({'average_inference_time': average_inference_time}) + scores.update({'average_inference_time(s)': average_inference_time}) eval_metric.reset() return scores