I collected Handwriting number and train model with VGG16 and made model is Sequential
from keras import models
from keras import layers
from keras import optimizers
model = models.Sequential()
model.add(layers.Dense(1024, activation='relu', input_dim=7 * 7 * 512))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(63, activation='softmax'))
model.compile(optimizer= tensorflow.keras.optimizers.RMSprop(learning_rate=2e-4),
loss='categorical_crossentropy',
metrics=['acc'])
I save in name modeldata.h5 and load it.
# load the handwriting OCR model
from keras.models import load_model
args = {}
args["model"] = '/content/drive/MyDrive/project/modeldata.h5'
model = load_model(args["model"] )
This is my model.summary()
Then I want to predict Image of number 8.
from tensorflow.keras.utils import load_img
from google.colab.patches import cv2_imshow
from matplotlib import pyplot as plt
img = '/content/drive/MyDrive/project/Dataset/DATA3/78/78_10.png'
image= cv2.imread(img)
cv2_imshow(image)
plt.imshow(image.reshape(224, 224),cmap='Greys')
pred = model.predict(image.reshape(1, 224, 224, 1))
print("From which the max choice is:", pred.argmax())
please Help me to fix it! I have model but I don't know to predict the numbers. I want resault is my model can predicted this picture.
Here actually there are many problems. The 2 major problems are:
Edit:
Adding solution.
In your case you can do something like this:
image = cv2.imread(img)
image = cv2.resize(image, (224, 224))
image = image[None, ...]
features = vgg_conv.predict(image)
features = np.reshape(features,(1,7*7*512))
result = model.predict(features)