ylecun/mnist
Viewer • Updated • 70k • 78.9k • 239
How to use lane99/resnet_mnist_digits with Keras:
# Available backend options are: "jax", "torch", "tensorflow".
import os
os.environ["KERAS_BACKEND"] = "jax"
import keras
model = keras.saving.load_model("hf://lane99/resnet_mnist_digits")
This model is is a Residual Neural Network (ResNet) for classifying handwritten digits in the MNIST dataset. This model has 27.5 M parameters and achieves 99.45% accuracy on the MNIST test dataset (i.e., on digits not seen during training).
This model takes as an input a 28x28 array of MNIST digits with values normalized to [0, 1]. The model was trained using Keras on an Nvidia Ampere A100.
Use the code below to get started with the model.
from tensorflow.keras import models
from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical
from keras.utils.data_utils import get_file
# load the MNIST dataset test images and labels
(_, _), (test_images, test_labels) = mnist.load_data()
# normalize the images
test_images = test_images.astype('float32') / 255
# create one-hot labels
test_labels_onehot = to_categorical(test_labels)
# download the model
model_path = get_file('/path/to/resnet_mnist_digits.hdf5', 'https://huggingface.co/lane99/resnet_mnist_digits/resolve/main/resnet_mnist_digits.hdf5')
# import the model
resnet = models.load_model(model_path)
# evaluate the model
evaluation_conv = resnet.evaluate(test_images, test_labels_onehot)
print("Accuracy: ", str(evaluation_conv[1]))
This model was trained on the 60,000 entries in the MNIST training dataset.
This model was trained with a 0.1 validation split for 15 epochs using a batch size of 128.