存在类型错误,但类型已经是字节。请帮我解决一下。谢谢。
Run Code Online (Sandbox Code Playgroud)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
代码如下。但我不知道哪里出了问题,我自己也无法弄清楚。
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)