import imageio
import glob
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.image as mpimg
import numpy as np
from keras.models import load_model
from matplotlib import pyplot as plt
import datetime as t
from skimage.color import rgb2gray
import cv2
import os
import glob
img_dir = ('.') # Enter Directory of all images
data_path = os.path.join(img_dir,'*g')
files = glob.glob(data_path)
def rgb2gray(rgb):
return np.dot(rgb[...,:3], [0.2989, 0.5870, 0.1140])
images = []
for f1 in files:
img = cv2.imread(f1)
images.append(img)
images2 = np.expand_dims(img,axis=0)
images2 = np.expand_dims(images2,axis=3)
#images2 = np.array(img)
gray = rgb2gray(images2)
gray = gray.reshape(1,img_rows, img_cols,1)
gray /= 255
gray = np.dot(images2[...,:3], [0.299, 0.587, 0.114])
plt.imshow(img, cmap = plt.get_cmap('gray'))
plt.show()
model = load_model("first_test")
# predict digit
prediction = model.predict(gray)
print(prediction.argmax())