-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
45 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,44 @@ | ||
# Training a Simple MNIST Classifier with DEQ | ||
# Training a Simple MNIST Classifier using Deep Equilibrium Models | ||
|
||
This Tutorial is currently under preparation. Check back soon. | ||
We will train a simple Deep Equilibrium Model on MNIST. First we load a few packages. | ||
|
||
```@example basic_mnist_deq | ||
using DeepEquilibriumNetworks, SciMLSensitivity, Lux, NonlinearSolve, OrdinaryDiffEq, | ||
Statistics, Random, Optimization, OptimizationOptimisers | ||
using LuxCUDA | ||
using MLDatasets: MNIST | ||
using MLDataUtils: LabelEnc, convertlabel, stratifiedobs | ||
CUDA.allowscalar(false) | ||
ENV["DATADEPS_ALWAYS_ACCEPT"] = true | ||
``` | ||
|
||
Setup device functions from Lux. See | ||
[GPU Management](https://lux.csail.mit.edu/dev/manual/gpu_management) for more details. | ||
|
||
```@example basic_mnist_deq | ||
const cdev = cpu_device() | ||
const gdev = gpu_device() | ||
``` | ||
|
||
We can now construct our dataloader. | ||
|
||
```@example basic_mnist_deq | ||
function onehot(labels_raw) | ||
return convertlabel(LabelEnc.OneOfK, labels_raw, LabelEnc.NativeLabels(collect(0:9))) | ||
end | ||
function loadmnist(batchsize) | ||
# Load MNIST | ||
mnist = MNIST(; split=:train) | ||
imgs, labels_raw = mnist.features, mnist.targets | ||
# Process images into (H,W,C,BS) batches | ||
x_train = Float32.(reshape(imgs, size(imgs, 1), size(imgs, 2), 1, size(imgs, 3))) |> | ||
gdev | ||
x_train = batchview(x_train, batchsize) | ||
# Onehot and batch the labels | ||
y_train = onehot(labels_raw) |> gdev | ||
y_train = batchview(y_train, batchsize) | ||
return x_train, y_train | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters