File size: 1,027 Bytes
b7895c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# -*- 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) |