读取Detectron“列表”对象中的json文件时出现问题,没有属性“ items”

问题描述

要重新训练检测器2(固有分段神经网络),需要

读取.json文件中的数据。这是通过下面显示功能完成的。在该示例中,似乎他们使用VIA v1.x创建数据库和json文件,我使用VIA 2.x,并且在“区域”注释中具有不同之处。读取两者的.json文件代码。我在V2.x中发现的是“区域”:[{而在1.x中的是“区域”:{“ 0”:{
这给了我错误: AttributeError:“列表”对象没有属性“项目” 在行上:对于_,annos.items()中的anno 如果我没有记错的话,它应该在区域内的所有元素中导航,我应该用什么来替换items()? down是该函数的源代码。我将原来使用的版本降级到1.x,但是我丢失了大部分注释。降级的效果很好,但是我将不得不再次制作一半的数据集。有什么建议吗? 谢谢

def get_balloon_dicts(img_dir):
json_file = os.path.join(img_dir,"via_region_data.json")
with open(json_file) as f:
    imgs_anns = json.load(f)

dataset_dicts = []
for idx,v in enumerate(imgs_anns.values()):
    record = {}
    
    filename = os.path.join(img_dir,v["filename"])
    height,width = cv2.imread(filename).shape[:2]
    
    record["file_name"] = filename
    record["image_id"] = idx
    record["height"] = height
    record["width"] = width
  
    annos = v["regions"]
   
    objs = []
    for _,anno in annos.items():
        anno = anno["shape_attributes"]
        px = anno["all_points_x"]
        py = anno["all_points_y"]
        poly = [(x + 0.5,y + 0.5) for x,y in zip(px,py)]
        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,"segmentation": [poly],"category_id": 0,}
        objs.append(obj)
    record["annotations"] = objs
    dataset_dicts.append(record)
return dataset_dicts
对于[[train],“ val”]中的d

: DatasetCatalog.register(“ balloon_” + d,lambda d = d:get_balloon_dicts(“ dattaset /” + d)) MetadataCatalog.get(“ balloon_” + d).set(thing_classes = [“ Hojas”]) Balloon_Metadata = MetadataCatalog.get(“ balloon_train”)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)