Predictions callbacks

Open In Colab

Various callbacks to customize get_preds behaviors

  1. /usr/local/lib/python3.8/dist-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at /pytorch/c10/cuda/CUDAFunctions.cpp:100.)
  2. return torch._C._cuda_getDeviceCount() > 0

MCDropoutCallback

Turns on dropout during inference, allowing you to call Learner.get_preds multiple times to approximate your model uncertainty using Monte Carlo Dropout.

class MCDropoutCallback[source]

MCDropoutCallback(after_create=None, before_fit=None, before_epoch=None, before_train=None, before_batch=None, after_pred=None, after_loss=None, before_backward=None, before_step=None, after_cancel_step=None, after_step=None, after_cancel_batch=None, after_batch=None, after_cancel_train=None, after_train=None, before_validate=None, after_cancel_validate=None, after_validate=None, after_cancel_epoch=None, after_epoch=None, after_cancel_fit=None, after_fit=None) :: Callback

Basic class handling tweaks of the training loop by changing a Learner in various events

  1. learn = synth_learner()
  2. # Call get_preds 10 times, then stack the predictions, yielding a tensor with shape [# of samples, batch_size, ...]
  3. dist_preds = []
  4. for i in range(10):
  5. preds, targs = learn.get_preds(cbs=[MCDropoutCallback()])
  6. dist_preds += [preds]
  7. torch.stack(dist_preds).shape
  1. torch.Size([10, 32, 1])

Company logo

©2021 fast.ai. All rights reserved.
Site last generated: Mar 31, 2021