本文来源公众号“OpenCV学堂”,仅用于学术分享,侵权删,干货满满。
数据集地址
该图像数据集是 U2OS 细胞高通量化学筛选的一部分,其中包含 200 种生物活性化合物的示例。治疗效果最初是使用细胞绘画测定(荧光显微镜)成像的。该数据集仅包括每种化合物的单个视场的 DNA 通道。这些图像呈现了各种核表型,代表了高通量化学扰动。该数据集的主要用途是研究分割算法,该算法可以以准确的方式分离单个细胞核实例,而不管它们的形状和细胞密度如何。该集合有大约 23,000 个手动注释的单个细胞核,以建立用于分割评估的数据集合。
https://bbbc.broadinstitute.org/BBBC039
模型训练
准备好数据集以后,直接按下面的命令行运行即可:
yolo train model=yolov8s.pt data=bbbc022_dataset.yaml epochs=25 imgsz=640 batch=1
导出与测试
模型导出与测试
yolo export model=bbbc022_best.pt format=onnx
yolo predict model=bbbc022_best.pt source=D:\tensor_cv2.jpg
部署推理
转成ONNX格式文件以后,基于OpenVINO-Python部署推理,相关代码如下
ie = Core()
for device in ie.available_devices:
print(device)
# Read IR
model = ie.read_model(model="bbbc022_best.onnx")
compiled_model = ie.compile_model(model=model, device_name="CPU")
output_layer = compiled_model.output(0)
frame = cv.imread("D:/tensor_cv2.jpg")
bgr = format_yolov8(frame)
img_h, img_w, img_c = bgr.shape
start = time.time()
image = cv.dnn.blobFromImage(bgr, 1 / 255.0, (640, 640), swapRB=True, crop=False)
res = compiled_model([image])[output_layer] # 1x84x8400
rows = np.squeeze(res, 0).T
class_ids = []
confidences = []
boxes = []
x_factor = img_w / 640
y_factor = img_h / 640
for r in range(rows.shape[0]):
row = rows[r]
classes_scores = row[4:]
_, _, _, max_indx = cv.minMaxLoc(classes_scores)
class_id = max_indx[1]
if (classes_scores[class_id] > .25):
confidences.append(classes_scores[class_id])
class_ids.append(class_id)
x, y, w, h = row[0].item(), row[1].item(), row[2].item(), row[3].item()
left = int((x - 0.5 * w) * x_factor)
top = int((y - 0.5 * h) * y_factor)
width = int(w * x_factor)
height = int(h * y_factor)
box = np.array([left, top, width, height])
boxes.append(box)
indexes = cv.dnn.NMSBoxes(boxes, confidences, 0.25, 0.45)
for index in indexes:
box = boxes[index]
color = colors[int(class_ids[index]) % len(colors)]
rr = int((box[2] + box[3])/4)
cv.circle(frame, (box[0]+int(box[2]/2), box[1]+int(box[3]/2)), rr-4, color, 2)
cv.putText(frame, class_list[class_ids[index]], (box[0] + int(box[2] / 2), box[1] + int(box[3] / 2)),
cv.FONT_HERSHEY_SIMPLEX, .5, (0, 0, 0))
cv.putText(frame, "gloomyfish@2024", (20, 45), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
cv.imshow("YOLOv8+OpenVINO2023 BBBC Count", frame)
cv.waitKey(0)
cv.destroyAllWindows()
THE END !
文章结束,感谢阅读。您的点赞,收藏,评论是我继续更新的动力。大家有推荐的公众号可以评论区留言,共同学习,一起进步。
标签:box,int,class,YOLOv8,OpenCV,model,cv,荧光,row From: https://blog.csdn.net/csdn_xmj/article/details/143085520