简体   繁体   English

ValueError: ...与图层不兼容:输入形状的预期轴 -1 的值为 20,但接收到的输入形状为 (None, 20, 637)

[英]ValueError: ...incompatible with the layer: expected axis -1 of input shape to have value 20 but received input with shape (None, 20, 637)

I hit with the error message on my model;我在模型上遇到错误消息; 'ValueError: Input 0 of layer sequential_5 is incompatible with the layer: expected axis -1 of input shape to have value 20 but received input with shape (None, 20, 637)' 'ValueError: 层序 5 的输入 0 与层不兼容:输入形状的预期轴 -1 具有值 20,但接收到的输入形状为 (None, 20, 637)'

Im not sure how to fix this.我不知道如何解决这个问题。 Code as below;代码如下;

print(str(audio_train.shape)+''+str(y_train.shape)+''+str(audio_valid.shape))

(700, 20, 637) (700, 2) (236, 20, 637) (700, 20, 637) (700, 2) (236, 20, 637)

model=Sequential()
###first layer
model.add(Dense(100,input_shape=(20,)))
model.add(Activation('relu'))
model.add(Dropout(0.3))
###second layer
model.add(Dense(200))
model.add(Activation('relu'))
model.add(Dropout(0.3))
###third layer
model.add(Dense(100))
model.add(Activation('relu'))
model.add(Dropout(0.3))
###final layer
model.add(Dense(2))
model.add(Activation('softmax'))
model.summary()

adam = tf.keras.optimizers.Adam(learning_rate=0.0001)
model.compile(optimizer = adam, loss = 'categorical_crossentropy', metrics = ['accuracy'])
#fitting the model
Au_model = model.fit(audio_train, y_train, batch_size = 32, epochs = 10, validation_data = (audio_valid, y_valid), verbose=1)

Error message as below;错误信息如下;

ValueError: in user code:

C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:855 train_function  *
    return step_function(self, iterator)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:845 step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:1285 run
    return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2833 call_for_each_replica
    return self._call_for_each_replica(fn, args, kwargs)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:3608 _call_for_each_replica
    return fn(*args, **kwargs)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:838 run_step  **
    outputs = model.train_step(data)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:795 train_step
    y_pred = self(x, training=True)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py:1013 __call__
    input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
C:\Users\seren\anaconda3\lib\site-packages\tensorflow\python\keras\engine\input_spec.py:251 assert_input_compatibility
    raise ValueError(

ValueError: Input 0 of layer sequential_5 is incompatible with the layer: expected axis -1 of input shape to have value 20 but received input with shape (None, 20, 637)

Appreciate your advice/suggestion.感谢您的意见/建议。

Change改变

model.add(Dense(100,input_shape=(20,)))

To

model.add(Dense(100,input_shape=(20, 637)))

You can also use input_shape=(audio_train.shape[1], audio_train.shape[2]) instead if you wanted to be a bit more programmatic.如果您想更加程序化,也可以使用input_shape=(audio_train.shape[1], audio_train.shape[2])

暂无
暂无

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

相关问题 “ValueError:……与图层不兼容:输入形状的预期轴 -1 的值为 8,但接收到的输入形状为(无、7、169)” - “ValueError: …incompatible with the layer: expected axis -1 of input shape to have value 8 but received input with shape (None, 7, 169)” ValueError:密集层的输入 0 与层不兼容:预期轴 -1 的值为 8,但接收到形状为 [None, 1] 的输入 - ValueError: Input 0 of layer dense is incompatible with the layer: expected axis -1 to have value 8 but received input with shape [None, 1] ValueError: 层序 7 的输入 0 与层不兼容:输入形状的预期轴 -1 具有值 5,但接收到的形状(无,21) - ValueError: Input 0 of layer sequential_7 incompatible with the layer: expected axis -1 of input shape to have value 5 but received shape (None, 21) 层密集的输入 0 与层不兼容:输入形状的预期轴 -1 具有值 3,但收到的输入形状为 (None, 1) - Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 3 but received input with shape (None, 1) ValueError:层顺序的输入 0 与层不兼容:输入形状的预期轴 -1 具有值 3,但接收到的输入具有形状 - ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 3 but received input with shape 层顺序的输入 0 与层不兼容:输入形状的预期轴 -1 具有值 8,但收到的输入具有形状(无,71) - Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 8 but received input with shape (None, 71) 'ValueError:层顺序的输入0与层不兼容:输入形状的预期轴-1具有值3但接收到输入 - 'ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 3 but received input ValueError:层顺序的输入 0 与层不兼容:输入形状的预期轴 -1 具有值 3 [None, 224, 224, 1] - ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 3 [None, 224, 224, 1] 密集层的输入 0 与该层不兼容:输入形状的预期轴 -1 的值为 2700,但接收到的输入形状为 [None, 900] - Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 2700 but received input with shape [None, 900] 层密集_18 的输入 0 与层不兼容:输入形状的预期轴 -1 具有值 3500,但接收到形状为 [None, 7] 的输入 - Input 0 of layer dense_18 is incompatible with the layer: expected axis -1 of input shape to have value 3500 but received input with shape [None, 7]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM