Getting Started with MNIST using JAX, NNX, and Grain
Google for DevelopersDecember 3, 20257 min442 views
29 connectionsยท39 entities in this videoโMNIST Dataset Preparation
- ๐ฅ Download the MNIST dataset from HuggingFace, storing it in parquet format.
- ๐ผ Use the pandas library to read the training and testing data files into dataframes.
- ๐ผ๏ธ Implement a
Datasetclass using grain to handle data loading, extracting image bytes, and converting them into normalized NumPy arrays.
CNN Model Definition with NNX
- ๐๏ธ Define a Convolutional Neural Network (CNN) model using NNX, featuring two convolutional layers, average pooling, ReLU activation, and two linear layers.
- ๐ Instantiate the CNN model and use
nnx.displayto visualize its architecture. - ๐งช Pass a dummy input to the model to verify its structure and output before training.
Optimizer and Metrics Setup
- โ๏ธ Configure the AdamW optimizer from Optx, utilizing the
nnx.paramargument to explicitly target learnable parameters. - ๐ Visualize the optimizer setup using
nnx.display. - ๐ Define training and evaluation step functions, including a cross-entropy loss function and gradient computation.
Training and Evaluation Loop
- ๐ Decorate training and evaluation functions with
nnx.jitfor significant performance improvements. - ๐ Implement the main training loop, iterating through the dataset, calling the
train_stepfunction, and computing metrics at intervals. - ๐ฏ Execute the
eval_stepon the test dataset to record test metrics and reset them.
Model Prediction and Visualization
- ๐ Switch the model to evaluation mode using
model.eval(). - ๐ฎ Define a
predict_stepfunction to obtain predicted labels for test images. - ๐ Plot a grid of test images with their corresponding predicted labels to visually assess model performance.
Knowledge graph39 entities ยท 29 connections
How they connect
An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.
Hover ยท drag to explore
39 entities
Chapters3 moments
Key Moments
Transcript27 segments
Full Transcript
Topics12 themes
Whatโs Discussed
MNISTJAXNNXGrainConvolutional Neural Network (CNN)Machine LearningData LoadingOptimizerCross-Entropy LossJIT CompilationModel EvaluationHuggingFace
Smart Objects39 ยท 29 links
Conceptsยท 18
Productsยท 10
Mediasยท 8
Companiesยท 2
Personยท 1