momentum_rate = 0.5
learning_rate = 0.1
neurons = 30
def convolutional_neural_network(x, y):
print("Hyper-parameter values:\n")
print('Momentum Rate =',momentum_rate,'\n')
print('learning rate =',learning_rate,'\n')
print('Number of neurons =',neurons,'\n')
model = Sequential()
#model.summary()
model.add(Conv1D(input_shape=(X.shape[1],X.shape[0]),activation='relu',kernel_size = 1,filters = 64))
model.add(Flatten())
model.add(Dense(neurons,activation='relu')) # first hidden layer
model.summary()
model.add(Dense(neurons, activation='relu'))
model.summary()# second hidden layer
model.add(Dense(neurons, activation='relu'))
model.summary()
model.add(Dense(neurons, activation='relu'))
model.summary()
model.add(Dense(10, activation='softmax'))
model.summary()
sgd = optimizers.SGD(lr=learning_rate, decay=1e-6, momentum=momentum_rate, nesterov=True)
model.summary()
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy',tensorflow.keras.metrics.Precision()])
model.summary()
history = model.fit(X, y, validation_split=0.2, epochs=10)
model.summary()
print("\nTraining Data Statistics:\n")
print("CNN Model with Relu Hidden Units and Cross-Entropy Error Function:")
print(convolutional_neural_network(X,y))
The shape of X is (150, 1320) The shape of y is (150,)
Here is the output I am getting:
Model: "sequential_36"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_30 (Conv1D) (None, 1320, 64) 9664
_________________________________________________________________
flatten_21 (Flatten) (None, 84480) 0
_________________________________________________________________
dense_106 (Dense) (None, 30) 2534430
_________________________________________________________________
dense_107 (Dense) (None, 30) 930
_________________________________________________________________
dense_108 (Dense) (None, 30) 930
_________________________________________________________________
dense_109 (Dense) (None, 30) 930
_________________________________________________________________
dense_110 (Dense) (None, 10) 310
=================================================================
Total params: 2,547,194
Trainable params: 2,547,194
Non-trainable params: 0
ValueError: Error when checking input: expected conv1d_30_input to have 3 dimensions, but got array with shape (150, 1320)