我在 colab 上使用 RetinaNet Detectron2 训练了一个模型。培训成功,但我无法在图像上进行测试。
代码:
from detectron2.utils.visualizer import ColorMode
import glob
for imageName in glob.glob('/content/drive/My Drive/Detectron/test/*jpg'):
print(imageName)
im = cv2.imread(imageName)
outputs = predictor(im)
v = Visualizer(im[:, :, ::-1],
metadata=test_metadata,
scale=0.8,
instance_mode=ColorMode.IMAGE_BW
)
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
cv2_imshow(out.get_image()[:, :, ::-1])
错误:
/content/drive/My Drive/Detectron/test/wh_dresscode_4969_jpg.rf.5a2702518691d3d6f9cef7ad7977e5c8.jpg 数据类型:<class 'detectron2.structures.instances.Instances'> AttributeError Traceback(最近一次调用最后一次)
AttributeError:在给定的实例中找不到字段“pred_masks”!