gpt4 book ai didi

python - 类型错误 : '...' has type str, 但需要以下之一:字节

转载 作者:行者123 更新时间:2023-12-02 19:12:21 27 4
gpt4 key购买 nike

我正在尝试在开放图像数据集(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?字节还是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 到哪里去了?)

最佳答案

TypeError 似乎引用了此行中创建的文件名:

dataset_util.bytes_feature('{}.jpg'.format(image_id)),

也许这个图像名称应该是字节,如下所示:

dataset_util.bytes_feature('{}.jpg'.format(image_id).encode()),

关于python - 类型错误 : '...' has type str, 但需要以下之一:字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64072148/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com