On hand drawn digit
from PIL import Image
import numpy as np
for num in range(1,10):
im = Image.open(f"/home/steven/ai/MyTestData/{num}.png")
# convert to grayscale because thats what we trained on
gray = im.convert('L')
# convert to 2x2
two_dim_array = []
flattened_pixel_map = list(gray.getdata())
i=0
for j in range(28):
i=0
two_dim_array.append([])
while i < 28:
two_dim_array[-1].append(flattened_pixel_map[j * 28 + i])
i += 1
arr = np.array(two_dim_array)
new = arr[np.newaxis, :, :, np.newaxis]
prediction = model.predict(new)
print(prediction)