您的位置:首页 > 健康 > 养生 > AI 模型本地推理 - YYPOLOE - Python - Windows - GPU - 吸烟检测(目标检测)- 有配套资源直接上手实现

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

2024/10/7 2:20:20 来源:https://blog.csdn.net/m0_48812875/article/details/140498276  浏览:    关键词:AI 模型本地推理 - YYPOLOE - Python - Windows - GPU - 吸烟检测(目标检测)- 有配套资源直接上手实现

Python 运行 - GPU 推理 - windows

  • 环境准备
  • python 代码

环境准备

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 osmodel_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 包含以下内容,模型在文章关联资源处。
在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com