【发布时间】:2021-01-12 06:19:23
【问题描述】:
我正在尝试在 Open Images Dataset (v6) 上进行基本的 Tensorflow 边界框对象检测...
File "/home/work/models/research/object_detection/dataset_tools/create_oid_tf_record.py", line 115, in main
tf_example = oid_tfrecord_creation.tf_example_from_annotations_data_frame(
File "/root/anaconda3/lib/python3.8/site-packages/object_detection/dataset_tools/oid_tfrecord_creation.py", line 71, in tf_example_from_annotations_data_frame
dataset_util.bytes_feature('{}.jpg'.format(image_id)),
File "/root/anaconda3/lib/python3.8/site-packages/object_detection/utils/dataset_util.py", line 33, in bytes_feature
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
TypeError: '000411001ff7dd4f.jpg' has type str, but expected one of: bytes
相关代码好像在这里:
def bytes_feature(value):
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
我以为value=[value.encode()] 可能会修复它,但后来它说:
AttributeError: 'bytes' object has no attribute 'encode'
(嗯,是哪个,TF?bytes 还是 str?)
输入文件中的行包含:
ImageID,Source,LabelName,Confidence,XMin,XMax,YMin,YMax,IsOccluded,IsTruncated,IsGroupOf,IsDepiction,IsInside,XClick1X,XClick2X,XClick3X,XClick4X,XClick1Y,XClick2Y,XClick3Y,XClick4Y
000411001ff7dd4f,xclick,/m/09b5t,1,0.1734375,0.46875,0.19791667,0.7916667,0,0,1,0,0
TFRecord 的特征图:
feature_map = {
standard_fields.TfExampleFields.object_bbox_ymin:
dataset_util.float_list_feature(
filtered_data_frame_boxes.YMin.to_numpy()),
standard_fields.TfExampleFields.object_bbox_xmin:
dataset_util.float_list_feature(
filtered_data_frame_boxes.XMin.to_numpy()),
standard_fields.TfExampleFields.object_bbox_ymax:
dataset_util.float_list_feature(
filtered_data_frame_boxes.YMax.to_numpy()),
standard_fields.TfExampleFields.object_bbox_xmax:
dataset_util.float_list_feature(
filtered_data_frame_boxes.XMax.to_numpy()),
standard_fields.TfExampleFields.object_class_text:
dataset_util.bytes_list_feature(
filtered_data_frame_boxes.LabelName.to_numpy()),
standard_fields.TfExampleFields.object_class_label:
dataset_util.int64_list_feature(
filtered_data_frame_boxes.LabelName.map(lambda x: label_map[x])
.to_numpy()),
standard_fields.TfExampleFields.filename:
dataset_util.bytes_feature('{}.jpg'.format(image_id)),
standard_fields.TfExampleFields.source_id:
dataset_util.bytes_feature(image_id),
standard_fields.TfExampleFields.image_encoded:
dataset_util.bytes_feature(encoded_image),
}
有什么想法吗?我安装了 pip3 并且必须修复一堆包弃用错误才能达到这一点。
pip3 install tensorflow
pip3 install tensorflow-object-detection-api
编辑:
版本:
tensorflow 2.3.1
tensorflow-object-detection-api 0.1.1
我试过了
standard_fields.TfExampleFields.filename:
dataset_util.bytes_feature(bytes(('{}.jpg'.format(image_id)),'ascii')),
但它得到以下内容:
TypeError: '000411001ff7dd4f' has type str, but expected one of: bytes
(.jpg 去哪儿了?)
【问题讨论】:
-
我很确定 API 需要的是文件的 contents,而不是文件名。您甚至可能不得不使用其他东西将图像数据加载到表示位图的数组中。
-
"输入文件中的行包含:"你在说什么输入文件?这显然不是 .jpg。
-
无论如何,您应该绝对不要试图通过编辑库代码来解决问题。我不清楚这里的任何代码框是否代表您编写的代码。
-
您好 Karl,该字段名为“文件名”。我很确定它需要文件名。
-
我不习惯 3.x 代码以字节表示文件名,但我猜这是 TF 接口的结果。 ://
标签: python tensorflow tensorflow2.0 object-detection object-detection-api