调试错误:ValueError: Protocol message Feature has no "feature" field.
程序员文章站
2022-03-03 17:42:12
...
学习《Tensorflow:实战Google深度学习框架》过程中,在复现第7章 7.1节中的例子时出现错误
代码:
#-*-coding:utf-8-*-
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import numpy as np
##
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]))
mnist = input_data.read_data_sets('./mnist_data',dtype=tf.uint8,one_hot=True)
images = mnist.train.images
labels = mnist.train.labels
pixels = images.shape[1]
num_examples = mnist.train.num_examples
filename = './mnist_data/output.tfrecords'
writer = tf.python_io.TFRecordWriter(filename)
for index in range(num_examples):
image_raw = images[index].tostring()
example = tf.train.Example(
features = tf.train.Feature(
feature = {
'pixels':_int64_feature(pixels),
'label':_int64_feature(np.argmax(labels[index])),
'image_raw':_bytes_feature(image_raw)
}
)
)
writer.write(example.SerializeToString())
writer.
出错情况:
出错原因:以下位置
example = tf.train.Example(
features = tf.train.Feature(
tf.train.Feature 应该是 tf.train.Features。 少写了一个s 。
感谢博主:https://blog.csdn.net/Eric_Blog_CSDN/article/details/80466071#commentBox
上一篇: 学习笔记 -- MySQL常用函数(三)
下一篇: MySQL笔记--常用函数