Reputation: 1115
I'm trying to make an OCR for Bangla character. I have 168 different classes. For predicting each character my model is
model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3),
activation='relu',
input_shape=(42,28,1)))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))
It performs well in my testing set. I'm trying to predict a single instance but for each different instance it's showing same class output. I read single image as following
from PIL import Image
#location for single image
location='Bangla-Compound-Character-Recognition/data/2/ka.jpg'
#image size = (42x28) grayscale
image=np.array(Image.open(location)).reshape(42,28,1)
image=np.expand_dims(image,axis=0)
single_image_cls=model.predict_classes(image)
print(single_image_cls)
Predicting a single instance of test set shows proper result and test accuracy is 90%
#predicting a single test instance
probablity=model.predict_classes(x_test[100:101])
Upvotes: 1
Views: 52
Reputation: 56347
When testing on new images, you have to apply the same normalization as the training set, normally dividing image pixels by 255:
single_image_cls=model.predict_classes(image / 255)
Upvotes: 1