I am trying to train ANN model on my sound data set, which has 320 rows and 50 columns, while running this code:
Model= Sequential([ Flatten(),
Dense(16, input_shape=(1,50), activation= 'relu' ) ,
Dense(32, activation= 'relu' ),
Dense(2, activation='softmax' ) ,
])
Model.compile(Adam(lr=0.0001), loss='sparse_categorical_crossentropy', metrics=['accuracy'])
Model.fit(S_T_S, T_L, validation_split=0.1, batch_size=20, epochs=20, shuffle='true', verbose=2)
I am getting error of:
Input 0 is incompatible with layer flatten_15: expected min_ndim=3, found ndim=2,
If the dataset has (N, C) shape, where N is the number of the data points and C is the number of channels for single data point, the input_shape argument of the first layer should only specify the channels.
model= Sequential([
Dense(16, input_shape=(50,), activation= 'relu' ) ,
Dense(32, activation= 'relu' ),
Dense(2, activation='softmax' ) ,
])
model.compile(Adam(lr=0.0001), loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(S_T_S, T_L, validation_split=0.1, batch_size=20, epochs=20, shuffle='true', verbose=2)
If the number of output classes is two then an output layer with one node can work better than using the one with two nodes. In this case, the activation of the output layer should be changed to sigmoid and the loss should be changed to binary cross entropy.
model= Sequential([
Dense(16, input_shape=(50,), activation= 'relu' ) ,
Dense(32, activation= 'relu' ),
Dense(1, activation='sigmoid' ) ,
])
model.compile(Adam(lr=0.0001), loss='sparse_binary_crossentropy', metrics=['accuracy'])