class_docstr: `Callback` that returns all predictions and targets, optionally `with_input` or `with_loss`
class_docstr_tok: ["`","Callback","`","that","returns","all","predictions","and","targets",",","optionally","`","with_input","`","or","`","with_loss","`"]
docstr: Save predictions, targets and potentially losses
docstr_tok: ["Save","predictions",",","targets","and","potentially","losses"]
code: def after_batch(self):
      "Save predictions, targets and potentially losses"
      if not hasattr(self, "pred"):
          return
      preds, targs = self.learn.to_detach(
          self.pred
      ), self.learn.to_detach(self.yb)
      if self.with_preds:
          self.preds.append(preds)
      if self.with_targs:
          self.targets.append(targs)
      if self.save_preds is not None:
          torch.save(
              preds,
              self.save_preds / str(self.iter),
              pickle_protocol=self.pickle_protocol,
          )
      if self.save_targs is not None:
          torch.save(
              targs[0],
              self.save_targs / str(self.iter),
              pickle_protocol=self.pickle_protocol,
          )
      if self.with_loss:
          bs = find_bs(self.yb)
          loss = (
              self.loss
              if self.loss.numel() == bs
              else self.loss.view(bs, -1).mean(1)
          )
          self.losses.append(self.learn.to_detach(loss))
  
imports: from __future__ import annotations
  from ..data.all import *
  from ..optimizer import *
  from ..losses import BaseLoss
label_desc: Use image node_id 4 for calling the GatherPredsCallback obj's underlying member method code with example usage: obj.after_batch() without return types