【问题标题】:detectron2.data.detection_utils.SizeMismatchError: Mismatched image shape for imagedetectron2.data.detection_utils.SizeMismatchError:图像的图像形状不匹配
【发布时间】:2022-08-07 09:58:13
【问题描述】:

实际上问题很明显,我的图像形状与所需的形状不一样。我所做的只是把我的图像放到detectron 已经准备好的函数中(你可以在下面看到函数)。我该如何解决?

这些功能正在为detectron2模型准备数据(用于训练)

def get_data_dicts(directory, classes):
    dataset_dicts = []
    for filename in [file for file in os.listdir(directory) if file.endswith(\'.json\')]:
        json_file = os.path.join(directory, filename)
        with open(json_file) as f:
            img_anns = json.load(f)

        record = {}
        
        filename = os.path.join(directory, img_anns[\"imagePath\"])
        
        record[\"file_name\"] = filename
        record[\"height\"] = 700
        record[\"width\"] = 700
      
        annos = img_anns[\"shapes\"]
        objs = []
        for anno in annos:
            px = [a[0] for a in anno[\'points\']] # x coord
            py = [a[1] for a in anno[\'points\']] # y-coord
            poly = [(x, y) for x, y in zip(px, py)] # poly for segmentation
            poly = [p for x in poly for p in x]

            obj = {
                \"bbox\": [np.min(px), np.min(py), np.max(px), np.max(py)],
                \"bbox_mode\": BoxMode.XYXY_ABS,
                \"category_id\": classes.index(anno[\'label\']),
                \"segmentation\": [poly],
                \"iscrowd\": 0
            }
            objs.append(obj)
        record[\"annotations\"] = objs
        dataset_dicts.append(record)
    return dataset_dicts

classes = [\'bos_el\', \'dolu_el\']
data_path = \'/home/berkay/Masaüstü/detectron_data/\'

for d in [\"test\", \"train\"]:
    DatasetCatalog.register(
        \"my_\" + d, 
        lambda d=d: get_data_dicts(data_path+d, classes)
    )
    MetadataCatalog.get(\"my_\" + d).set(thing_classes=classes)

    标签: image-processing computer-vision detectron


    【解决方案1】:

    将 700 高度和 700 宽度更改为您的图像尺寸

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-04
      • 2016-07-10
      • 2012-02-02
      • 2014-11-07
      • 1970-01-01
      • 2021-05-18
      • 1970-01-01
      相关资源
      最近更新 更多