I have a very simple image classifier that will eventually be part of a larger system. It takes 6 channels of 39 by 39 pixel data as input and classifies as valid or invalid (1.0 or 0.0).
For reasons I cannot seem to determine the accuracy at the first epoch is the accuracy at all epochs. The model doesn't seem to modify it's weights...
The code for the model is below. imgdata is a numpy array of n * 39,39,6 and knownsso is a numpy array of n 1 or 0 values.
imgtrain,imgtest,nametrain,nametest,knowntrain,knowntest =
train_test_split(imgdata,names,knownsso,test_size=0.3, random_state=42)
imgtrain=tf.cast(np.array(imgtrain),tf.float32)
knowntrain=tf.cast(np.array(knowntrain),tf.float32)
imgtest =tf.cast(np.array(imgtest ),tf.float32)
knowntest =tf.cast(np.array(knowntest ),tf.float32)
inputImg = tf.keras.Input(shape=(39,39,6))
x = tf.keras.layers.Conv2D(32,(3,3), activation='relu')(inputImg)
x = tf.keras.layers.MaxPooling2D((2,2))(x)
x = tf.keras.layers.Flatten()(x)
x = tf.keras.layers.Dense(32, activation=tf.nn.relu)(x)
x = tf.keras.layers.Dense(2, activation=tf.nn.softmax)(x)
model = tf.keras.Model(inputs=inputImg,outputs=x)
model.compile(optimizer = tf.optimizers.Adam(),
loss = 'sparse_categorical_crossentropy',
metrics=['accuracy'])
history = model.fit(imgtrain,knowntrain,epochs=5,validation_data=(imgtest,knowntest))
print(history.history)
I simplified the model a bit to make it a little more friendly to the human eye, but the behavior is consistent with addition and subtraction of additional dropout, dense, maxpool, and conv2d layers. I've tried changing the learning rate too, but the results remain exactly the same.
Every version of this that I have tried to run generates an identical history with accuracy unchanged across epochs:
{'loss': [nan, nan, nan, nan, nan], 'accuracy': [0.75873935, 0.75873935, 0.75873935, 0.75873935, 0.75873935], 'val_loss': [nan, nan, nan, nan, nan], 'val_accuracy': [0.77059567, 0.77059567, 0.77059567, 0.77059567, 0.77059567]}
I can tell that whatever is wrong must be pretty simple, but I am at a loss in terms of what I should be trying for fixing this.