基于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硬件任重道远...

相关推荐
JANGHIGH10 分钟前
YOLO系列——Ubuntu20.04下通过conda虚拟环境安装Labelme
yolo·conda
山烛5 小时前
YOLO v1:目标检测领域的单阶段革命之作
人工智能·yolo·目标检测·计算机视觉·yolov1
山烛12 小时前
深入解析 YOLO v2
人工智能·yolo·计算机视觉·目标跟踪·yolov2
程序猿小D15 小时前
【完整源码+数据集+部署教程】遥感图像道路检测分割系统源码和数据集:改进yolo11-CARAFE
python·yolo·计算机视觉·目标跟踪·数据集·yolo11·遥感图像道路检测分割系统
zy_destiny15 小时前
【工业场景】用YOLOv8实现人员打电话识别
人工智能·python·深度学习·yolo·机器学习·计算机视觉·目标跟踪
B站计算机毕业设计之家1 天前
多模态项目:Python人脸表情系统 CNN算法 神经网络+Adaboost定位+PyQt5界面 源码+文档 深度学习实战✅
python·深度学习·神经网络·opencv·yolo·计算机视觉·情绪识别
dlraba8021 天前
YOLO 目标检测算法全解析:原理、分类与性能指标
算法·yolo·目标检测
荼蘼2 天前
【YOLO 模型入门】(1)一文读懂 YOLO:从核心概念到检测原理
yolo
小关会打代码2 天前
深度学习之YOLO系列了解基本知识
人工智能·深度学习·yolo
zy_destiny3 天前
【工业场景】用YOLOv8实现反光衣识别
人工智能·python·yolo·机器学习·计算机视觉