基于Ascend910+PyTorch1.11.0+CANN6.3.RC2的YoloV5训练推理一体化解决方案

昇腾Pytorch镜像:https://ascendhub.huawei.com/#/detail/ascend-pytorch

代码仓:git clone https://gitee.com/ascend/modelzoo-GPL.git

coco测试验证集:wget https://bj-aicc.obs.cn-north-309.mtgascendic.cn/dataset/coco2017/coco.zip

coco训练集(放images下):wget https://bj-aicc.obs.cn-north-309.mtgascendic.cn/dataset/coco2017/train2017.zip

部分代码

python 复制代码
# import StreamManagerApi.py
from StreamManagerApi import *

if __name__ == '__main__':
    # init stream manager
    streamManagerApi = StreamManagerApi()
    ret = streamManagerApi.InitManager()
    if ret != 0:
        print("Failed to init Stream manager, ret=%s" % str(ret))
        exit()

    # create streams by pipeline config file
    with open("data/pipeline/Sample.pipeline", 'rb') as f:
        pipelineStr = f.read()
    ret = streamManagerApi.CreateMultipleStreams(pipelineStr)
    if ret != 0:
        print("Failed to create Stream, ret=%s" % str(ret))
        exit()

    # Construct the input of the stream
    dataInput = MxDataInput()
    with open("data/test.jpg", 'rb') as f:
        dataInput.data = f.read()

    # The following is how to set the dataInput.roiBoxs
    """
    roiVector = RoiBoxVector()
    roi = RoiBox()
    roi.x0 = 100
    roi.y0 = 100
    roi.x1 = 200
    roi.y1 = 200
    roiVector.push_back(roi)
    dataInput.roiBoxs = roiVector
    """

    # Inputs data to a specified stream based on streamName.
    streamName = b'classification'
    inPluginId = 0
    uniqueId = streamManagerApi.SendDataWithUniqueId(streamName, inPluginId, dataInput)
    if uniqueId < 0:
        print("Failed to send data to stream.")
        exit()

    # Obtain the inference result by specifying streamName and uniqueId.
    inferResult = streamManagerApi.GetResultWithUniqueId(streamName, uniqueId, 3000)
    if inferResult.errorCode != 0:
        print("GetResultWithUniqueId error. errorCode=%d, errorMsg=%s" % (
            inferResult.errorCode, inferResult.data.decode()))
        exit()

    # print the infer result
    print(inferResult.data.decode())

    # destroy streams
    streamManagerApi.DestroyAllStreams()

本来想一次性写完的,奈何装CANN的驱动装了一个礼拜,各种内核版本不匹配,国产AI硬件任重道远...

相关推荐
红色的山茶花4 小时前
YOLOv7-0.1部分代码阅读笔记-general.py
笔记·yolo
源代码•宸5 小时前
完美解决 no model scale passed. assuming scale=‘n‘ 的YOLO问题
经验分享·yolo
lanboAI7 小时前
基于yolov5的番茄成熟度检测系统,支持图像、视频和摄像实时检测【pytorch框架、python源码】
python·yolo·智能手机
goomind8 小时前
YOLOv11实战宠物狗分类
人工智能·yolo·机器学习·计算机视觉·分类·聚类
aabbcccddd0110 小时前
yolov8目标检测如何设置背景/无标签图像参与训练
人工智能·yolo·目标检测·ultralytics
啊文师兄11 小时前
使用 Pytorch 搭建视频车流量检测资源(基于YOLO)
人工智能·pytorch·yolo
牙牙要健康1 天前
【目标检测】【Ultralytics-YOLO系列】Windows11下YOLOV5人脸目标检测
人工智能·yolo·目标检测
Python图像识别-11 天前
基于yolov8、yolov5的番茄成熟度检测识别系统(含UI界面、训练好的模型、Python代码、数据集)
python·yolo·ui
双木的木1 天前
集智书童 | YOLOv8架构的改进:POLO 模型在多类目标检测中的突破 !
人工智能·python·深度学习·yolo·目标检测·机器学习·计算机视觉
985小水博一枚呀1 天前
【深度学习目标检测|YOLO算法4-4】YOLO家族进化史:从YOLOv1到YOLOv11的架构创新、性能优化与行业应用全解析——工业领域
网络·人工智能·深度学习·算法·yolo·目标检测·架构