Color-Classification-CNN icon indicating copy to clipboard operation
Color-Classification-CNN copied to clipboard

Model Training Completed: How to calculate model outputs correctly

Open abhirajasp opened this issue 4 years ago • 0 comments

Validation accuracy reached over 95% by epoch 5 during training. However, I'm only able to reach 54% while inferencing. Please find the code I use for getting model output below -

input = tf.keras.preprocessing.image.load_img("test/3.jpg", target_size=(224,224)) input_arr = keras.preprocessing.image.img_to_array(input) input_arr = np.array([input_arr]) #input_arr = input_arr.astype('float32') #input_arr /= 255 t = time.time() output = model.predict(input_arr) y_class = output.argmax(axis=-1) print("time taken = ", (time.time()-t)*1000) print(output) print(y_class)

If I don't rescale the image to [0,1], I get an accuracy of 38%. Also, after if I print output - it is always similar to the following - [[0. 0. 0. 0. 0. 0. 0. 1. 0.]] Which means probability for whatever class is 1, and for rest all classes is 0.

abhirajasp avatar Jun 19 '20 15:06 abhirajasp