我想训练一个模型来检测图像中的车辆和道路。为此,我将使用Mask R-CNN和YOLACT++。我使用vgg图像标注工具为Mask R-CNN标注了一些图像,分割点看起来如下图所示。
如您所见,这里没有面积参数或边界框参数。我可以用minx、miny、maxx、maxy找到我的实例的边界框,但不知道如何找到该分割区域的面积。您可以在下图中看到Yolact的标注格式。
标记所有实例需要大量时间。我在标记一张图像中所有汽车时至少花了10分钟,我已经标记了500张图像。您对我有何建议或有什么想法可以帮助我在将第一种标注格式转换为第二种格式(Mask R-CNN到COCO(Yolact))时节省时间吗?
回答:
类似这样,但这取决于您在vgg中如何标注
def vgg_to_coco(vgg_path: str, outfile: str=None, class_keyword: str = "Class"): with open(vgg_path) as f: vgg = json.load(f) images_ids_dict = {v["filename"]: i for i, v in enumerate(vgg.values())} # TDOD fix images_info = [{"file_name": k, "id": v, "width": 1024, "height": 1024} for k, v in images_ids_dict.items()] classes = {class_keyword} | {r["region_attributes"][class_keyword] for v in vgg.values() for r in v["regions"] if class_keyword in r["region_attributes"]} category_ids_dict = {c: i for i, c in enumerate(classes, 1)} categories = [{"supercategory": class_keyword, "id": v, "name": k} for k, v in category_ids_dict.items()] annotations = [] suffix_zeros = math.ceil(math.log10(len(vgg))) for i, v in enumerate(vgg.values()): for j, r in enumerate(v["regions"]): if class_keyword in r["region_attributes"]: x, y = r["shape_attributes"]["all_points_x"], r["shape_attributes"]["all_points_y"] annotations.append({ "segmentation": [list(chain.from_iterable(zip(x, y)))], "area": helper.polygon_area(x, y), "bbox": helper.bbox(x, y, out_format="width_height"), "image_id": images_ids_dict[v["filename"]], "category_id": category_ids_dict[r["region_attributes"][class_keyword]], "id": int(f"{i:0>{suffix_zeros}}{j:0>{suffix_zeros}}"), "iscrowd": 0 }) coco = { "images": images_info, "categories": categories, "annotations": annotations } if outfile is None: outfile = vgg_path.replace(".json", "_coco.json") with open(outfile, "w") as f: json.dump(coco, f)
您需要将1024更改为您的图像尺寸,或者如果您有变量图像尺寸,您需要为此创建一个映射。