Function
loss_batch
(model, loss_func, xb, yb, opt=None)
Source from the content-addressed store, hash-verified
| 631 | |
| 632 | |
| 633 | def loss_batch(model, loss_func, xb, yb, opt=None): |
| 634 | loss = loss_func(model(xb), yb) |
| 635 | |
| 636 | if opt is not None: |
| 637 | loss.backward() |
| 638 | opt.step() |
| 639 | opt.zero_grad() |
| 640 | |
| 641 | return loss.item(), len(xb) |
| 642 | |
| 643 | ############################################################################### |
| 644 | # ``fit`` runs the necessary operations to train our model and compute the |
Tested by
no test coverage detected