我得用角膜训练神经网络。为此,我使用以下形状的一些测试数据:
print(" Training data: {}".format(x_Train.shape))
print(" Training data: {}".format(y_Train.shape))
print(" Test data: {}".format(x_Test.shape))
print(" Test data: {}".format(y_Test.shape))
....
Training data: (128, 90, 561)
Training data: (128,)
Test data: (43, 90, 561)
Test data: (43,)
这种网络架构:
class NeuralNetwork:
@staticmethod
def Build(Width, Depth, Classes, Drop = 0.5):
Model = Sequential()
Model.add(Conv1D(filters = 32,
kernel_size = 5,
input_shape = (Width, Depth)
))
Model.add(Activation("relu"))
Model.add(MaxPooling1D(pool_size = 2,
strides = 2
))
Model.add(Conv1D(filters = 64,
kernel_size = 3
))
Model.add(Activation("relu"))
Model.add(MaxPooling1D(pool_size = 2,
strides = 2
))
Model.add(Flatten())
Model.add(Dense(1024))
Model.add(Dropout(Drop))
Model.add(Dense(Classes))
Model.add(Activation("softmax"))
return Model
但当我试图训练我的模型时,我发现了这个错误:
ValueError: Error when checking target: expected activation_3 to have shape (12,) but got array with shape (1,)
我使用此代码进行培训:
print("[INFO] Train model...")
self.__Model = NeuralNetwork.Build(90, 561, 12)
plot_model(self.__Model, show_layer_names = True, show_shapes = True)
self.__Model.compile(loss = "binary_crossentropy", optimizer = Adam(lr = self.__Learnrate), metrics = ["accuracy"])
self.__Model.fit(x_Train,
y_Train,
validation_data = (x_Test, y_Test),
batch_size = self.__BatchSize,
epochs = self.__Epochs,
verbose = 1
)
我不知道这个错误的来源。我用TensorFlow测试了整个代码,它工作得很好。但是我做了一些错误的重新设计与喀拉斯。
谢谢你的提示或其他什么…