Fastai
02 / 02

fastai: Model Interpretation, Deployment & Design Philosophy

fastai: Model Interpretation, Deployment & Design Philosophy

Inspecting Predictions

# Displays sample predictions alongside true labels -- more
# informative than a single aggregate accuracy number
learn.show_results()

# Run inference on a single new input
learn.predict('path/to/new_image.jpg')

Error Analysis

interp = ClassificationInterpretation.from_learner(learn)

# Reveals which classes the model tends to confuse with each other
interp.plot_confusion_matrix()

# Surfaces the most confidently-WRONG predictions -- often reveals
# mislabeled training data or genuinely ambiguous edge cases
interp.plot_top_losses(9)

Callbacks

# Hooks into the training loop without modifying fastai's core code --
# stops automatically once validation loss stops improving
learn.fit(
    10,
    cbs=[EarlyStoppingCallback(monitor='valid_loss', patience=2)],
)

Exporting for Deployment

# Bundles trained weights AND the preprocessing pipeline into one file
learn.export('model.pkl')

# On a separate deployment machine -- no need to redefine the
# original DataBlock/DataLoaders setup
learn = load_learner('model.pkl')
prediction = learn.predict(new_image)

Design Philosophy

fastai (from the fast.ai organization, which also produces the 'Practical Deep Learning for Coders' course) bakes research-informed defaults into high-level functions -- letting a newcomer get strong results quickly, while still allowing full customization or dropping down to raw PyTorch as understanding grows. The train/validation split (handled automatically via DataLoaders) is core to honestly evaluating whether a model generalizes, rather than just memorizing training data.

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free