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
大概我将我的注释列错误地设置为它的期望。