Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow Inception build_imagenet_data.py TypeError:&x27;RGB&x27;具有类型<;类别';str'>;,但应为以下内容之一:(<;class';字节';>;,)_Tensorflow - Fatal编程技术网

Tensorflow Inception build_imagenet_data.py TypeError:&x27;RGB&x27;具有类型<;类别';str'>;,但应为以下内容之一:(<;class';字节';>;,)

Tensorflow Inception build_imagenet_data.py TypeError:&x27;RGB&x27;具有类型<;类别';str'>;,但应为以下内容之一:(<;class';字节';>;,),tensorflow,Tensorflow,我试图在以下示例中使用_convert_to_example()函数的一个轻微变体: 我得到一个与colorspace变量关联的错误: TypeError:'RGB'具有类型类'str',但应为以下类型之一:(类'bytes',) 如果我注释掉图像/颜色空间特性,我会得到与图像/格式相同的错误。图像/文件名也是如此。如果我注释掉这三个特性,该函数似乎会按预期运行。我做错了什么?这听起来像是Python 2/3不兼容的问题。通过在字符串文本前加ab,可以显式地将colorspace和image\u

我试图在以下示例中使用_convert_to_example()函数的一个轻微变体:

我得到一个与colorspace变量关联的错误:

TypeError:'RGB'具有类型类'str',但应为以下类型之一:(类'bytes',)


如果我注释掉图像/颜色空间特性,我会得到与图像/格式相同的错误。图像/文件名也是如此。如果我注释掉这三个特性,该函数似乎会按预期运行。我做错了什么?

这听起来像是Python 2/3不兼容的问题。通过在字符串文本前加a
b
,可以显式地将
colorspace
image\u格式
创建为
bytes
对象,如下所示:

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

我注意到了一些额外的变化

o     #shuffled_index = range(len(filenames))
o     shuffled_index = list(range(len(filenames)))
o     #for i in xrange(len(spacing) - 1):
o     for i in range(len(spacing) - 1):
o         'image/class/text': _bytes_feature(text.encode()),
o         'image/filename': _bytes_feature(os.path.basename(filename.encode())),
o     colorspace = 'RGB'.encode()
o     channels = 3
o     image_format = 'JPEG'.encode()

谢谢并确认。在py3.4中注意到该问题,但在py2.7中不存在。此外,除了建议在字符串文字前加上b外,encode()方法还可用于应用于字符串变量。
o     #shuffled_index = range(len(filenames))
o     shuffled_index = list(range(len(filenames)))
o     #for i in xrange(len(spacing) - 1):
o     for i in range(len(spacing) - 1):
o         'image/class/text': _bytes_feature(text.encode()),
o         'image/filename': _bytes_feature(os.path.basename(filename.encode())),
o     colorspace = 'RGB'.encode()
o     channels = 3
o     image_format = 'JPEG'.encode()