我試圖使用_convert_to_example()函數的輕微變型,build_imagenet_data.py:啓build_imagenet_data.py類型錯誤:「RGB」的類型是<class 'str'>,但預期的一個:(<類的字節'>,)
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',)
如果我註釋掉圖像/色彩空間的功能,我得到的圖像/格式相同的錯誤。同樣對於圖像/文件名。如果我評論這三個功能,功能似乎按預期運行。我究竟做錯了什麼?
謝謝並確認。 py3.4提到了這個問題,但使用py2.7不存在。此外,除了將b預設爲字符串文字的建議之外,encode()方法適用於字符串變量。 – RobR