钢筋计数模型训练教学与实践 模型文件所在目录 lowestloss 9999 bestmodelname '' for modelname in trainedmodels: if not modelname.endswith('pth'): continue loss float(modelname.split('loss')[1].split('.pth')[0]) if loss 0: for i in range(classcollection.shape[0]): if classcollection[i, 1] > 0.6: pt classcollection[i] cv2.circle(imagedraw, (int((pt[0] + pt[2]) 0.5), int((pt[1] + pt[3]) 0.5)), int((pt[2] pt[0]) 0.5 0.6), (255, 0, 0), 1) rebarcount + 1 cv2.putText(imagedraw, 'rebarcount: %d' % rebarcount, (25, 50), cv2.FONTHERSHEYSIMPLEX, 2, (0, 255, 0), 3) plt.figure(i, figsize(30, 20)) plt.imshow(imagedraw) plt.show() 输出: 从推理结果可以看到,模型能较为精准的对钢筋进行计数。