切换版块
×
基础软件平台
PyTorch开发
TensorFlow开发
编解码及SDK开发
BANG语言与计算库
开发工具链
MagicMind开发
软件栈百科
云平台集成
硬件产品专区
MLU370系列AI加速卡
MLU270系列AI加速卡
MLU220系列AI加速产品
经验方案交流区
经验案例与实践分享
开发者服务
开发者活动
公告与版务
高校支持
《智能计算系统》
签到
版块
社区
文档
SDK下载
370系列
200系列
开发平台
官网首页
注册
登录
全部版块
基础软件平台
硬件产品专区
经验方案交流区
开发者服务
高校支持
发布新帖
登录/注册
LV.1
yinyin123456
98
积分
0
赞
11
帖子
61
回复
0
收藏
TA的动态
TA的帖子
TA的回复
yolov5离线模型在mlu220芯片盒子上推理结果不正确
我的回复:已解决
0
mlu270上生成的离线模型不能在mlu220芯片盒子上运行?是否需要设置生成离线模型参数
我的回复:2022-04-19 19:48:16.230890: [cnrtWarning] [10274] [Card : 0] The device you run is MLU270, but the platform in kernel is MLU220!2022-04-19 19:48:16.440299: [cnrtWarning] [10274] [Card : 0] The device you run is not the same as the platform in kernel!2022-04-19 19:48:16.440319: [cnrtWarning] [10274] [Card : 0] The device you run is MLU270, but the platform in kernel is MLU220!2022-04-19 19:48:21.031934: [cnrtWarning] [10274] [Card : 0] The device you run is not the same as the platform in kernel!2022-04-19 19:48:21.031966: [cnrtWarning] [10274] [Card : 0] The device you run is MLU270, but the platform in kernel is MLU220!2022-04-19 19:48:21.177680: [cnrtWarning] [10274] [Card : 0] The device you run is not the same as the platform in kernel!2022-04-19 19:48:21.177705: [cnrtWarning] [10274] [Card : 0] The device you run is MLU270, but the platform in kernel is MLU220!2022-04-19 19:48:21.194644: [cnrtWarning] [10274] [Card : 0] The device you run is not the same as the platform in kernel!2022-04-19 19:48:21.194664: [cnrtWarning] [10274] [Card : 0] The device you run is MLU270, but the platform in kernel is MLU220!2022-04-19 19:48:21.559884: [cnrtWarning] [10274] [Card : 0] The device you run is not the same as the platform in kernel!2022-04-19 19:48:21.559912: [cnrtWarning] [10274] [Card : 0] The device you run is MLU270, but the platform in kernel is MLU220!
0
mlu270上生成的离线模型不能在mlu220芯片盒子上运行?是否需要设置生成离线模型参数
我的回复:#2yinyin123456回复设置 ct.set_core_version("MLU220")报错:[图片]2022-04-19 19:48:16.230890: [cnrtWarning] [10274] [Card : 0] The device you run is MLU270, but the platform in kernel is MLU220!2022-04-19 19:48:16.440299: [cnrtWarning] [10274] [Card : 0] The device you run is not the same as the platform in kernel!2022-04-19 19:48:16.440319: [cnrtWarning] [10274] [Card : 0] The device you run is MLU270, but the platform in kernel is MLU220!2022-04-19 19:48:21.031934: [cnrtWarning] [10274] [Card : 0] The device you run is not the same as the platform in kernel!2022-04-19 19:48:21.031966: [cnrtWarning] [10274] [Card : 0] The device you run is MLU270, but the platform in kernel is MLU220!2022-04-19 19:48:21.177680: [cnrtWarning] [10274] [Card : 0] The device you run is not the same as the platform in kernel!2022-04-19 19:48:21.177705: [cnrtWarning] [10274] [Card : 0] The device you run is MLU270, but the platform in kernel is MLU220!2022-04-19 19:48:21.194644: [cnrtWarning] [10274] [Card : 0] The device you run is not the same as the platform in kernel!2022-04-19 19:48:21.194664: [cnrtWarning] [10274] [Card : 0] The device you run is MLU270, but the platform in kernel is MLU220!2022-04-19 19:48:21.559884: [cnrtWarning] [10274] [Card : 0] The device you run is not the same as the platform in kernel!2022-04-19 19:48:21.559912: [cnrtWarning] [10274] [Card : 0] The device you run is MLU270, but the platform in kernel is MLU220!
0
mlu270上生成的离线模型不能在mlu220芯片盒子上运行?是否需要设置生成离线模型参数
我的回复:设置 ct.set_core_version("MLU220")报错:
0
mlu270上生成的离线模型不能在mlu220芯片盒子上运行?是否需要设置生成离线模型参数
我的回复:设置core版本也不行
0
生成离线模型报错
我的回复:已解决上述问题,但270上生成的离线模型 在mlu220芯片盒子上推理失败:CNRT: 4.7.12 03ea1d92022-04-19 17:31:13.735909: [cnrtWarning] [22803] [Card : 0] The device you run is not the same as the platform in kernel!2022-04-19 17:31:13.736012: [cnrtWarning] [22803] [Card : 0] The device you run is MLU220, but the platform in kernel is MLU270!2022-04-19 17:31:13.736065: [cnrtError] [22803] [Card : 0] Model is compiled for MLU270, now device is MLU2202022-04-19 17:31:13.736116: [cnrtError] [22803] [Card : 0] [../src/al CNRT error, code=632020(Unsupported operation.) "cnrtInitRuntimeContext(ctx, NULL)"2022-04-19 17:31:13.736172: [cnrtError] [22803] [Card : 0] Runtime context is not initialized yet.2022-04-19 17:31:13.736220: [cnrtError] [22803] [Card : 0] [../src/algorithem_test.cpp:299] CNRT error, code=632024(Uninitialized.) "cnrtRuntimeContextCreateQueue(ctx, &queue)"input shape:1 640 480 3output shape:1 1 1 7232ccccc:9602022-04-19 17:31:13.877099: [cnrtError] [22803] [Card : 0] Runtime context is not initialized yet.2022-04-19 17:31:13.877214: [cnrtError] [22803] [Card : 0] [../src/algorithem_test.cpp:449] CNRT error, code=632024(Uninitialized.) "cnrtRuntimeContextCreateNotifier(ctx, ¬ifi2022-04-19 17:31:13.877275: [cnrtError] [22803] [Card : 0] Runtime context is not initialized yet.2022-04-19 17:31:13.877323: [cnrtError] [22803] [Card : 0] [../src/algorithem_test.cpp:450] CNRT error, code=632024(Uninitialized.) "cnrtRuntimeContextCreateNotifier(ctx, ¬ifi2022-04-19 17:31:13.877386: [cnrtError] [22803] [Card : 0] [../src/algorithem_test.cpp:451] CNRT error, code=632034(Failure on notifier operation.) "cnrtPlaceNotifier(notifier_st2022-04-19 17:31:13.877445: [cnrtError] [22803] [Card : 0] Runtime context is not initialized yet.2022-04-19 17:31:13.877492: [cnrtError] [22803] [Card : 0] [../src/algorithem_test.cpp:458] CNRT error, code=632024(Uninitialized.) "cnrtInvokeRuntimeContext_V2(ctx, nullptr, parm)"2022-04-19 17:31:13.877561: [cnrtError] [22803] [Card : 0] [../src/algorithem_test.cpp:459] CNRT error, code=632034(Failure on notifier operation.) "cnrtPlaceNotifier(notifier_en2022-04-19 17:31:13.877635: [cnrtError] [22803] [Card : 0] MLU unfinished. cnrtStream fail.2022-04-19 17:31:13.877682: [cnrtError] [22803] [Card : 0] the mlu device is unknown or doesn't exist.
0
生成离线模型报错
我的回复:代码:from pathlib import Pathimport cv2import torchimport torch.backends.cudnn as cudnnfrom numpy import randomimport argparseimport timefrom models.experimental import attempt_loadfrom utils.datasets import LoadStreams, LoadImagesfrom utils.general import check_img_size, non_max_suppression, apply_classifier, scale_coords, xyxy2xywh, \\ strip_optimizer, set_logging, increment_pathfrom utils.plots import plot_one_boxfrom utils.torch_utils import select_device, load_classifier, time_synchronizedimport osimport torch_mluimport torch_mlu.core.mlu_quantize as mlu_quantizeimport torch_mlu.core.mlu_model as ctimport numpy as npbatchsize = 1corenum = 1def get_boxes(prediction, batch_size=1, img_size=640): reshape_value = torch.reshape(prediction, (-1, 1)) num_boxes_final = reshape_value[0].item() print('num_boxes_final: ',num_boxes_final) all_list = [[] for _ in range(batch_size)] for i in range(int(num_boxes_final)): batch_idx = int(reshape_value[64 + i * 7 + 0].item()) if batch_idx >= 0 and batch_idx < batch_size: bl = reshape_value[64 + i * 7 + 3].item() br = reshape_value[64 + i * 7 + 4].item() bt = reshape_value[64 + i * 7 + 5].item() bb = reshape_value[64 + i * 7 + 6].item() if bt - bl > 0 and bb -br > 0: all_list[batch_idx].append(bl) all_list[batch_idx].append(br) all_list[batch_idx].append(bt) all_list[batch_idx].append(bb) all_list[batch_idx].append(reshape_value[64 + i * 7 + 2].item()) # all_list[batch_idx].append(reshape_value[64 + i * 7 + 2].item()) all_list[batch_idx].append(reshape_value[64 + i * 7 + 1].item()) output = [np.array(all_list[i]).reshape(-1, 6) for i in range(batch_size)] # outputs = [torch.FloatTensor(all_list[i]).reshape(-1, 6) for i in range(batch_size)] return outputdef detect(save_img=False): source, weights, view_img, save_txt, imgsz = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size webcam = source.isnumeric() or source.endswith('.txt') or source.lower().startswith( ('rtsp://', 'rtmp://', 'http://')) # Directories save_dir = Path(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok)) # increment run (save_dir / 'labels' if save_txt else save_dir).mkdir(parents=True, exist_ok=True) # make dir # Initialize #set_logging() device = select_device(opt.device) half = device.type !='cpu' # half precision only supported on CUDA # Load model model = attempt_load(weights, map_location=device) # load FP32 model # torch.save(model.state_dict(), "v4_head_uzip.pt", _use_new_zipfile_serialization=False) imgsz = check_img_size(imgsz, s=model.stride.max()) # check img_size if half: model.half() # to FP16 # Second-stage classifier classify = False if classify: modelc = load_classifier(name='resnet101', n=2) # initialize modelc.load_state_dict(torch.load('weights/resnet101.pt', map_location=device)['model']).to(device).eval() # Set Dataloader #vid_path, vid_writer = None, None #if webcam: # view_img = True # cudnn.benchmark = True # set True to speed up constant image size inference # dataset = LoadStreams(source, img_size=imgsz) #else: # save_img = True dataset = LoadImages(source, img_size=imgsz) # Get names and colors names = model.module.names if hasattr(model, 'module') else model.names colors = [[random.randint(0, 255) for _ in range(3)] for _ in names] # Run inference global quantized_model global quantized_net if opt.cfg == 'qua': qconfig = {'iteration':2,'firstconv':False} quantized_model = mlu_quantize.quantize_dynamic_mlu(model, qconfig, dtype='int8', gen_quant=True) elif opt.cfg =='mlu': from models.yolo import Model model = Model("models/yolov5s.yaml").to(torch.device("cpu")) model.float().fuse().eval() quantized_net = torch_mlu.core.mlu_quantize.quantize_dynamic_mlu(model) state_dict = torch.load("yolov5sv4_head_int8_20220419.pt") quantized_net.load_state_dict(state_dict, strict=False) quantized_net.eval() quantized_net.to(ct.mlu_device()) print("load success!", ct.mlu_device()) if opt.jit: ct.save_as_combraicon("yolov5_v4_head") 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.mlu_device()) quantized_net = torch.jit.trace(quantized_net, trace_input, check_trace = False) t0 = time.time() img = torch.zeros((1, 3, imgsz, imgsz), device=device) #init img _ = model(img.half() if half else img) if device.type != 'cpu' else None # run once for path, img, im0s, vid_cap in dataset: img = torch.from_numpy(img).to(device) img = img.half() if half else img.float() # uint8 to fp16/32 img /= 255.0 # 0 - 255 to 0.0 - 1.0 if img.ndimension() == 3: img = img.unsqueeze(0) # Inference t1 = time_synchronized() if opt.cfg == 'cpu': pred = model(img, augment=opt.augment)[0] print('run cpu') elif opt.cfg == 'qua': pred = quantized_model(img)[0] torch.save(quantized_model.state_dict(), 'yolov5sv4_head_int8_20220419.pt') print('run qua') print(pred) elif opt.cfg == 'mlu': img = img.type(torch.HalfTensor).to(ct.mlu_device()) img = img.to(ct.mlu_device()) pred = quantized_net(img)[0] pred = pred.data.cpu().type(torch.FloatTensor) print("pred_shape", pred.shape) box_result = get_boxes(pred) print("im0s.shape:", im0s.shape) print(box_result) res = box_result[0].tolist() with open("yolov5s_mlu_output.txt", "w+") as f: for pt in sorted(res, key=lambda x: (x[0], x[1])): f.write("{}\\n{}\\n{}\\n{}\\n".format(pt[0], pt[1], pt[2], pt[3])) cv2.rectangle(im0s, (int(pt[0]), int(pt[1])), (int(pt[2]), int(pt[3])), (255, 0, 0), 2) cv2.imwrite("mlu_out_{}.jpg".format(os.path.basename(path).split('.')[0]), im0s) print('run mlu')if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--weights', nargs='+', type=str, help='model.pt path(s)') parser.add_argument('--source', type=str, default="data/images/bus.jpg", help='source') # file/folder, 0 for webcam parser.add_argument('--cfg', default='cpu', help='qua and off') parser.add_argument('--jit', type=bool) parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)') parser.add_argument('--conf-thres', type=float, default=0.5, help='object confidence threshold') parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS') parser.add_argument('--device', default='cpu', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') parser.add_argument('--view-img', action='store_true',default=True, help='display results') parser.add_argument('--save-txt', action='store_true', help='save results to *.txt') parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels') parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3') parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS') parser.add_argument('--augment', action='store_true', help='augmented inference') parser.add_argument('--update', action='store_true', help='update all models') parser.add_argument('--project', default='runs/detect', help='save results to project/name') parser.add_argument('--name', default='exp', help='save results to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') opt = parser.parse_args() print(opt) with torch.no_grad(): if opt.update: # update all models (to fix SourceChangeWarning) for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']: detect() strip_optimizer(opt.weights) else: detect()
0
yolov5离线模型移植
我的回复:#1jiapeiyuan回复你好,可以把 非80类的 整个工程(包括代码、模型和图片)发给我们吗,我们本地复现一下也遇到此问题,训练的yolov5-3.0模型 只检测一类 在mlu220芯片边缘盒子上测试出现检测无结果
0
mlu220边缘计算盒离线推理yolov5报错
我的回复:#1jiapeiyuan回复运行bin文件之前,执行export LD_LIBRARY_PATH=libcnrt.so所在目录root@localhost:/opt/yolov5_offline_simple_demo# ./build/yolov5_offline_simple_demo model/yolov5s-220.cambricon subnet0 0 0 data/000000315719.jpg 2 data/label_map_coco.txtCNRT: 4.7.12 03ea1d9input shape:1 640 640 3output shape:1 1 1 7232HardwareTime:46.116000(ms) E2ETime:55.762000(ms)boxnum:9=========================504.777 172.691 590.322 380.455 0.772659 0345.08 120.341 505.737 428.227 0.723597 09.69883 210.268 28.9566 244.928 0.559216 0184.052 259.124 605.077 528.237 0.842521 17.43911 214.137 137.276 291.024 0.920868 2165.675 213.27 419.95 412.953 0.813765 2117.277 220.207 156.041 271.607 0.766291 2140.894 217.468 188.346 272.17 0.765653 2174.697 218.276 216.731 264.947 0.636769 2不知道 从图像输入到结果输出 包括后处理的时间(坐标画框)的时间
0
mlu220边缘计算盒离线推理yolov5报错
我的回复:#7yinyin123456回复谢谢!可以了 但运行可执行文件报错 opencv问题root@localhost:/opt/yolov5_offline_simple_demo# ./build/yolov5_offline_simple_demo model/yolov5s-220.cambricon subnet0 0 0 data/000000000872.jpg 2 data/label_map_coco.txtCNRT: 4.7.12 03ea1d9input shape:1 640 640 3output shape:1 1 1 7232OpenCV Error: Assertion failed (ssize.area() > 0) in resize, file /home/cambricon/sunsh/file_bak/opencv/opencv/modules/imgproc/src/imgwarp.cpp, line 1968terminate called after throwing an instance of 'cv::Exception' what(): /home/cambricon/sunsh/file_bak/opencv/opencv/modules/imgproc/src/imgwarp.cpp:1968: error: (-215) ssize.area() > 0 in function resize展开发现图像路径问题 解决了 谢谢哈
0
上一页
1
2
3
下一页
Github
开发平台
文档中心
新手必读
官方微信
版权所有 © 2024 寒武纪 Cambricon.com 备案/许可证号:
京ICP备17003415号-1
关闭