classify-nums / huggingface /classify_nums.py
jonesmarquelle's picture
Upload 4 files
b7895c0
# -*- coding: utf-8 -*-
"""classify_nums.ipynb
Partially generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1UlXGnv-1ivfoGQp4c0k-xONsC5kUjSNm
"""
# Commented out IPython magic to ensure Python compatibility.
# %pip install huggingface_hub["tensorflow"]
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)
#print(im.shape)
x_image = tf.image.resize(im, (28, 28))
x_image = tf.expand_dims(x_image, 0)
#print(x_image.shape)
out_tensor = model.predict(x_image, verbose=0)
res = tf.math.argmax(out_tensor[0])
res = tf.keras.backend.eval(res)
print("Prediction: ", res)