×
分享到微信

打开微信,使用扫一扫进入页面后,点击右上角菜单,

点击“发送给朋友”或“分享到朋友圈”完成分享

执行 python detect.py 测试yolov5s_int8.pt 结果不画框,没有输出 已解决 bonjour2022-07-22 10:18:46 回复 9 查看 使用求助
执行 python detect.py 测试yolov5s_int8.pt 结果不画框,没有输出
分享到:

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('--cfg', type=str, default='yolov5s.yaml',help='model.yaml')
    parser.add_argument('--device', default='cpu',help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
    parser.add_argument('--jit',type=bool,help='fusion',default=False)
    parser.add_argument('--save',type=bool,default=False,help='selection of save *.cambrcion')
    opt = parser.parse_args()
    # 获取yolov5网络文件
    net = yolo.get_empty_model(opt)
    quantized_net = torch_mlu.core.mlu_quantize.quantize_dynamic_mlu(net)
    state_dict = torch.load('yolov5s_int8.pt')
    quantized_net.load_state_dict(state_dict, strict=False)
    # 设置为推理模式
    quantized_net = quantized_net.eval().float()
    print("i am here i am here i am here")
   # device = ct.mlu_device()
    ct.set_device(-1)
    
    quantized_net.to(ct.set_device(-1))
    print("how are you how are are you how are you")
    # 读取图片
    img_mat = cv2.imread('images/image.jpg')
    # 预处理
    img = letter_box(img_mat)
    print(img.shape)
    # 设置在线融合模式
    if opt.jit:
        if opt.save:
            ct.save_as_cambricon('yolov5s')
        torch.set_grad_enabled(False)
        ct.set_core_number(4)
        trace_input = torch.randn(1, 3, 640, 640, dtype=torch.float)
        trace_input = trace_input.to(ct.set_device(-1))
        quantized_net = torch.jit.trace(quantized_net, trace_input, check_trace = False)
    # 推理
    detect_out = quantized_net(img.to(ct.set_device(-1)))

    if opt.jit:
        if opt.save:
            ct.save_as_cambricon('')
    # 后处理
    #anchors = [10, 13, 16, 30, 33, 23,30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326]
    detect_out=detect_out.to(torch.device('cpu'))
    print(detect_out.shape)
    #print('==============================')
    #det = detect_out.clone()
    #det = det.numpy().tolist()
    #print(det)
    #print('==============================')
    # 画框,标出类别和置信度并保存图片
    box_result = get_boxes(detect_out)
    print(box_result)
    draw_boxes(box_result)

我把所有的ct.mlu_device()    改为   ct.set_device(-1)


执行  python detect.py    报错

(pytorch) root@liulei:/opt/cambricon/models/Pytorch_Yolov5_Inference/quantize_online# python detect.py
CNML: 7.9.114 06a1920
CNRT: 4.7.12 03ea1d9
2022-07-21 19:41:29.936052: [cnrtWarning] [3462] [Card : NONE] Failed to initialize CNDEV. Host manage interface disabled
2022-07-21 19:41:29.938028: [cnrtError] [3462] [Card : NONE] No MLU can be found !
2022-07-21 19:41:29.938036: [cnmlError] No MLU device
2022-07-21 19:41:29.938164: [cnmlError] No MLU device
Using CPU


                 from  n    params  module                                  arguments                     
  0                -1  1      3520  common.Focus                            [3, 32, 3]                    
  1                -1  1     18560  common.Conv                             [32, 64, 3, 2]                
  2                -1  1     19904  common.BottleneckCSP                    [64, 64, 1]                   
  3                -1  1     73984  common.Conv                             [64, 128, 3, 2]               
  4                -1  1    161152  common.BottleneckCSP                    [128, 128, 3]                 
  5                -1  1    295424  common.Conv                             [128, 256, 3, 2]              
  6                -1  1    641792  common.BottleneckCSP                    [256, 256, 3]                 
  7                -1  1   1180672  common.Conv                             [256, 512, 3, 2]              
  8                -1  1    656896  common.SPP                              [512, 512, [5, 9, 13]]        
  9                -1  1   1248768  common.BottleneckCSP                    [512, 512, 1, False]          
 10                -1  1    131584  common.Conv                             [512, 256, 1, 1]              
 11                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 12           [-1, 6]  1         0  common.Concat                           [1]                           
 13                -1  1    378624  common.BottleneckCSP                    [512, 256, 1, False]          
 14                -1  1     33024  common.Conv                             [256, 128, 1, 1]              
 15                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 16           [-1, 4]  1         0  common.Concat                           [1]                           
 17                -1  1     95104  common.BottleneckCSP                    [256, 128, 1, False]          
 18                -1  1    147712  common.Conv                             [128, 128, 3, 2]              
 19          [-1, 14]  1         0  common.Concat                           [1]                           
 20                -1  1    313088  common.BottleneckCSP                    [256, 256, 1, False]          
 21                -1  1    590336  common.Conv                             [256, 256, 3, 2]              
 22          [-1, 10]  1         0  common.Concat                           [1]                           
 23                -1  1   1248768  common.BottleneckCSP                    [512, 512, 1, False]          
 24      [17, 20, 23]  1    229245  yolo.Detect                             [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]]
Model Summary: 191 s, 7.46816e+06 parameters, 7.46816e+06 gradients

i am here i am here i am here
2022-07-21 19:41:31.139407: [cnrtError] [3462] [Card : NONE] input param  is invalid device handle in cnrtSetCurrentDevice
2022-07-21 19:41:31.139427: [cnrtError] [3462] [Card : NONE] input param  is invalid device handle in cnrtSetCurrentDevice
how are you how are are you how are you
torch.Size([1, 3, 640, 640])
2022-07-21 19:41:31.150708: [cnrtError] [3462] [Card : NONE] input param  is invalid device handle in cnrtSetCurrentDevice
torch.Size([1, 25200, 85])
num_boxes_final:  5.57780647277832
[tensor([[0.00017, 0.00011, 0.00025, 0.00028, 0.00012, 0.00184],
        [0.04477, 0.00651, 0.06613, 0.01171, 0.00214, 0.00200]])]
640x640 1 persons, 1 persons,
label person 0.00
label person 0.00




输出的图像并没有画框

版权所有 © 2022 寒武纪 Cambricon.com 备案/许可证号:京ICP备17003415号-1
关闭