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

相关推荐
前网易架构师-高司机1 小时前
带标注的山体滑坡识别数据集,识别率95.4%,1848张图,支持yolo,coco json,voc xml格式,文末有模型训练代码
yolo·数据集·模型·滑坡·山体
极智视界1 小时前
无人机场景 - 目标检测数据集 - 空中救援目标检测数据集下载「包含VOC、COCO、YOLO三种格式」
yolo·目标检测·数据集·voc·coco·无人机场景·空中救援
爱思考的观赏鱼2 小时前
YOLO 系列:2026最新遥感检测:YOLOv11-OBB 旋转框训练、参数调优与踩坑全解析
人工智能·yolo·目标检测·机器学习·计算机视觉·目标跟踪
rabbit_pro3 小时前
Mac OS/M1 Pro 搭建Yolo V5环境
人工智能·yolo
羊羊小栈4 小时前
基于「YOLO目标检测 + 多模态AI分析」的增材制造粉末床熔合缺陷智能检测分析预警系统
人工智能·yolo·目标检测·计算机视觉·毕业设计·制造
QQ6765800817 小时前
基于yolo26算法的玉米卷叶心识别 智慧农业玉米病虫害农药丢撒识别 玉米卷心识别 玉米叶心图像识别 农作物识别第10410期
yolo·玉米卷叶心·玉米病虫害农药丢撒·玉米卷心识别·玉米叶心·农作物识别
xiaoyaohou1121 小时前
026、训练策略改进(二):余弦退火、热重启与早停策略
yolo
DeepLearningYolo1 天前
UNet架构训练输电线路、输电杆塔、水泥杆和输电线路木头杆塔的语义分割模型检测输电线路分割
pytorch·深度学习·yolo·目标检测
嵌入式吴彦祖1 天前
yolov5 C++环境搭建
yolo
mahtengdbb11 天前
CGFM上下文引导特征融合改进YOLOv26多尺度检测精度
yolo·数学建模