We're going to use the MNIST training code from Ignite's examples directory (as at August 2020), converted to a module.
migrating_igniteis in the
examplessubdirectory of this folder if you checked out the
fastairepo from git, or can be downloaded from here if you’re using an online viewer such as Colab.
from migrating_ignite import * from fastai.vision.all import *
data = DataLoaders(*get_data_loaders(64, 128)).cuda()
opt_func = partial(SGD, momentum=0.5) learn = Learner(data, Net(), loss_func=nn.NLLLoss(), opt_func=opt_func, metrics=accuracy) learn.fit_one_cycle(1, 0.01)
As you can see, migrating from Ignite allowed us to replace 52 lines of code (in
run()) with just 3 lines, and doesn't require you to change any of your existing data pipelines, optimizers, loss functions, models, etc. Once you've made this change, you can then benefit from fastai's rich set of callbacks, transforms, visualizations, and so forth.
Note that fastai is very different from Ignite, in that it is much more than just a training loop (although we're only using the training loop in this example) - it is a complete framework including GPU-accelerated transformations, end-to-end inference, integrated applications for vision, text, tabular, and collaborative filtering, and so forth. You can use any part of the framework on its own, or combine them together, as described in the fastai paper.