首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Turi Create中使用对象检测导致错误的注释

在Turi Create中使用对象检测导致错误的注释
EN

Stack Overflow用户
提问于 2017-12-13 22:50:21
回答 2查看 384关注 0票数 1

Turi Create中的guide for Object Detection并没有涵盖数据的设置,包括如何附加“注解”类别。

我所做的是创建一个单独的annotations文件,如下所示:

代码语言:javascript
复制
{
  "1.jpg": {
    "type": "rectangle",
    "coordinates": {
      "height": 97,
      "width": 243,
      "x": 4224,
      "y": 1821
    },
    "label": "cw"
}

然后我使用load_images设置我的数据,并使用这个文件:

代码语言:javascript
复制
# 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,我会得到这样的结果:

代码语言:javascript
复制
+-------------------------------+---------------------------+
|              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... |
+-------------------------------+

我不知道为什么它在控制台中被分成两行--可能只是因为大小的原因。

然后,我来到了Object Detection指南中的这一行,它打算可视化应用于数据的注释:

代码语言:javascript
复制
tc.object_detector.util.draw_bounding_boxes(data["image"], data["annotations"])

当我运行此命令时,我在控制台中收到以下错误:

代码语言:javascript
复制
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

此外,如果我将其注释掉,然后继续执行以下操作:

代码语言:javascript
复制
model = tc.object_detector.create(data, feature="image", annotations="annotations")

我得到了错误:

代码语言:javascript
复制
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

大概我错误地设置了我的注释栏,使其不符合预期。

EN

回答 2

Stack Overflow用户

发布于 2017-12-28 15:30:22

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

目前还不太确定该如何解决这个问题。但当我得到解决方案时,我会尝试发布。

票数 0
EN

Stack Overflow用户

发布于 2020-07-05 20:55:21

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

代码语言:javascript
复制
turicreate.toolkits._main.ToolkitError: Annotations column must contain lists 

试一试

代码语言:javascript
复制
annotations.column_types() or data.column_types()

您很可能会看到类似这样的内容

代码语言:javascript
复制
 str, image, str

而不是所需的

代码语言:javascript
复制
str, image, list

而问题将是一个格式错误的字符串,因此Python解析器会断定。在我的例子中,缺陷只是在每一行的闭方括号后有一个额外的空格。修复它,重新运行column_types来验证列表处理是否正确,然后继续前进到下一个障碍!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47795909

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档