【发布时间】:2022-06-16 23:59:19
【问题描述】:
我写这个问题是为了提醒自己,因为我已经知道我会再次重现这个错误,我不想再花半个小时来修复它。
我目前正在做一个机器学习项目,在执行网络的过程中遇到了一个错误: 当我像这样编写 Tfrecords 后执行神经网络时
def write_to_tfrec_spatial(training_directories, path, filename):
record_file = filename
n_samples = len(training_directories)
print()
print(n_samples)
with tf.io.TFRecordWriter(record_file) as writer:
print("writing", end=": ")
for i in range(n_samples):
if(i % 50) == 0:
print()
print(i, end=",")
dir = path + training_directories[i]
loaded = np.load(dir)
ground = loaded["rad"]
if normalization:
ground = ground / max_norm_value
print(np.amax(ground), end=",")
padded_ground = np.pad(ground, [(3, 2), (0, 0)], mode='constant')
inputs = data_augmentation(padded_ground)
for input in inputs:
tf_example = image_example_spatial(input=input, ground=padded_ground)
writer.write(tf_example.SerializeToString())
return record_file
然后我像这样执行网络:
model.fit(training_dataset, steps_per_epoch=steps, epochs=60, validation_data=validation_dataset, callbacks=my_callbacks)
但我收到以下错误:
2 root error(s) found.
(0) INVALID_ARGUMENT: Input to reshape is a tensor with 376832 values, but the requested shape has 188416
[[{{node Reshape}}]]
[[IteratorGetNext]]
[[IteratorGetNext/_428]]
(1) INVALID_ARGUMENT: Input to reshape is a tensor with 376832 values, but the requested shape has 188416
[[{{node Reshape}}]]
[[IteratorGetNext]]
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_165085]
我不明白为什么我得到的值恰好是两倍,我检查了多次形状并且它们总是正确的,但是 TFRecord 总是返回错误数量的值
【问题讨论】:
标签: python tensorflow keras deep-learning neural-network