【问题标题】:ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shapeValueError:层顺序的输入0与层不兼容:输入形状的预期轴-1
【发布时间】:2021-05-25 11:31:43
【问题描述】:

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

----------------------------------------------

import IPython.display as ipd
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import librosa
from tqdm import tqdm
from sklearn.preprocessing import StandardScaler
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import Adam

model = Sequential()

model.add(Dense(186, input_shape=(186,), activation = 'relu'))

model.add(Dense(256, activation = 'relu'))
model.add(Dropout(0.6))

model.add(Dense(128, activation = 'relu'))
model.add(Dropout(0.5))

model.add(Dense(10, activation = 'softmax'))

model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adam')

history = model.fit(X_train, y_train, batch_size=64, epochs=30)

【问题讨论】:

  • 可以上传代码吗?

标签: deep-learning conv-neural-network


【解决方案1】:

X_train 的形状是 (None,180),但您将形状 (None,186) 的输入提供给密集层。 改变

model.add(Dense(186, input_shape=(186,), activation = 'relu'))

到:

model.add(Dense(186, input_shape=(180,), activation = 'relu'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-11
    • 2021-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多