【发布时间】:2022-01-08 04:20:24
【问题描述】:
动机
- 我有一个detectron2 Mask R-CNN 基线模型,它足以准确预测某些对象边界。
- 我想将这些预测边界转换为 COCO 多边形,以注释下一个数据集(监督标注)。
- 为此,我需要在没有注释的图像数据集上运行推理。
- detectron2 方法
register_coco_instances和load_coco_json需要带有注释的图像才能正确标记预测对象。
问题
代码
dataset_name = "test_data"
image_dir = "data/test"
coco_file = "data/test_annotations.json"
# Register dataset
# A COCO file is needed with image info, which I don't have
register_coco_instances(dataset_name , {}, coco_file, image_dir)
test_dict = load_coco_json(coco_file, image_dir, dataset_name=dataset_name )
metadata = MetadataCatalog.get(dataset_name)
# config details omitted for brevity
cfg = get_cfg()
predictor = DefaultPredictor(cfg)
# Make predictions for all images
for sample in test_dict:
image_filename = sample["file_name"]
img = cv2.imread(image_filename)
outputs = predictor(img)
# Display or save image with predictions to file
【问题讨论】:
标签: python image-segmentation detectron labelme