input_shape = (3168, 21, 64)
class Archer:
def __init__(self):
self.model = tf.keras.Sequential(name="Archer", layers=([Conv2D(64, (5, 5), activation='relu',
batch_size=10, input_shape=input_shape), MaxPooling2D((2, 2)),
Conv2D(64, (5, 5),activation='relu'), MaxPooling2D((2, 2)), Flatten(), Dense(100), Dense(10,
activation="softmax")]))
archer = Archer()
archer.model.build(input_shape=input_shape)
archer.model.compile(optimizer="adam",
loss="categorical_crossentropy",
metrics=["accuracy"])
archer.model.save(os.path.join("Models", "Archer.model"))
train_x = np.array(train_x, dtype=float)
这是我每次尝试训练模型时都会遇到的错误:
ValueError: Input 0 of layer Archer is incompatible with the layer: expected ndim=4, found ndim=2.
Full shape received: [None, 20]
这就是我加载数据的方式:
voice = pd.read_csv(os.path.join("data", "voice.csv"))
voice_data = pd.DataFrame(voice)
train_x, train_y, test_x, test_y = train_test_split(voice_data[voice_data.columns[0:20]],
voice_data[voice_data.columns[20]], test_size=0.2, random_state=101)
train_x = np.array(train_x, dtype=float)
无论我做什么,总是会遇到相同的错误。