AI 模型本地推理 - YYPOLOE - Python - Windows - GPU - 吸烟检测(目标检测)- 有配套资源直接上手实现

Python 运行 - GPU 推理 - windows

环境准备

FastDeploy预编译库下载

conda config --add channels conda-forge && conda install cudatoolkit=11.2 cudnn=8.2
pip install fastdeploy_gpu_python-0.0.0-cp38-cp38-win_amd64.whl

python 代码



import fastdeploy as fd
import cv2
import os


model_path = "D:\\file\\ai\\models\\paddle\\ppyoloe\\infer_model"
image_path = "D:\\code\\fastdeploy\\pythonProject1\\image\\OIP1.jpg"
topk = 1
device = "gpu"
device_id = 1  # 仅当使用 GPU 时需要设置
backend = "paddle"

# 配置runtime,加载模型
# option = build_option(model_path, device, device_id, backend)
option = fd.RuntimeOption()

model_file = os.path.join(model_path, "inference.pdmodel")
params_file = os.path.join(model_path, "inference.pdiparams")
config_file = os.path.join(model_path, "inference.yml")
# 加载模型
model = fd.vision.detection.PaddleDetectionModel(
    model_file, params_file, config_file, runtime_option=option)
dump_result = dict()
im = cv2.imread(image_path)
# 推理
result = model.predict(im)
print(result)
# 预测结果可视化
vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5)
cv2.imwrite("visualized_result.jpg", vis_im)
print("Visualized result save in ./visualized_result.jpg")

model_path 包含以下内容,模型在文章关联资源处。
在这里插入图片描述

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-19 12:22:01       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-19 12:22:01       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-19 12:22:01       58 阅读
  4. Python语言-面向对象

    2024-07-19 12:22:01       69 阅读

热门阅读

  1. 防火墙(firewall)详细介绍

    2024-07-19 12:22:01       17 阅读
  2. YOLOv7简介

    2024-07-19 12:22:01       23 阅读
  3. Zabbix的安装部署及使用流程

    2024-07-19 12:22:01       22 阅读
  4. 【golang-makefile】最全的go语言makefile文件

    2024-07-19 12:22:01       16 阅读
  5. 【MySQL】数据库LOCK锁类型

    2024-07-19 12:22:01       20 阅读
  6. 【Qt+opencv】基础的图像绘制

    2024-07-19 12:22:01       20 阅读
  7. git删除本地远程分支

    2024-07-19 12:22:01       16 阅读
  8. 面向开发者的提示词工程第五章-推断

    2024-07-19 12:22:01       20 阅读
  9. C# 4.List

    2024-07-19 12:22:01       18 阅读