outputs = session.run(outname, inp)[0] print('inference time :%.4f' % (time.time() - t1))

print(outputs)

ori_images = [img.copy()] areas = [] for i, (batch_id, x0, y0, x1, y1, cls_id, score) in enumerate(outputs): image = ori_images[int(batch_id)] box = np.array([x0, y0, x1, y1]) box -= np.array(dwdh * 2) box /= ratio box = box.round().astype(np.int32).tolist() cls_id = int(cls_id) score = round(float(score), 3) name = names[cls_id] color = colors[name] name += ' ' + str(score) # print(color) # print(box) areas.append([box[0], box[1], box[2] - box[0], box[3] - box[1], None]) # cv2.rectangle(image, tuple(box[:2]), tuple(box[2:]), color, 2) # cv2.putText(image, name, (box[0], box[1] - 2), cv2.FONT_HERSHEY_SIMPLEX, 0.75, [225, 255, 255], thickness=2) # t = int(time.time()) # cv2.imwrite(image, "process_img/%d.jpg"%t) # cv2.imwrite(img2, "process_img/%d_origin.jpg"%t)

return areas, gray

cv2.rectangle(image, tuple(box[:2]), tuple(box[2:]), color, 2) cv2.putText(image,name,(box[0], box[1] - 2),cv2.FONT_HERSHEY_SIMPLEX,0.75,[225, 255, 255],thickness=2)

cv2.imwrite('onnx.jpg', ori_images[0])

Object Detection with ONNX Model: Inference and Visualization

原文地址: https://www.cveoy.top/t/topic/p771 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录