AI 模型本地推理 - YYPOLOE - Python - Windows - GPU - 吸烟检测(目标检测)- 有配套资源直接上手实现
创始人
2024-12-28 01:06:50
0

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 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、打开软件...
第5分钟插件!微信小程序游戏辅... 第5分钟插件!微信小程序游戏辅助器,微乐小程序黑科技,积累教程(有挂app)-哔哩哔哩1、微信小程序...
透视存在!微乐小程序挂哪里,微... 透视存在!微乐小程序挂哪里,微乐小程序黑科技,窍门教程(有挂app)-哔哩哔哩运微乐小程序挂哪里辅助...
五分钟辅助!微信微乐辅助器免费... 五分钟辅助!微信微乐辅助器免费安装,微乐小程序黑科技,积累教程(有挂app)-哔哩哔哩1、游戏颠覆性...
透视安装!微乐自建房辅助多少钱... 透视安装!微乐自建房辅助多少钱一个月,微乐小程序免费黑科技,绝活教程(有挂插件)-哔哩哔哩1、许多玩...
9分钟脚本!微乐小程序辅助开挂... 9分钟脚本!微乐小程序辅助开挂,微乐小程序免费黑科技,项目教程(有挂下载)-哔哩哔哩1、操作简单,无...
透视苹果版!微信微乐游戏辅助脚... 透视苹果版!微信微乐游戏辅助脚本,微乐小程序黑科技,指引教程(有挂修改器)-哔哩哔哩微信微乐游戏辅助...
第4分钟辅助!微信微乐自建房脚... 第4分钟辅助!微信微乐自建房脚本免费下载,微乐小程序黑科技,攻略教程(有挂工具)-哔哩哔哩1、微信微...
透视插件!微乐小程序辅助工具,... 透视插件!微乐小程序辅助工具,微乐小程序免费黑科技,讲义教程(有挂安装)-哔哩哔哩;1、微乐小程序免...
第6分钟脚本!微乐小程序免费黑... 第6分钟脚本!微乐小程序免费黑科技是真的吗,微乐小程序黑科技,积累教程(有挂安装)-哔哩哔哩1、点击...