-1

I have trained my model using EMNIST byclass dataset by loading .csv files of training and testing data as well as label for digit (0-9) and letter (A-Z, a-z) classification. I got the model evaluation accuracy around 87%. But when I am using the the best saved model weights (.hdf5) using keras load_model(), it gives me weird results, as if no training has been done. But after loading the model if I run the model evaluation still iyt gives me 87% accuracy.

Then what could be the problem while doing prediction of any new image and I am getting wrong prediction ?

Thanks

Deb
  • 11
  • 2
  • Welcome to Stack Overflow! Questions seeking debugging help should include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it within the question itself. Questions without a clear problem statement are not useful to other readers. Please see: [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Gerardo BLANCO Feb 10 '18 at 03:21
  • One more I would like to mention that I am using all the required same pre-processing for EMNIST training/validation data what I used for MNIST data too. And the same code is doing right prediction while using MNIST dataset. But now I am using EMNIST dataset to predict both alphabets & digits (A-Z, a-z, 0-9) since MNIST dataset has only digits. Have anyone used EMNIST dataset for Alphabet & Digit prediction and prediction happened right ? Or still EMNIST dataset is not OK for such prediction. But I am surprised in that case how am I getting evaluation accuracy as 88%. – Deb Feb 10 '18 at 05:54

2 Answers2

1

One more input I would like to pass everyone about my above mentioned issue -

One more I would like to mention that I am using all the required same pre-processing for EMNIST training/validation data what I used for MNIST data too. And the same code is doing right prediction while using MNIST dataset. But now I am using EMNIST dataset to predict both alphabets & digits (A-Z, a-z, 0-9) since MNIST dataset has only digits. Have anyone used EMNIST dataset for Alphabet & Digit prediction and prediction happened right ? Or still EMNIST dataset is not OK for such prediction. But I am surprised in that case how am I getting evaluation accuracy as 88%.

Deb
  • 11
  • 2
0

It seems like EMNIST dataset photos are rotated and mirrored.You should do vise versa before feeding image to your net,and don't forget bit-wise inversion and thresholding.

x1 = cv2.imread('c9.jpg')
x2 = cv2.cvtColor(x1, cv2.COLOR_BGR2GRAY)
ret,x3 = cv2.threshold(x2, 127, 255, cv2.THRESH_BINARY)


#compute a bit-wise inversion so black becomes white and vice versa

x4 = np.invert(x3)

#make it the right size

x5 = cv2.resize(x4, (28, 28))

#rotate and flip

rows,cols = x5.shape
M = cv2.getRotationMatrix2D((cols/2,rows/2),270,1)
dst = cv2.warpAffine(x5,M,(cols,rows))
flip = cv2.flip(dst,1)

#convert to a 4D tensor to feed into our model

x6 = flip.reshape(1,28,28,1)
x7 = x6.astype('float32')
x7 /= 255
out = model.predict(x7)

print(np.argmax(out))