ylecun/mnist
Viewer • Updated • 70k • 82.5k • 239
How to use nivashuggingface/digit-recognition with TF-Keras:
# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy)
# See https://github.com/keras-team/tf-keras for more details.
from huggingface_hub import from_pretrained_keras
model = from_pretrained_keras("nivashuggingface/digit-recognition")
This model is trained to recognize handwritten digits from the MNIST dataset.
The model was trained on the MNIST dataset using a CNN architecture with attention mechanisms.
import tensorflow as tf
import numpy as np
# Load the model
model = tf.saved_model.load("path_to_saved_model")
# Prepare input
image = tf.keras.preprocessing.image.load_img("digit.png", target_size=(28, 28))
image = tf.keras.preprocessing.image.img_to_array(image)
image = image.astype('float32') / 255.0
image = np.expand_dims(image, axis=0)
# Make prediction
predictions = model(image)
predicted_digit = tf.argmax(predictions, axis=1).numpy()[0]