Turi Create中的guide for Object Detection不包括设置数据,包括如何附加“注释”类别。
我所做的是创建一个单独的annotations
文件,如下所示:
{
"1.jpg": {
"type": "rectangle",
"coordinates": {
"height": 97,
"width": 243,
"x": 4224,
"y": 1821
},
"label": "cw"
}
然后我使用load_images
和此文件设置我的数据:
# Load images
data = tc.image_analysis.load_images('train', with_path=True)
# Open annotations file as dict
annotations = eval(open("annotations").read())
# Add annotations column to SFrame, using the annotations dict key with the same name as the file name
data["annotations"] = data["path"].apply(lambda path: bounds[os.path.split(path)[1]])
效果很好,如果我打印data
,我会得到类似的结果:
+-------------------------------+---------------------------+
| path | image |
+-------------------------------+---------------------------+
| /Users/Andrew/Code/turi/cw... | Height: 3816 Width: 11056 |
| /Users/Andrew/Code/turi/cw... | Height: 3888 Width: 10672 |
| /Users/Andrew/Code/turi/cw... | Height: 3656 Width: 9700 |
| /Users/Andrew/Code/turi/cw... | Height: 3872 Width: 8280 |
+-------------------------------+---------------------------+
+-------------------------------+
| annotations |
+-------------------------------+
| {'type': 'rectangle', 'coo... |
| {'type': 'rectangle', 'coo... |
| {'type': 'rectangle', 'coo... |
| {'type': 'rectangle', 'coo... |
+-------------------------------+
我不知道为什么在控制台中将它分成2行 - 可能仅仅是为了调整尺寸。
然后我在对象检测指南中找到这一行,它打算可视化应用于数据的注释:
tc.object_detector.util.draw_bounding_boxes(data["image"], data["annotations"])
当我运行它时,我在控制台中收到此错误:
Traceback (most recent call last):
File "app.py", line 62, in <module>
load_data(bounds)
File "app.py", line 23, in load_data
tc.object_detector.util.draw_bounding_boxes(data["image"], data["annotations"])
File "/Users/Andrew/turi/lib/python2.7/site-packages/turicreate/toolkits/object_detector/util/_visualization.py", line 139, in draw_bounding_boxes
.apply(draw_single_image))
File "/Users/Andrew/turi/lib/python2.7/site-packages/turicreate/data_structures/sframe.py", line 2463, in apply
dryrun = [fn(row) for row in test_sf]
File "/Users/Andrew/turi/lib/python2.7/site-packages/turicreate/toolkits/object_detector/util/_visualization.py", line 124, in draw_single_image
_annotate_image(pil_img, anns, confidence_threshold=confidence_threshold)
File "/Users/Andrew/turi/lib/python2.7/site-packages/turicreate/toolkits/object_detector/util/_visualization.py", line 49, in _annotate_image
for ann in reversed(anns):
TypeError: argument to reversed() must be a sequence
另外,如果我发表评论,然后继续做:
model = tc.object_detector.create(data, feature="image", annotations="annotations")
我收到错误:
Traceback (most recent call last):
File "app.py", line 65, in <module>
learn()
File "app.py", line 37, in learn
model = tc.object_detector.create(data, feature="image", annotations="annotations")
File "/Users/Andrew/turi/lib/python2.7/site-packages/turicreate/toolkits/object_detector/object_detector.py", line 170, in create
require_annotations=True)
File "/Users/Andrew/turi/lib/python2.7/site-packages/turicreate/toolkits/object_detector/object_detector.py", line 66, in _raise_error_if_not_detection_sframe
raise _ToolkitError("Annotations column must contain lists")
turicreate.toolkits._main.ToolkitError: Annotations column must contain lists
据推测,我正在将我的注释列错误地设置为它的期望值。
答案 0 :(得分:0)
annotations
列缺少开始和结束括号。如果你看一下教程中的可视化输出,你会看到每个注释的开头都有一个开括号(...结果可能是最后的一个括号)。
目前还不确定如何解决这个问题。但是当我得到解决方案时会尝试发布。
答案 1 :(得分:0)
有点晚了,但是我最近遇到了这个问题,或者至少是相同的错误报告。当您得到类似的信息时:
turicreate.toolkits._main.ToolkitError: Annotations column must contain lists
尝试
annotations.column_types() or data.column_types()
您很可能会看到类似的东西
str, image, str
而不是期望的
str, image, list
,问题将是一个字符串格式错误,以便Python分析器使用barfs。在我的情况下,缺陷只是每行右方括号后的多余空间。对其进行修复,然后重新运行column_types以验证列表是否已正确处理,然后继续进行下一个障碍!