小编Tri*_*ang的帖子

在执行 tf.train.example 时,出现 TypeError: 71 has type int, but Expected one of: bytes

存在类型错误,但类型已经是字节。请帮我解决一下。谢谢。

Traceback (most recent call last):
   File "toTFRECORDS_1.py", line 29, in <module>
      feature = {'train/image': _bytes_feature(img_data),
   File "toTFRECORDS_1.py", line 10, in _bytes_feature
      return tf.train.Feature(bytes_list=tf.train.BytesList(value=value))
TypeError: 71 has type int, but expected one of: bytes
Run Code Online (Sandbox Code Playgroud)

代码如下。但我不知道哪里出了问题,我自己也无法弄清楚。

def _int64_feature(value):
    return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))

def _bytes_feature(value):
    return tf.train.Feature(bytes_list=tf.train.BytesList(value=value))

images = os.listdir('D:\python_64\Training_Set')


train_filename = 'train.tfrecords'
with tf.python_io.TFRecordWriter(train_filename) as tfrecord_writer: 
    for i in range(len(images)):
        # read in image data by tf
        img_data = tf.gfile.FastGFile(os.path.join('D:\python_64\Training_Set',images[i]), 'rb').read()  # image data type is string
        # get width and height of …
Run Code Online (Sandbox Code Playgroud)

python tensorflow

2
推荐指数
1
解决办法
2984
查看次数

标签 统计

python ×1

tensorflow ×1