Python Tensorflow:无效参数:元组组件中的形状不匹配
我在运行输入记录函数时出现以下错误Python Tensorflow:无效参数:元组组件中的形状不匹配,python,numpy,queue,tensorflow,labels,Python,Numpy,Queue,Tensorflow,Labels,我在运行输入记录函数时出现以下错误 Invalid argument: Shape mismatch in tuple component 1 Expected [2], got [4] 我的标签是每个记录的(0,1)numpy数组。设置的尺寸为2。但它给出了错误的尺寸误差。 解码后打印张量对象也会得到维度2 Tensor("DecodeRaw_1:0", shape=(2,), dtype=float32) 输入功能是: def input(): filename_queue = tf
Invalid argument: Shape mismatch in tuple component 1
Expected [2], got [4]
我的标签是每个记录的(0,1)numpy数组。设置的尺寸为2。但它给出了错误的尺寸误差。
解码后打印张量对象也会得到维度2
Tensor("DecodeRaw_1:0", shape=(2,), dtype=float32)
输入功能是:
def input():
filename_queue = tf.train.string_input_producer(["path_to_record"])
print filename_queue
label = read_and_decode(f_queue)
min_queue_examples = n
labels_batch = tf.train.shuffle_batch(
[ label_record],
batch_size=batch_size,
num_threads=2,
capacity=min_queue_examples + 3 * batch_size,
min_after_dequeue=min_queue_examples)
return labels_batch
读取记录功能为
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example,
features={
'label': tf.FixedLenFeature([], tf.string),
})
)
label = tf.decode_raw(features['label'], tf.float32)
label.set_shape([2])
return label
此错误最可能的原因是
label.set\u shape([2])
调用断言的形状与tf.decode\u raw()的结果的真实形状不匹配。尝试调用sess.run(label)
获取其中一个张量的值,并打印其真实形状。从tfrecords读取原始数据时,可能是张量的数据类型错误