gpt4 book ai didi

tensorflow - Inception build_imagenet_data.py TypeError : 'RGB' has type , 但预期为 : (, 之一)

转载 作者:行者123 更新时间:2023-12-03 23:59:26 24 4
gpt4 key购买 nike

我试图在 build_imagenet_data.py 中使用 _convert_to_example() 函数的一个轻微变体:

def _convert_to_example(filename, image_buffer, label, bboxes, height, width):

xmin = []
ymin = []
xmax = []
ymax = []
for b in bboxes:
assert len(b) == 4
# pylint: disable=expression-not-assigned
[l.append(point) for l, point in zip([xmin, ymin, xmax, ymax], b)]
# pylint: enable=expression-not-assigned

colorspace = 'RGB'
channels = 3
image_format = 'JPEG'

example = tf.train.Example(features=tf.train.Features(feature={
'image/height': _int64_feature(height),
'image/width': _int64_feature(width),
'image/colorspace': _bytes_feature(colorspace),
'image/channels': _int64_feature(channels),
'image/class/label': _int64_feature(label),
'image/object/bbox/xmin': _float_feature(xmin),
'image/object/bbox/xmax': _float_feature(xmax),
'image/object/bbox/ymin': _float_feature(ymin),
'image/object/bbox/ymax': _float_feature(ymax),
'image/object/bbox/label': _int64_feature(label),
'image/format': _bytes_feature(image_format),
'image/filename': _bytes_feature(os.path.basename(filename)),
'image/encoded': _bytes_feature(image_buffer)}))
return example

我收到与颜色空间变量相关的错误:

TypeError: 'RGB' has type class 'str', but expected one of: (class 'bytes',)



如果我注释掉图像/色彩空间功能,我会收到与图像/格式相同的错误。同样对于图像/文件名。如果我注释掉这三个功能,该功能似乎按预期运行。我究竟做错了什么?

最佳答案

这听起来像是 Python 2/3 不兼容问题。您可以显式创建 colorspaceimage_formatbytes通过在对象前面加上 b到字符串文字,如下所示:

colorspace = b'RGB'
# ...
image_format = b'JPEG'

关于tensorflow - Inception build_imagenet_data.py TypeError : 'RGB' has type <class 'str' >, 但预期为 : (<class 'bytes' >, 之一),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38546672/

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