当我使用 YOLACT 运行 train.py 时,我收到错误 KeyError: 0
Posted
技术标签:
【中文标题】当我使用 YOLACT 运行 train.py 时,我收到错误 KeyError: 0【英文标题】:When I run train.py with YOLACT, I get the error KeyError: 0 【发布时间】:2021-02-01 19:11:49 【问题描述】:我是机器学习和编程的新手。 现在我正在尝试使用我自己的数据开发 YOLACT AI。 但是,当我运行 train.py 时,出现以下错误并且无法学习。 我该怎么做才能克服这个错误?`
(yolact) tmori@tmori-Lenovo-Legion-Y740-15IRHg:~/yolact$ python train.py --config=can_config --save_interval=2000
将注释加载到内存中...
完成(t=0.00s)
创建索引...
索引创建!
将注释加载到内存中...
完成(t=0.00s)
创建索引...
索引创建!
正在初始化权重...
开始训练!
/home/tmori/yolact/utils/augmentations.py:309:VisibleDeprecationWarning:从不规则的嵌套序列(它是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建一个 ndarray 已弃用.如果您打算这样做,则必须在创建 ndarray 时指定 'dtype=object'
模式 = random.choice(self.sample_options)
/home/tmori/yolact/utils/augmentations.py:309:VisibleDeprecationWarning:从不规则的嵌套序列(它是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建一个 ndarray 已弃用.如果您打算这样做,则必须在创建 ndarray 时指定 'dtype=object'
模式 = random.choice(self.sample_options)
/home/tmori/yolact/utils/augmentations.py:309:VisibleDeprecationWarning:从不规则的嵌套序列(它是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建一个 ndarray 已弃用.如果您打算这样做,则必须在创建 ndarray 时指定 'dtype=object'
模式 = random.choice(self.sample_options)
/home/tmori/yolact/utils/augmentations.py:309:VisibleDeprecationWarning:从不规则的嵌套序列(它是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建一个 ndarray 已弃用.如果您打算这样做,则必须在创建 ndarray 时指定 'dtype=object'
模式 = random.choice(self.sample_options)
[0]0||乙:4.840 | C: 16.249 |男:4.682 | S: 2.749 |电话:28.521 ||预计到达时间:9:18:44 ||计时器:3.352
/home/tmori/yolact/utils/augmentations.py:309:VisibleDeprecationWarning:从不规则的嵌套序列(它是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建一个 ndarray 已弃用.如果您打算这样做,则必须在创建 ndarray 时指定 'dtype=object'
模式 = random.choice(self.sample_options)
/home/tmori/yolact/utils/augmentations.py:309:VisibleDeprecationWarning:从不规则的嵌套序列(它是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建一个 ndarray 已弃用.如果您打算这样做,则必须在创建 ndarray 时指定 'dtype=object'
模式 = random.choice(self.sample_options)
/home/tmori/yolact/utils/augmentations.py:309:VisibleDeprecationWarning:从不规则的嵌套序列(它是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建一个 ndarray 已弃用.如果您打算这样做,则必须在创建 ndarray 时指定 'dtype=object'
模式 = random.choice(self.sample_options)
/home/tmori/yolact/utils/augmentations.py:309:VisibleDeprecationWarning:从不规则的嵌套序列(它是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建一个 ndarray 已弃用.如果您打算这样做,则必须在创建 ndarray 时指定 'dtype=object'
模式 = random.choice(self.sample_options)
[1] 10 ||乙:4.535 | C: 9.228 |男:4.379 |小号:1.867 |电话:20.008 ||预计到达时间:3:25:24 ||计时器:0.864
/home/tmori/yolact/utils/augmentations.py:309:VisibleDeprecationWarning:从不规则的嵌套序列(它是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建一个 ndarray 已弃用.如果您打算这样做,则必须在创建 ndarray 时指定 'dtype=object'
模式 = random.choice(self.sample_options)
/home/tmori/yolact/utils/augmentations.py:309:VisibleDeprecationWarning:从不规则的嵌套序列(它是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建一个 ndarray 已弃用.如果您打算这样做,则必须在创建 ndarray 时指定 'dtype=object'
模式 = random.choice(self.sample_options)
/home/tmori/yolact/utils/augmentations.py:309:VisibleDeprecationWarning:从不规则的嵌套序列(它是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建一个 ndarray 已弃用.如果您打算这样做,则必须在创建 ndarray 时指定 'dtype=object'
模式 = random.choice(self.sample_options)
/home/tmori/yolact/utils/augmentations.py:309:VisibleDeprecationWarning:从不规则的嵌套序列(它是具有不同长度或形状的列表或元组或 ndarray 的列表或元组)创建一个 ndarray 已弃用.如果您打算这样做,则必须在创建 ndarray 时指定 'dtype=object'
模式 = random.choice(self.sample_options)
计算验证 mAP(这可能需要一段时间)...
回溯(最近一次通话最后):
我正在尝试开发一种能够找到罐头并对其进行分割的 AI。 首先我用labelme只注释了“can”的一项,然后用labelme2coco.py创建了一个COCO格式的json文件。 之后,我根据 YOLACT 的 GitHub 上的“Custom Datasets”修改了 config.py 并运行了 train.py。
我的开发环境如下。 操作系统:Ubuntu20.04LTS 蟒蛇:4.8.3 蟒蛇:3.6.12 火炬:1.4.0 CUDA 工具包:10.1 cuDNN: 7.6.5
【问题讨论】:
我认为 Coco 类别 ID 是基于 1 的。你配置正确了吗(检查config.py) 【参考方案1】:您在 annotations.json 中的类 id 应该从 1 而不是 0 开始。如果它们从 0 开始,请在标签映射中的“my_custom_dataset”中的 config.py 中尝试添加此
'label_map': 0: 1, 1: 2, 2: 3... and so on
在这种情况下有 3 个类!
同样在同一脚本中的 yolact_base_config 中,num_classes 应该比您的类数大 1,例如在本例中为 4。
【讨论】:
感谢您的建议!我立即更改了 config.py 中的“label_map”部分,并再次运行了 train.py。但我得到了同样的错误。我再次检查了train.json和test.json文件,但类别只是“可以”。而“can”的“id”为0。 id 应该是 1 而不是 0。如果您使用github.com/dbolya/yolact/issues/70#issuecomment-504283008 中提到的步骤,并且labels.txt 中应该有ignore 和background,并且第3 行应该可以。您也可以查看此链接immersivelimit.com/tutorials/… 再次感谢您的建议!使用您提供给我的 URL 信息,我重新创建了 label.txt 并对其进行了注释。并且我确认train.json和test.json的“can”的“categories”的“id”改为1。但是,我仍然遇到错误“return coco_cats [transformed_cat_id] KeyError:1”...... config.py 中“DATASET”的内容如下。 'class_names': ('can'), 'label_map': 1: 1 在原始 config.py 的第 661 行将 更改为我准备的train.json如下。 test.json 的内容几乎一样。
"info": "description": null, "url": null, "version": null, "year": 2020, "contributor": null, "date_created": "2020-10-22 17 :03:01.164640", "licenses": ["url": null, "id": 0, "name": null], "images": ["license": 0, "url": null , "file_name": "1v6s4.jpg", "height": 640, "width": 480, "date_captured": null, "id": 0, "license": 0, "url": null, "文件名”:“11aaw.jpg”,“高度”:640,“宽度”:480,“日期捕获”:空,“id”:1,“许可证”:0,“url”:空,“文件名” : "a255r.jpg", "height": 640, "width": 480, "date_captured": null, "id": 2, "license": 0, "url": null, "file_name": " 3ww4h.jpg", "height": 640, "width": 480, "date_captured": null, "id": 3, "license": 0, "url": null, "file_name": "crgm5. jpg", "height": 640, "width": 480, "date_captured": null, "id": 4, "license": 0, "url": null, "file_name": "hh00w.jpg" , "height": 640, "width": 480, "date_captured": null, "id": 5, "license": 0, "url": null, "file_name": "60fwn.jpg", "高度”:640,“宽度”:480,“date_captur ed": null, "id": 6, "license": 0, "url": null, "file_name": "5umjh.jpg", "height": 640, "width": 480, "date_captured" :null,“id”:7,“license”:0,“url”:null,“file_name”:“as8ox.jpg”,“height”:640,“width”:480,“date_captured”:null , "id": 8, "license": 0, "url": null, "file_name": "cyu14.jpg", "height": 640, "width": 480, "date_captured": null, " id": 9], "type": "instances", "annotations": ["id": 0, "image_id": 0, "category_id": 1, "segmentation": [[276.12582781456956, 190.39072847682118, 129.10596026490066 ,224.16556291390728,108.57615894039736,237.41059602649005,90.6953642384106,267.87417218543044,87.38410596026489,306.94701986754967,92.01986754966885,345.3576158940397,115.19867549668874,387.7417218543046,146.98675496688742,416.21854304635764,178.7748344370861,433.4370860927152,231.09271523178808,426.1523178807947,335.06622516556286,343.3708609271523,367.51655629139077,299.0,368.841059602649,277.8079470198675,378.77483443708604,261.9139072847682 , 378.1125827814569,236.74834437086093,358.90728476821187,213.56953642384107,333.7417218543046,207.60927152317882,308.57615894039736,193.7019867549669]], “面积”:50785.0, “BBOX”:[87.0,190.0,292.0,244.0], “iscrowd”:0, “ID”: 1, “image_id”:1, “CATEGORY_ID”:1, “分割”:[[252.28476821192055,218.20529801324503,195.99337748344368,226.1523178807947,157.58278145695363,249.9933774834437,129.76821192052978,279.1324503311258,115.86092715231786,312.2450331125828,117.84768211920527,365.2251655629139,132.41721854304637,400.3245033112583,176.78807947019868, 495.6887417218543,201.95364238410593,509.5960264900662,231.09271523178808,515.5562913907285,256.2582781456954,514.8940397350993,281.42384105960264,499.6622516556291,370.16556291390725,388.4039735099338,380.0993377483444,346.01986754966885,373.47682119205297,299.6622516556291,340.36423841059604,253.3046357615894,293.34437086092714,224.16556291390728]], “面积”:58133.0, “BBOX”: [115.0、218.0、266。 0,298.0], “iscrowd”:0, “ID”:2 “image_id”:2 “CATEGORY_ID”:1, “分割”:[[190.6953642384106,175.82119205298014,169.50331125827813,172.50993377483442,148.31125827814571,178.47019867549668,130.43046357615896 ,191.71523178807948,120.49668874172187,212.24503311258277,117.18543046357615,230.78807947019868,121.15894039735099,248.66887417218544,201.95364238410593,371.8476821192053,221.8211920529801,392.3774834437086,235.0662251655629,407.6092715231788,253.6092715231788,415.55629139072846,276.12582781456956,414.89403973509934,306.5894039735099,400.9867549668874,328.44370860927154,379.79470198675494,343.67549668874176,355.95364238410593,348.3112582781457,330.12582781456956 ,343.67549668874176,310.9205298013245,332.4172185430464,297.6754966887417,319.1721854304636,279.1324503311258]], “面积”:32819.0, “BBOX”:[117.0,172.0,232.0,244.0], “iscrowd”:0, “ID”:3“, image_id": 3, "category_id": 1, "segmentation": [[301.95364238410593, 155.29139072847 68,285.3973509933775,157.27814569536423,274.1390728476821,164.56291390728478,272.81456953642385,173.83443708609272,268.1788079470199,180.4569536423841,264.20529801324506,297.0132450331126,284.07284768211923,310.2582781456954,303.2781456953643,310.9205298013245,322.48344370860923,300.9867549668874,336.3907284768212,191.05298013245033,334.40397350993373,182.4437086092715,333.7417218543046,168.53642384105962,321.158940397351,159.9271523178808] ], "area": 9448.0, "bbox": [264.0, 155.0, 73.0, 156.0], "iscrowd": 0, "id": 4, "image_id": 3, "category_id": 1, "segmentation “:[[143.01324503311258,315.55629139072846,122.48344370860929,320.8543046357616,110.56291390728478,332.7748344370861,105.26490066225165,347.34437086092714,105.26490066225165,353.3046357615894,104.60264900662253,362.57615894039736,141.02649006622516,468.5364238410596,156.25827814569539,472.50993377483445,179.43708609271522,469.19867549668874,192.68211920529802,461.25165562913907,197。 9801324503311,444.6953642384106,182.08609271523176,342.7086092715232,177.4503311258278,338.07284768211923,170.82781456953643,324.82781456953643,157.58278145695363,317.5430463576159]], “面积”:10548.0, “BBOX”:[104.0,315.0,94.0,158.0], “iscrowd”:0, “ID”:5 “image_id”:4 “CATEGORY_ID”:1, “分割”:[[321.158940397351,231.4503311258278,111.88741721854302,310.9205298013245,95.99337748344368,330.12582781456956,99.96688741721852,358.6026490066225,117.84768211920527,398.3377483443709,137.71523178807945,428.80132450331126,142.35099337748346, 432.112582781457,170.1655629139073,434.7615894039735,365.5298013245033,334.7615894039735,375.46357615894044,310.9205298013245,372.1523178807947,282.44370860927154,356.2582781456954,252.64238410596028,336.3907284768212,234.76158940397352]], “面积”:33580.0, “BBOX”:[95.0,231.0,281.0,204.0],“iscrowd ": 0, "id": 6, "image_id": 5, "category_id": 1, "segmentation": [[235.72847682119203, 177.1456953642384, 182. 74834437086093,183.10596026490066,185.39735099337747,189.0662251655629,178.11258278145698,217.54304635761588,177.4503311258278,465.887417218543,188.7086092715232,473.8344370860927,220.49668874172187,478.4701986754967,257.5827814569536,477.1456953642384,290.0331125827814,467.2119205298013,294.6688741721854,218.20529801324503,286.7218543046357,194.36423841059602,290.69536423841055,184.43046357615893]], “面积”: 33720.0, "bbox": [177.0, 177.0, 118.0, 302.0], "iscrowd": 0, "id": 7, "image_id": 6, "category_id": 1, "segmentation": [[185.39735099337747, 210.25827814569536,156.9205298013245,211.58278145695365,127.78145695364236,222.17880794701986,119.83443708609269,241.3841059602649,122.48344370860929,251.31788079470198,115.19867549668874,273.17218543046357,130.43046357615896,471.8476821192053,145.0,491.05298013245033,173.47682119205297,496.35099337748346,203.27814569536423,494.36423841059604,220.49668874172187,485.0927152317881,227.11920529801324,4 73.8344370860927,251.62251655629137,271.8476821192053,246.3245033112583,262.57615894039736,248.31125827814571,242.04635761589404,239.03973509933775,224.16556291390728,212.5496688741722,214.2317880794702]], “面积”:32447.0, “BBOX”:[115.0,210.0,137.0,287.0], “iscrowd”:0 , “ID”:8中, “image_id”:7, “CATEGORY_ID”:1, “分割”:[[240.36423841059604,157.94039735099338,213.21192052980132,163.23841059602648,200.6291390728477,166.5496688741722,204.60264900662253,177.80794701986756,203.27814569536423,181.11920529801324,203.94039735099335,185.09271523178808, 200.6291390728477,198.33774834437085,202.6158940397351,200.32450331125827,204.60264900662253,215.5562913907285,192.01986754966885,229.46357615894038,172.81456953642385,273.17218543046357,180.76158940397352,471.18543046357615,183.41059602649005,477.1456953642384,182.74834437086093,482.44370860927154,203.94039735099335,500.3245033112583,237.71523178807945,504.96026490066225,276.7880794701987,5 00.3245033112583,297.9801324503311,492.3774834437086,303.2781456953643,478.4701986754967,301.95364238410593,471.8476821192053,307.2516556291391,463.9006622516556,307.91390728476824,266.5496688741722,292.0198675496689,228.80132450331126,280.7615894039735,215.5562913907285,282.7483443708609,210.9205298013245,278.1125827814569,202.3112582781457,280.0993377483444,195.02649006622516,280.7615894039735,163.90066225165563,250.96026490066225,158.60264900662253] ], "area": 40240.0, "bbox": [172.0, 157.0, 136.0, 348.0], "iscrowd": 0, "id": 9, "image_id": 8, "category_id": 1, "segmentation “:[[243.01324503311258,165.2251655629139,214.53642384105962,169.86092715231788,195.33112582781456,177.80794701986756,181.42384105960264,187.74172185430464,176.78807947019868,206.28476821192052,180.0993377483444,210.25827814569536,172.81456953642385,224.82781456953643,187.3841059602649,449.33112582781456,197.9801324503311,469.19867549668874,227.11920529801324,480.456953 6423841,249.63576158940396,481.11920529801324,272.1523178807947,473.8344370860927,289.3708609271523,457.94039735099335,323.8079470198676,228.80132450331126,319.83443708609275,218.86754966887418,319.83443708609275,204.2980132450331,313.2119205298013,189.0662251655629,294.00662251655626,175.158940397351,270.8278145695364,169.86092715231788]], “面积”:38543.0, “BBOX”: [172.0,165.0,152.0,317.0],“iscrowd”:0,“ID”:10,“image_id”:9,“categor_id”:1,“分段”:[[122.48344370860860860860860860890860860860469,280,2839,280,289,280,289,280,289,280,283930430430460430490 82.08609271523181,302.3112582781457,78.7748344370861,311.5827814569536,82.08609271523181,327.47682119205297,154.9337748344371,447.34437086092714,170.1655629139073,447.34437086092714,205.26490066225165,422.841059602649,211.88741721854302,408.27152317880797,135.72847682119203,291.05298013245033]], “面积”:11069.0, “BBOX”:[78.0,283.0,134.0 , 165.0], "iscrowd": 0, "id": 11, "image_id": 9, "category_id": 1, "se gmentation“:[[383.4105960264901,249.33112582781456,370.8278145695364,245.35761589403972,355.59602649006627,246.01986754966887,337.05298013245033,258.6026490066225,337.05298013245033,266.5496688741722,351.62251655629143,384.43046357615896,358.90728476821187,392.3774834437086,380.0993377483444,393.03973509933775,402.61589403973505,385.7549668874172,409.2384105960265,378.4701986754967,388.04635761589407,256.6158940397351]] , "区域": 7924.0, "bbox": [337.0, 245.0, 73.0, 149.0], "iscrowd": 0], "类别": ["supercategory": null, "id": 0, "name" : "背景", "supercategory": null, "id": 1, "name": "can"]
我使用 git clone 命令在我的主目录中安装了 yolact。 我PC的目录结构如下:
/home/user-name/yolact/cans/cans_train/train.json 和图片
/home/user-name/yolact/cans/cans_test/test.json 和图片
最后,我在config.py中设置了--DATASETS--如下。
cans_dataset = dataset_base.copy(
'name': 'cans_dataset',
'train_images': './cans/cans_train/',
'train_info': './cans/cans_train/train.json',
'valid_images': './cans/cans_test/',
'valid_info': './cans/cans_test/test.json',
'has_gt': True,
'class_names': ('can'),
'label_map': 1: 1
我在 config.py 中设置 --YOLACT v1.0 CONFIGS-- 如下。
cans_config = yolact_darknet53_config.copy(
'name': 'cans',
'dataset': cans_dataset,
'num_classes': len(cans_dataset.class_names) + 1,
'max_size': 500,
# Training params
'lr_steps': (8000, 9000),
'max_iter': 10000,
)
【讨论】:
您能否也显示您的 -- YOLACT v1.0 CONFIGS --?它应该是......'dataset': my_custom_dataset, 'num_classes': len(my_custom_dataset.class_names) + 1,或者只是 2。就像这是我的一样,您可以将其设置为您的特定名称。 我添加了我自己设置的-YOLACT v1.0 CONFIGS-的信息。以上是关于当我使用 YOLACT 运行 train.py 时,我收到错误 KeyError: 0的主要内容,如果未能解决你的问题,请参考以下文章
自定义对象检测train.py-错误:在https://pastebin.com/raw/EtkkfiDX处进行分块
TensorFlow 对象检测 API 没有 train.py 文件
nn_train.py: error: the following arguments are required:pycharm设置python运行参数