简体   繁体   English

ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(None, 455, 30),找到的形状 =(None, 30)

[英]ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 455, 30), found shape=(None, 30)

Here is the little project of Cancer detection, and it has already has the dataset and colab code, but I get an error when I execute这里是Cancer detection的小项目,里面已经有了数据集和colab代码,但是我执行的时候报错

model.fit(x_train, y_train, epochs=1000)

The error is:错误是:

ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 455, 30), found shape=(None, 30)

When I look at the comments, other people are having this issue看评论其他人也有这个问题

The Tensorflow model expects the first dimension of the input to be the batch size, in the model declaration however they set the input shape to be the same shape as the input. Tensorflow model 期望输入的第一个维度是批量大小,在 model 声明中,它们将输入形状设置为与输入相同的形状。 To fix this you can change the input shape of the model to be the number of feature in the dataset.要解决此问题,您可以将 model 的输入形状更改为数据集中的特征数。

model.add(tf.keras.layers.Dense(256, input_shape=(x_train.shape[1],), activation='sigmoid'))

The number of rows in the.csv files will be the number of samples in your dataset. .csv 文件中的行数将是数据集中的样本数。 Since you're not using batches, the model will evaluate the whole dataset at once every epoch由于您不使用批处理,因此 model 将在每个时期一次评估整个数据集

I tried this solution as above:我尝试了上面的解决方案:

model.add(tf.keras.layers.Dense(256,input_shape(x_train.shape[1],), activation='sigmoid'))

but same problem occurred so i tried to define the inpute_shape of model separately as below code and it works hope this help you:但同样的问题发生了,所以我尝试按照下面的代码分别定义 model 的 inpute_shape 并且它有效希望这对你有帮助:

model.add(tf.keras.Input(shape=(x_train.shape[1],))) model.add(tf.keras.layers.Dense(128, activation='sigmoid')) model.add(tf.keras.layers.Dense(256, activation='sigmoid')) model.add(tf.keras.layers.Dense(1, activation='sigmoid'))

Args input_shape Shape tuple (not including the batch axis), or TensorShape instance (not including the batch axis). Args input_shape 形状元组(不包括批轴),或 TensorShape 实例(不包括批轴)。 the input shape does include batch axis as per documentation of keras so try giving input_shape=(30,) instead of input_shape=(455,30)根据 keras 的文档,输入形状确实包括批处理轴,因此请尝试提供 input_shape=(30,) 而不是 input_shape=(455,30)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:“顺序”层的输入 0 与层不兼容:预期形状 =(无,223461,5),找到形状 =(无,5) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 223461, 5), found shape=(None, 5) ValueError: 层“sequential_1”的输入 0 与层不兼容:预期形状=(None, 60, 1),发现形状=(None, 59, 1) - ValueError: Input 0 of layer "sequential_1" is incompatible with the layer: expected shape=(None, 60, 1), found shape=(None, 59, 1) ValueError:层“顺序”的输入0与层不兼容:预期形状=(无,90),发现形状=(无,2,90) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 90), found shape=(None, 2, 90) ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(无,33714,12),找到形状 =(无,12) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 33714, 12), found shape=(None, 12) | ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(None, 28, 28),找到的形状 =(None, 28, 3) - | ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 28, 28), found shape=(None, 28, 3) ValueError:层“顺序”的输入 0 与层不兼容:预期形状=(无,32,32,3),找到形状=(32,32,3) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 32, 32, 3), found shape=(32, 32, 3) ValueError: 层“sequential_32”的输入 0 与层不兼容:预期形状=(None, 3, 1),发现形状=(32, 0, 1) - ValueError: Input 0 of layer "sequential_32" is incompatible with the layer: expected shape=(None, 3, 1), found shape=(32, 0, 1) Keras LSTM ValueError:层“顺序”的输入 0 与层不兼容:预期形状 =(无,478405,33),找到形状 =(1、33) - Keras LSTM ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 478405, 33), found shape=(1, 33) ValueError:“顺序”层的输入 0 与该层不兼容:预期形状=(无,128,128,3),找到形状=(32,128,3) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 128, 128, 3), found shape=(32, 128, 3) ValueError: 层序的输入 0 与层不兼容:预期 ndim=3,发现 ndim=2。 收到的完整形状:(无,1) - ValueError: Input 0 of layer sequential is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM