I keep getting a few NaN outputs from my neural network using Keras. I only get about one NaN per 10,000 results. Originally I had a relu activation layer feeding into the final softmax layer. This produced more NaN results. I changed the activation function for the last two dense layers in the constitutional network from relu to sigmoid. This made the problem better but I still get NaN. Any advice for how I can completely eliminate Nan?
model = Sequential()
model.add(InputLayer((1, IMG_H, IMG_W)))
model.add(Convolution2D(32, 3, 3, activation = 'relu'))
model.add(Convolution2D(32, 3, 3, activation = 'relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Dropout(0.3))
model.add(Convolution2D(64, 3, 3, activation = 'relu'))
model.add(Convolution2D(64, 3, 3, activation = 'relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Dropout(0.3))
model.add(Flatten())
model.add(Dense(256, activation = 'sigmoid'))
model.add(Dropout(0.3))
model.add(Dense(64, activation = 'sigmoid'))
model.add(Dropout(0.3))
model.add(Dense(categories, activation = 'softmax'))