FastDeploy项目简介,使用其进行(图像分类、目标检测、语义分割、文本检测|orc部署)

FastDeploy是一款全场景、易用灵活、极致高效的AI推理部署工具, 支持云边端部署。提供超过 🔥160+ Text,Vision, Speech和跨模态模型📦开箱即用的部署体验,并实现🔚端到端的推理性能优化。包括 物体检测、字符识别(OCR)、人脸、人像扣图、多目标跟踪系统、NLP、Stable Diffusion文图生成、TTS 等几十种任务场景,满足开发者多场景、多硬件、多平台的产业部署需求。
在这里插入图片描述

1、FastDeploy支持的环境

1.1 芯片支持

FastDeploy支持各个常见的硬件平台和各种国产化的芯片。例如华为的ascend
在这里插入图片描述

X86_64 CPU      





NVDIA GPU




飞腾 CPU
昆仑芯 XPU
华为昇腾 NPU
Graphcore IPU
算能
Intel 显卡
Jetson




ARM CPU

RK3588等
RV1126等
晶晨
恩智浦

1.2 编程语言支持

FastDeploy支持python、c++、java等开发语言,同时还支持web与小程序部署。
在这里插入图片描述

1.3 操作系统支持

FastDeploy支持linux、windows、mac、安卓部署。
在这里插入图片描述

1.4 推理后端支持

FastDeploy对各种推理后端接口均做了封装,可以以一种代码风格同时调用onnx、paddle infer、tensorrt、openvino等推理框架。
在这里插入图片描述

2、安装与使用

本博文对应的代码和模型资源可以进行付费下载,也可以参考博文资料轻松实现复现。

2.1 安装命令

🔸 前置依赖
  • CUDA >= 11.2、cuDNN >= 8.0、Python >= 3.6
  • OS: Linux x86_64/macOS/Windows 10
🔸 安装GPU版本
pip install numpy opencv-python fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html
🔸 Conda安装(推荐✨)
conda config --add channels conda-forge && conda install cudatoolkit=11.2 cudnn=8.2
🔸 安装CPU版本
pip install numpy opencv-python fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html

最终安装成功的输出如下所示
在这里插入图片描述

2.2 部署图像分类模型

下载paddle官方的预训练模型,https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz,也可以使用自己基于paddleclas训练的模型
将以下图片保存为000000014439.jpg
请添加图片描述
预测代码如下所示,使用onnxruntime-gpu进行推理

# GPU/TensorRT部署参考 examples/vision/detection/paddledetection/python
import cv2
import fastdeploy as fd
import fastdeploy.vision as vision
import ipdboption = fd.RuntimeOption()
#option.use_trt_backend()
option.use_gpu(device_id=0) #使用0号gpu进行预测
option.use_ort_backend() #使用onnxruntime作为后端model_file="ResNet50_vd_infer/inference.pdmodel"
params_file="ResNet50_vd_infer/inference.pdiparams"
config_file="ResNet50_vd_infer/inference_cls.yaml"
model = fd.vision.classification.PaddleClasModel(model_file, params_file, config_file, runtime_option=option)
im = cv2.imread("000000014439.jpg")
result = model.predict(im, topk=5)
print(type(result),dir(result))
print(result)

程序运行后输出如下所示:

[INFO] fastdeploy/vision/common/processors/transform.cc(93)::fastdeploy::vision::FuseNormalizeHWC2CHW                                                                  Normalize and HWC2CHW are fused to NormalizeAndPermute  in preprocessing pipeline.
[INFO] fastdeploy/vision/common/processors/transform.cc(159)::fastdeploy::vision::FuseNormalizeColorConvert                                                            BGR2RGB and NormalizeAndPermute are fused to NormalizeAndPermute with swap_rb=1
[INFO] fastdeploy/runtime/runtime.cc(300)::fastdeploy::Runtime::CreateOrtBackend                                                                                       Runtime initialized with Backend::ORT in Device::GPU.
<class 'fastdeploy.libs.fastdeploy_main.vision.ClassifyResult'> ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', 'feature', 'label_ids', 'scores']
ClassifyResult(
label_ids: 701, 879, 417, 645, 723, 
scores: 0.424514, 0.084369, 0.058738, 0.016847, 0.013349, 
)

从以上输出中可以看到,预测结果又’feature’, ‘label_ids’, 'scores’三个属性。

2.2 部署目标检测模型

下载paddle官方的预训练模型,也可以使用自己导出的paddle infer模型。
https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz
将以下图片保存为000000014439.jpg
请添加图片描述

预测代码如下所示

# GPU/TensorRT部署参考 examples/vision/detection/paddledetection/python
import cv2
import fastdeploy.vision as visionmodel = vision.detection.PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel","ppyoloe_crn_l_300e_coco/model.pdiparams","ppyoloe_crn_l_300e_coco/infer_cfg.yml")
im = cv2.imread("000000014439.jpg")
result = model.predict(im)
print(result)vis_im = vision.vis_detection(im, result, score_threshold=0.5)
cv2.imshow("vis_image.jpg", vis_im)
cv2.waitKey()
#cv2.imwrite("vis_image.jpg", vis_im)

程序运行时的输出如下所示,可见默认是使用OPENVINO cpu进行推理。其返回结果为DetectionResult对象,其一共有’boxes’, ‘contain_masks’, ‘label_ids’, ‘masks’, ‘rotated_boxes’, 'scores’等属性。其中boxes是xmin, ymin, xmax, ymax,格式的数据,其默认只返回nms操作后的top 300个结果,后续需要自己根据scores进行结果过滤。

[INFO] fastdeploy/vision/common/processors/transform.cc(45)::fastdeploy::vision::FuseNormalizeCast      Normalize and Cast are fused to Normalize in preprocessing pipeline.
[INFO] fastdeploy/vision/common/processors/transform.cc(93)::fastdeploy::vision::FuseNormalizeHWC2CHW   Normalize and HWC2CHW are fused to NormalizeAndPermute  in preprocessing pipeline.
[INFO] fastdeploy/vision/common/processors/transform.cc(159)::fastdeploy::vision::FuseNormalizeColorConvert     BGR2RGB and NormalizeAndPermute are fused to NormalizeAndPermute with swap_rb=1
[INFO] fastdeploy/runtime/backends/openvino/ov_backend.cc(218)::fastdeploy::OpenVINOBackend::InitFromPaddle     number of streams:1.
[INFO] fastdeploy/runtime/backends/openvino/ov_backend.cc(228)::fastdeploy::OpenVINOBackend::InitFromPaddle     affinity:YES.
[INFO] fastdeploy/runtime/backends/openvino/ov_backend.cc(240)::fastdeploy::OpenVINOBackend::InitFromPaddle     Compile OpenVINO model on device_name:CPU.
[INFO] fastdeploy/runtime/runtime.cc(286)::fastdeploy::Runtime::CreateOpenVINOBackend   Runtime initialized with Backend::OPENVINO in Device::CPU.
DetectionResult: [xmin, ymin, xmax, ymax, score, label_id]
415.047180,89.311569, 506.009613, 283.863098, 0.950423, 0
163.665710,81.914932, 198.585342, 166.760895, 0.896433, 0
581.788635,113.027618, 612.623474, 198.521713, 0.842596, 0
267.217224,89.777306, 298.796051, 169.361526, 0.837951, 0
104.465584,45.482422, 127.688850, 93.533867, 0.773348, 0
348.902130,44.059338, 367.541687, 98.403542, 0.767127, 0
363.889740,58.385532, 381.397522, 114.652367, 0.756467, 0
504.843811,114.531601, 612.280945, 271.292572, 0.714129, 0

2.4 部署语义分割模型

下载paddle发布的预训练模型SegFormer_B0,也可以使用paddleseg训练后导出模型。

https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz
将以下图片保存为000000014439.jpg
请添加图片描述

预测代码如下所示

# GPU/TensorRT部署参考 examples/vision/detection/paddledetection/python
import cv2
import fastdeploy as fd
import fastdeploy.vision as vision
import numpy as np
import ipdb
def get_color_map_list(num_classes):"""Args:num_classes (int): number of classReturns:color_map (list): RGB color list"""color_map = num_classes * [0, 0, 0]for i in range(0, num_classes):j = 0lab = iwhile lab:color_map[i * 3] |= (((lab >> 0) & 1) << (7 - j))color_map[i * 3 + 1] |= (((lab >> 1) & 1) << (7 - j))color_map[i * 3 + 2] |= (((lab >> 2) & 1) << (7 - j))j += 1lab >>= 3color_map = [color_map[i:i + 3] for i in range(0, len(color_map), 3)]return color_mapcolor_map=get_color_map_list(80) #80个类别
color_map=np.array(color_map).astype(np.uint8)option = fd.RuntimeOption()
#option.use_kunlunxin() #使用昆仑芯片进行部署
#option.use_lite_backend()
option.use_paddle_infer_backend()model_file="SegFormer_B0-cityscapes-with-argmax/model.pdmodel"
params_file="SegFormer_B0-cityscapes-with-argmax/model.pdiparams"
config_file="SegFormer_B0-cityscapes-with-argmax/deploy.yaml"
model = fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=option)
im = cv2.imread("000000014439.jpg")
result = model.predict(im)
print(type(result),dir(result))
print(result)
#ipdb.set_trace()
res=np.array(result.label_map,np.uint8)
res=res.reshape(result.shape)res=color_map[res] #为结果上色
cv2.imshow("label_map",res)
cv2.waitKey()

代码运行时输出如下所示:


[INFO] fastdeploy/vision/common/processors/transform.cc(93)::fastdeploy::vision::FuseNormalizeHWC2CHW                                                                  Normalize and HWC2CHW are fused to NormalizeAndPermute  in preprocessing pipeline.
[INFO] fastdeploy/vision/common/processors/transform.cc(159)::fastdeploy::vision::FuseNormalizeColorConvert                                                            BGR2RGB and NormalizeAndPermute are fused to NormalizeAndPermute with swap_rb=1
WARNING: Logging before InitGoogleLogging() is written to STDERR
W0125 21:32:56.195503  5356 analysis_config.cc:971] It is detected that mkldnn and memory_optimize_pass are enabled at the same time, but they are not supported yet. Currently, memory_optimize_pass is explicitly disabled
[INFO] fastdeploy/runtime/runtime.cc(273)::fastdeploy::Runtime::CreatePaddleBackend                                                                                    Runtime initialized with Backend::PDINFER in Device::CPU.
<class 'fastdeploy.libs.fastdeploy_main.vision.SegmentationResult'> ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', 'contain_score_map', 'label_map', 'score_map', 'shape']
SegmentationResult Image masks 10 rows x 10 cols:
[4, 4, 4, 4, 4, 2, 2, 2, 2, 2, .....]
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, .....]
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, .....]
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, .....]
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, .....]
[2, 2, 2, 2, 2, 2, 2, 4, 4, 4, .....]
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, .....]
[4, 4, 2, 2, 2, 2, 2, 2, 2, 2, .....]
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, .....]
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, .....]
...........
result shape is: [404 640]

运行效果如下所示
在这里插入图片描述

2.5 部署文本识别模型

进行全流程文本识别

首先下载以下模型,可以手动打开http链接进行下载。

下载PP-OCRv3文字检测模型

wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar
tar -xvf ch_PP-OCRv3_det_infer.tar

下载文字方向分类器模型

wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar
tar -xvf ch_ppocr_mobile_v2.0_cls_infer.tar

下载PP-OCRv3文字识别模型

wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar
tar -xvf ch_PP-OCRv3_rec_infer.tar

准备label文件

下载ppocr_keys_v1.txt,保存到代码目录下。

准备测试文件

将以下图片保存为12.jpg 在这里插入图片描述
测试代码如下所示;

# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.import fastdeploy as fd
import cv2
import osdef parse_arguments():import argparseimport astparser = argparse.ArgumentParser()parser.add_argument("--det_model", default="ch_PP-OCRv3_det_infer", help="Path of Detection model of PPOCR.")parser.add_argument("--cls_model",default="ch_ppocr_mobile_v2.0_cls_infer",help="Path of Classification model of PPOCR.")parser.add_argument("--rec_model",default="ch_PP-OCRv3_rec_infer",help="Path of Recognization model of PPOCR.")parser.add_argument("--rec_label_file",default="ppocr_keys_v1.txt",help="Path of Recognization model of PPOCR.")parser.add_argument("--image", type=str, default="12.jpg", help="Path of test image file.")parser.add_argument("--device",type=str,default='cpu',help="Type of inference device, support 'cpu' or 'gpu'.")parser.add_argument("--device_id",type=int,default=0,help="Define which GPU card used to run model.")parser.add_argument("--cls_bs",type=int,default=1,help="Classification model inference batch size.")parser.add_argument("--rec_bs",type=int,default=6,help="Recognition model inference batch size")parser.add_argument("--backend",type=str,default="openvino",help="Type of inference backend, support ort/trt/paddle/openvino, default 'openvino' for cpu, 'tensorrt' for gpu")return parser.parse_args()def build_option(args):det_option = fd.RuntimeOption()cls_option = fd.RuntimeOption()rec_option = fd.RuntimeOption()if args.device.lower() == "gpu":det_option.use_gpu(args.device_id)cls_option.use_gpu(args.device_id)rec_option.use_gpu(args.device_id)if args.backend.lower() == "trt":assert args.device.lower() == "gpu", "TensorRT backend require inference on device GPU."det_option.use_trt_backend()cls_option.use_trt_backend()rec_option.use_trt_backend()# If use TRT backend, the dynamic shape will be set as follow.# We recommend that users set the length and height of the detection model to a multiple of 32.# We also recommend that users set the Trt input shape as follow.det_option.set_trt_input_shape("x", [1, 3, 64, 64], [1, 3, 640, 640],[1, 3, 960, 960])cls_option.set_trt_input_shape("x", [1, 3, 48, 10],[args.cls_bs, 3, 48, 320],[args.cls_bs, 3, 48, 1024])rec_option.set_trt_input_shape("x", [1, 3, 48, 10],[args.rec_bs, 3, 48, 320],[args.rec_bs, 3, 48, 2304])# Users could save TRT cache file to disk as follow.det_option.set_trt_cache_file(args.det_model + "/det_trt_cache.trt")cls_option.set_trt_cache_file(args.cls_model + "/cls_trt_cache.trt")rec_option.set_trt_cache_file(args.rec_model + "/rec_trt_cache.trt")elif args.backend.lower() == "pptrt":assert args.device.lower() == "gpu", "Paddle-TensorRT backend require inference on device GPU."det_option.use_paddle_infer_backend()det_option.paddle_infer_option.collect_trt_shape = Truedet_option.paddle_infer_option.enable_trt = Truecls_option.use_paddle_infer_backend()cls_option.paddle_infer_option.collect_trt_shape = Truecls_option.paddle_infer_option.enable_trt = Truerec_option.use_paddle_infer_backend()rec_option.paddle_infer_option.collect_trt_shape = Truerec_option.paddle_infer_option.enable_trt = True# If use TRT backend, the dynamic shape will be set as follow.# We recommend that users set the length and height of the detection model to a multiple of 32.# We also recommend that users set the Trt input shape as follow.det_option.set_trt_input_shape("x", [1, 3, 64, 64], [1, 3, 640, 640],[1, 3, 960, 960])cls_option.set_trt_input_shape("x", [1, 3, 48, 10],[args.cls_bs, 3, 48, 320],[args.cls_bs, 3, 48, 1024])rec_option.set_trt_input_shape("x", [1, 3, 48, 10],[args.rec_bs, 3, 48, 320],[args.rec_bs, 3, 48, 2304])# Users could save TRT cache file to disk as follow.det_option.set_trt_cache_file(args.det_model)cls_option.set_trt_cache_file(args.cls_model)rec_option.set_trt_cache_file(args.rec_model)elif args.backend.lower() == "ort":det_option.use_ort_backend()cls_option.use_ort_backend()rec_option.use_ort_backend()elif args.backend.lower() == "paddle":det_option.use_paddle_infer_backend()cls_option.use_paddle_infer_backend()rec_option.use_paddle_infer_backend()elif args.backend.lower() == "openvino":assert args.device.lower() == "cpu", "OpenVINO backend require inference on device CPU."det_option.use_openvino_backend()cls_option.use_openvino_backend()rec_option.use_openvino_backend()elif args.backend.lower() == "pplite":assert args.device.lower() == "cpu", "Paddle Lite backend require inference on device CPU."det_option.use_lite_backend()cls_option.use_lite_backend()rec_option.use_lite_backend()return det_option, cls_option, rec_optionargs = parse_arguments()det_model_file = os.path.join(args.det_model, "inference.pdmodel")
det_params_file = os.path.join(args.det_model, "inference.pdiparams")cls_model_file = os.path.join(args.cls_model, "inference.pdmodel")
cls_params_file = os.path.join(args.cls_model, "inference.pdiparams")rec_model_file = os.path.join(args.rec_model, "inference.pdmodel")
rec_params_file = os.path.join(args.rec_model, "inference.pdiparams")
rec_label_file = args.rec_label_filedet_option, cls_option, rec_option = build_option(args)det_model = fd.vision.ocr.DBDetector(det_model_file, det_params_file, runtime_option=det_option)cls_model = fd.vision.ocr.Classifier(cls_model_file, cls_params_file, runtime_option=cls_option)rec_model = fd.vision.ocr.Recognizer(rec_model_file, rec_params_file, rec_label_file, runtime_option=rec_option)# Parameters settings for pre and post processing of Det/Cls/Rec Models.
# All parameters are set to default values.
det_model.preprocessor.max_side_len = 960
det_model.postprocessor.det_db_thresh = 0.3
det_model.postprocessor.det_db_box_thresh = 0.6
det_model.postprocessor.det_db_unclip_ratio = 1.5
det_model.postprocessor.det_db_score_mode = "slow"
det_model.postprocessor.use_dilation = False
cls_model.postprocessor.cls_thresh = 0.9# Create PP-OCRv3, if cls_model is not needed, just set cls_model=None .
ppocr_v3 = fd.vision.ocr.PPOCRv3(det_model=det_model, cls_model=cls_model, rec_model=rec_model)# Set inference batch size for cls model and rec model, the value could be -1 and 1 to positive infinity.
# When inference batch size is set to -1, it means that the inference batch size
# of the cls and rec models will be the same as the number of boxes detected by the det model.
ppocr_v3.cls_batch_size = args.cls_bs
ppocr_v3.rec_batch_size = args.rec_bs# Read the input image
im = cv2.imread(args.image)# Predict and reutrn the results
result = ppocr_v3.predict(im)print(result)# Visuliaze the results.
vis_im = fd.vision.vis_ppocr(im, result)
cv2.imwrite("visualized_result.jpg", vis_im)
cv2.imshow("visualized_result.jpg", vis_im)
cv2.waitKey()
print("Visualized result save in ./visualized_result.jpg")

以上代码基于paddleocr的官方代码改进而来,故而可以参考官方的命令参数进行使用

```# 在CPU上使用Paddle Inference推理
python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device cpu --backend paddle
# 在CPU上使用OenVINO推理
python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device cpu --backend openvino
# 在CPU上使用ONNX Runtime推理
python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device cpu --backend ort
# 在CPU上使用Paddle Lite推理
python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device cpu --backend pplite
# 在GPU上使用Paddle Inference推理
python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu --backend paddle
# 在GPU上使用Paddle TensorRT推理
python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu --backend pptrt
# 在GPU上使用ONNX Runtime推理
python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu --backend ort
# 在GPU上使用Nvidia TensorRT推理
python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu --backend trt

代码运行效果图如下所示
在这里插入图片描述
程序运行时输出如下所示,可以看到大部分文字都准确识别了。

[INFO] fastdeploy/runtime/backends/openvino/ov_backend.cc(218)::fastdeploy::OpenVINOBackend::InitFromPaddle                                                            number of streams:1.
[INFO] fastdeploy/runtime/backends/openvino/ov_backend.cc(228)::fastdeploy::OpenVINOBackend::InitFromPaddle                                                            affinity:YES.
[INFO] fastdeploy/runtime/backends/openvino/ov_backend.cc(240)::fastdeploy::OpenVINOBackend::InitFromPaddle                                                            Compile OpenVINO model on device_name:CPU.
[INFO] fastdeploy/runtime/runtime.cc(286)::fastdeploy::Runtime::CreateOpenVINOBackend                                                                                  Runtime initialized with Backend::OPENVINO in Device::CPU.
[INFO] fastdeploy/runtime/backends/openvino/ov_backend.cc(218)::fastdeploy::OpenVINOBackend::InitFromPaddle                                                            number of streams:1.
[INFO] fastdeploy/runtime/backends/openvino/ov_backend.cc(228)::fastdeploy::OpenVINOBackend::InitFromPaddle                                                            affinity:YES.
[INFO] fastdeploy/runtime/backends/openvino/ov_backend.cc(240)::fastdeploy::OpenVINOBackend::InitFromPaddle                                                            Compile OpenVINO model on device_name:CPU.
[INFO] fastdeploy/runtime/runtime.cc(286)::fastdeploy::Runtime::CreateOpenVINOBackend                                                                                  Runtime initialized with Backend::OPENVINO in Device::CPU.
[INFO] fastdeploy/runtime/backends/openvino/ov_backend.cc(218)::fastdeploy::OpenVINOBackend::InitFromPaddle                                                            number of streams:1.
[INFO] fastdeploy/runtime/backends/openvino/ov_backend.cc(228)::fastdeploy::OpenVINOBackend::InitFromPaddle                                                            affinity:YES.
[INFO] fastdeploy/runtime/backends/openvino/ov_backend.cc(240)::fastdeploy::OpenVINOBackend::InitFromPaddle                                                            Compile OpenVINO model on device_name:CPU.
[INFO] fastdeploy/runtime/runtime.cc(286)::fastdeploy::Runtime::CreateOpenVINOBackend                                                                                  Runtime initialized with Backend::OPENVINO in Device::CPU.
det boxes: [[42,413],[483,391],[484,428],[43,450]]rec text: 上海斯格威铂尔大酒店 rec score:0.989301 cls label: 0 cls score: 1.000000
det boxes: [[187,456],[399,448],[400,480],[188,488]]rec text: 打浦路15号 rec score:0.994266 cls label: 0 cls score: 1.000000
det boxes: [[23,507],[513,488],[515,529],[24,548]]rec text: 绿洲仕格维花园公寓 rec score:0.984679 cls label: 0 cls score: 1.000000
det boxes: [[74,553],[427,542],[428,571],[75,582]]rec text: 打浦路252935号 rec score:0.996439 cls label: 0 cls score: 1.000000
Visualized result save in ./visualized_result.jpg
对文本切片进行识别
模型简介模型名称推荐场景检测模型方向分类器识别模型
中英文超轻量PP-OCRv4模型(15.8M)ch_PP-OCRv4_xx移动端&服务器端推理模型 / 训练模型推理模型 / 训练模型推理模型 / 训练模型
中英文超轻量PP-OCRv3模型(16.2M)ch_PP-OCRv3_xx移动端&服务器端推理模型 / 训练模型推理模型 / 训练模型推理模型 / 训练模型
英文超轻量PP-OCRv3模型(13.4M)en_PP-OCRv3_xx移动端&服务器端推理模型 / 训练模型推理模型 / 训练模型推理模型 / 训练模型

各位可以自行截图生成如下图片,保存为13.jpg
在这里插入图片描述
识别代码如下所示,识别效果十分棒,各位可以换成自己的文本切片。

import fastdeploy as fd
import cv2
import osrec_model_file = os.path.join('ch_ppocr_mobile_v2.0_cls_infer', "inference.pdmodel")
rec_params_file = os.path.join('ch_ppocr_mobile_v2.0_cls_infer', "inference.pdiparams")
rec_label_file = "ppocr_keys_v1.txt"# Set the runtime option
rec_option =  fd.RuntimeOption()
rec_option.use_ort_backend()# Create the rec_model
rec_model = fd.vision.ocr.Recognizer(rec_model_file, rec_params_file, rec_label_file, runtime_option=rec_option)# Read the image
im = cv2.imread("13.jpg")# Predict and return the result
result = rec_model.predict(im)
print(type(result),dir(result))
# User can infer a batch of images by following code.
# result = rec_model.batch_predict([im])print(result)

识别结果如下所示,可以看到识别结果完全正确。

[INFO] fastdeploy/runtime/runtime.cc(300)::fastdeploy::Runtime::CreateOrtBackend        Runtime initialized with Backend::ORT in Device::CPU.
<class 'fastdeploy.libs.fastdeploy_main.vision.OCRResult'> ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'boxes', 'cls_labels', 'cls_scores', 'rec_scores', 'text']
rec text: 绿洲仕格维花园公寓 rec score:0.988077

3、其他功能

前文仅描述了常见功能的python使用,在faskdeploy还提供了c++部署案列,其python接口与c++接口基本一致。

除了图像分类、目标检测、语义分割、文本识别等功能外,faskdeploy还提供了人脸检测、人脸特征点、人脸识别、生成式模型、姿态检测、扣图、图像超分、目标跟踪等功能的部署案例。后续有使用到会在这里补充案例。
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/647105.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

自动 CAPTCHA 解决方案,最佳 CAPTCHA 解决方案扩展 2024?

自动 CAPTCHA 解决方案&#xff0c;最佳 CAPTCHA 解决方案扩展 2024&#xff1f; 在迅速发展的数字领域中&#xff0c;高效的 CAPTCHA&#xff08;Completely Automated Public Turing tests to tell Computers and Humans Apart&#xff0c;完全自动化的全球公共图灵测试&…

JavaScript 执行上下文与作用域

执行上下文与作用域 ​ 执行上下文的概念在 JavaScript 中是颇为重要的。变量或函数的上下文决定了它们可以访问哪些数据&#xff0c;以及它们的行为。每个上下文都有一个关联的变量对象&#xff08;variable object&#xff09;&#xff0c; 而这个上下文中定义的所有变量和函…

C++:使用tinyXML生成矢量图svg

先说一下tinyXML库的配置&#xff1a; 很简单&#xff0c;去下面官网下载 TinyXML download | SourceForge.net 解压后是这样 直接将红框中的几个文件放到项目中即可使用 关于svg文件&#xff0c;SVG是基于XML的可扩展矢量图形&#xff0c;svg是xml文件&#xff0c;但是xml…

软件安装SQLyog

SQLyog 安装配置使用 首先下载SQLyog 软件&#xff0c;并解压 选择自己操作系统的版本 双击点击 .exe 文件&#xff0c;进行安装 选择安装语言&#xff0c;默认中文&#xff0c;直接点击【OK】即可 点击【下一步】 先【勾选】同意协议&#xff0c;再点击【下一步】 …

详解SpringCloud微服务技术栈:ElasticSearch实践1——RestClient操作索引库与文档

&#x1f468;‍&#x1f393;作者简介&#xff1a;一位大四、研0学生&#xff0c;正在努力准备大四暑假的实习 &#x1f30c;上期文章&#xff1a;详解SpringCloud微服务技术栈&#xff1a;ElasticSearch原理精讲、安装、实践 &#x1f4da;订阅专栏&#xff1a;微服务技术全家…

【Tailwind】各种样式的进度条

基本样式进度条&#xff1a; <div class"mb-5 h-2 rounded-full bg-gray-200"><div class"h-2 rounded-full bg-orange-500" style"width: 50%"></div> </div>带文字的进度条&#xff1a; <div class"relativ…

npm install报错certificate has expired

报错&#xff1a; reason: certificate has expired 解决&#xff1a;更换npm镜像源 登录到服务器上&#xff0c;更换npm镜像源(或者在jenkins上配置) npm config set registry http://registry.cnpmjs.org npm config set registry http://registry.npm.taobao.org #如果上面…

人工智能时代:让AIGC成为你的外部智慧源(文末送书)

&#x1f308;个人主页&#xff1a;聆风吟 &#x1f525;系列专栏&#xff1a;数据结构、网络奇遇记 &#x1f516;少年有梦不应止于心动&#xff0c;更要付诸行动。 文章目录 &#x1f4cb;前言一. 什么是AIGC?二. AIGC如何运作&#xff1f;2.1 步骤一&#xff1a;收集数据2.…

postgresql12表膨胀解决(不锁表)

查看所有数据库占用磁盘空间 SELECTpg_database.datname AS "数据库名称",pg_size_pretty(pg_database_size(pg_database.datname)) AS "磁盘占用空间" FROMpg_database;发现有个数据库占用空间过大 查询库中所有表占用空间 SELECTtable_name,pg_size_…

Lucene 源码分析——BKD-Tree

Lucene 源码分析——BKD-Tree - AIQ Bkd-Tree Bkd-Tree作为一种基于K-D-B-tree的索引结构&#xff0c;用来对多维度的点数据(multi-dimensional point data)集进行索引。Bkd-Tree跟K-D-B-tree的理论部分在本篇文章中不详细介绍&#xff0c;对应的两篇论文在附件中&#xff0c…

【LangChain学习之旅】—(9) 用SequencialChain链接不同的组件

【LangChain学习之旅】—&#xff08;9&#xff09;用SequencialChain链接不同的组件 什么是 ChainLLMChain&#xff1a;最简单的链链的调用方式直接调用通过 run 方法通过 predict 方法通过 apply 方法通过 generate 方法 Sequential Chain&#xff1a;顺序链首先&#xff0c;…

Oracle篇—分区表的管理(第二篇,总共五篇)

☘️博主介绍☘️&#xff1a; ✨又是一天没白过&#xff0c;我是奈斯&#xff0c;DBA一名✨ ✌✌️擅长Oracle、MySQL、SQLserver、Linux&#xff0c;也在积极的扩展IT方向的其他知识面✌✌️ ❣️❣️❣️大佬们都喜欢静静的看文章&#xff0c;并且也会默默的点赞收藏加关注❣…

day2C++

思维导图 Rect类 #include <iostream>using namespace std;class my_Rect { private:int width;int height;public://初始化void init(){cout << "please ener w and h" << endl;cin >> width;cin >> height;cout << "suc…

Linux入门攻坚——14、实战软件安装-搭建Python3.8环境-2

上一篇解决了openssl和pip问题&#xff0c;这一篇来解决sqlite问题 创建app时出现错误&#xff0c;模块_sqlite3找不到&#xff0c;查询sqlite相关的包&#xff1a; 在python2.6的lib-dynload路径下&#xff0c;有_sqlite3.so&#xff0c;这个应该就是Python需要的sqlite模块&a…

磺化 Cy5 溶菌酶,Sulfo-Cyanine5-Lysozyme,用于标记生物分子和细胞结构

您好&#xff0c;欢迎来到新研之家 文章关键词&#xff1a;磺化 Cy5 溶菌酶&#xff0c;Sulfo-Cyanine5-Lysozyme&#xff0c;Sulfo Cy5 Lysozyme 一、基本信息 产品简介&#xff1a;Sulfo Cyanine5 Lysozyme, also known as sulfonated Cy5 lysozyme, is a fluorescent mar…

ASP.NET Core WebAPI从HTTPS调整为HTTP启动

使用VS2022创建WebAPI项目时&#xff0c;默认勾选“配置HTTPS(H)”&#xff0c;这样启动WebAPI时以https方式启动。   如果要从HTTPS调整为HTTP启动&#xff0c;需要修改项目中以下几处&#xff0c;首先是Program.cs中删除app.UseHttpsRedirection()语句&#xff0c;删除后…

【Unity】粒子贴图异常白边问题

从PS制作的黑底&#xff0c;白光的贴图。放入Unity粒子中&#xff0c;拉远看会有很严重的白边&#xff0c;像马赛克一样。 材质使用&#xff1a;Mobile/Particles/Additive 经测试只使用一张黑色的图片&#xff0c;也会有白边。 解决方案&#xff1a; 关闭黑色底&#xf…

php基础学习之整型进制

不同进制的整型数据定义 在 PHP中提供了四种整型的定义方式&#xff1a;十进制定义&#xff0c;二进制定义&#xff0c;八进制定义和十六进制。 定义格式如下&#xff1a; 十进制是最基础的&#xff1a;$a 110;二进制需要在值前面加上0b&#xff1a;$a 0B1101110;&#xf…

arcgis 面要素shp数据处理

面要素是工作中用到最多的&#xff0c;那么面要素是如何形成的呢&#xff0c;主要还是由闭合的线要素转换而成。在面要素数据中常用的有以下几点&#xff1a; 一、 线转面&#xff08;要素转面&#xff09; 通过上一篇得到了点转线的要素&#xff0c;那么根据上节的线要素&am…

Sqlite真空命令VACUUM

之前在项目中使用了sqlite数据库&#xff0c;当日志变大时&#xff0c;执行CRUD操作就会变慢 后来尝试删除7天前的记录进行优化 delete from XX_CollectData where CreateTime<2024-01-24 发现sqlite文件的大小就没有变化&#xff0c;delete命令只是逻辑删除&#xff0c;…