编程语言
首页 > 编程语言> > ValueError: Negative dimension size caused by subtracting 5 from 1 for ‘{{node le_net5/conv2d/Conv2D

ValueError: Negative dimension size caused by subtracting 5 from 1 for ‘{{node le_net5/conv2d/Conv2D

作者:互联网

ValueError: Negative dimension size caused by subtracting 5 from 1 for '{{node le_net5/conv2d/Conv2D}} = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], explicit_paddings=[], padding="VALID", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true](le_net5/Cast, le_net5/conv2d/Conv2D/ReadVariableOp)' with input shapes: [32,1,28,28], [5,5,28,6].

使用Tensorflow搭建LeNet5训练Mnist数据集,出错的原因是图像数据维度的问题,输入模型的数据应该是三维,即 (32,32,3)或者(3,32,32),TensorFlow默认接受的是第一种方式,即(width,height,channel)
解决方法:
法一:在(60000,32,32)添加一个维度,填在最后面变成(60000,32,32,3)

train_images = tf.expand_dims(train_images, axis=3)

法二:修改TenforFlow默认指定通道方式

backend.set_image_data_format("channels_first")

标签:node,le,caused,28,conv2d,32,net5,Conv2D
来源: https://blog.csdn.net/m0_47256162/article/details/122161059