|
|
|
"""classify_nums.ipynb |
|
|
|
Partially generated by Colaboratory. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/1UlXGnv-1ivfoGQp4c0k-xONsC5kUjSNm |
|
""" |
|
|
|
|
|
|
|
|
|
import tensorflow as tf |
|
from tensorflow import image, expand_dims, math |
|
from tensorflow.keras import backend |
|
|
|
from huggingface_hub import from_pretrained_keras |
|
|
|
model = from_pretrained_keras("jonesmarquelle/classify-nums") |
|
|
|
import tkinter as tk |
|
from tkinter import filedialog |
|
|
|
root = tk.Tk() |
|
root.withdraw() |
|
|
|
print("Open image file...") |
|
filename = filedialog.askopenfilename() |
|
|
|
from PIL import Image |
|
im = Image.open(filename) |
|
|
|
im = tf.image.rgb_to_grayscale(im) |
|
|
|
|
|
x_image = tf.image.resize(im, (28, 28)) |
|
x_image = tf.expand_dims(x_image, 0) |
|
|
|
|
|
out_tensor = model.predict(x_image, verbose=0) |
|
res = tf.math.argmax(out_tensor[0]) |
|
res = tf.keras.backend.eval(res) |
|
print("Prediction: ", res) |