gpt4 book ai didi

python - tf.train.Features 类型错误 : No positional arguments allowed

转载 作者:行者123 更新时间:2023-12-05 08:55:55 25 4
gpt4 key购买 nike

我可能在这里做了一些愚蠢的事情,但我不确定为什么会收到此错误。

此代码有效:

example = tf.train.Example(features=tf.train.Features(feature={
'image/height': _int64_feature(FLAGS.img_height),
'image/width': _int64_feature(FLAGS.img_width),
'image/colorspace': _bytes_feature(tf.compat.as_bytes(colorspace)),
'image/channels': _int64_feature(channels),
'image/format': _bytes_feature(tf.compat.as_bytes(image_format)),
'image/label': _bytes_feature(label_img_buffer),
'image/label_path': _bytes_feature(tf.compat.as_bytes(os.path.basename(lbl_path))),
'image/fn_0': _bytes_feature(tf.compat.as_bytes(os.path.basename(ex_paths[0]))),
'image/encoded_0': _bytes_feature(tf.compat.as_bytes(ex_image_buffers[0])),
'image/fn_1': _bytes_feature(tf.compat.as_bytes(os.path.basename(ex_paths[1]))),
'image/encoded_1': _bytes_feature(tf.compat.as_bytes(ex_image_buffers[1])),
'image/fn_2': _bytes_feature(tf.compat.as_bytes(os.path.basename(ex_paths[2]))),
'image/encoded_2': _bytes_feature(tf.compat.as_bytes(ex_image_buffers[2]))}))
return example

但此代码不起作用(在帖子标题中抛出 TypeError):

feature_dict={
'image/height': _int64_feature(FLAGS.img_height),
'image/width': _int64_feature(FLAGS.img_width),
'image/colorspace': _bytes_feature(tf.compat.as_bytes(colorspace)),
'image/channels': _int64_feature(channels),
'image/format': _bytes_feature(tf.compat.as_bytes(image_format)),
'image/label': _bytes_feature(label_img_buffer),
'image/label_path': _bytes_feature(tf.compat.as_bytes(os.path.basename(lbl_path))),
}

for idx, image in sorted(ex_image_buffers.iteritems()):
img_key = 'image/encoded_' + str(idx)
fn_key = 'image/fn_' + str(idx)
feature_dict[img_key] = _bytes_feature(tf.compat.as_bytes(image))
feature_dict[fn_key] = _bytes_feature(tf.compat.as_bytes(os.path.basename(ex_paths[idx])))

example = tf.train.Example(features=tf.train.Features(feature_dict))
return example

ex_image_buffers 是一个列表。

据我所知,tf.train.Features 将字典作为参数,并且我在第一个示例和第二个示例中组装了相同的字典(我认为)。第二个允许我根据其他一些代码调整字典,所以我宁愿避免对不同的字段进行硬编码。

想法?感谢您的帮助!

最佳答案

是的,我认为你犯了一个愚蠢的错误。尝试

example = tf.train.Example(features=tf.train.Features(feature=feature_dict))

如错误所述,tf.train.Features 要求您传递关键字/参数对。您需要像在您提供的第一个示例中所做的那样添加关键字 feature

关于python - tf.train.Features 类型错误 : No positional arguments allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43567369/

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