1

Turi Create 中的对象检测指南不包括设置数据,包括如何附加“注释”类别。

我所做的是创建一个单独的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]])

这很好用,如果我 print 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 行 - 可能只是出于调整大小的原因。

因此,我在 Object Detection 指南中找到了这一行,它旨在可视化应用于数据的注释:

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

大概我将我的注释列错误地设置为它的期望。

4

2 回答 2

0

有点晚了,但我最近遇到了这个问题,或者至少是同样的错误报告。当你得到类似的东西时:

turicreate.toolkits._main.ToolkitError: Annotations column must contain lists 

尝试

annotations.column_types() or data.column_types()

你很可能会看到类似的东西

 str, image, str

而不是想要的

str, image, list

问题将是一个格式错误的字符串,因此 Python 解析器会出错。在我的情况下,缺陷只是每行右方括号后的一个额外空格。修复它,重新运行 column_types 以验证列表处理是否正确,然后继续下一个障碍!

于 2020-07-05T12:55:20.937 回答
0

annotations列缺少左括号和右括号。如果您查看本教程中的可视化输出,您会看到每个注释的开头都有一个左括号(......最后可能还有一个右括号)。

目前不完全确定如何解决这个问题。但是当我得到解决方案时会尝试发布。

于 2017-12-28T07:30:22.297 回答