(model, loss, inputs, labels)
| 93 | |
| 94 | # similar to train() but not doing the backprop step |
| 95 | def get_cost(model, loss, inputs, labels): |
| 96 | # set the model to testing mode |
| 97 | # because batch norm has 2 different modes! |
| 98 | model.eval() |
| 99 | |
| 100 | inputs = Variable(inputs, requires_grad=False) |
| 101 | labels = Variable(labels, requires_grad=False) |
| 102 | |
| 103 | # Forward |
| 104 | logits = model.forward(inputs) |
| 105 | output = loss.forward(logits, labels) |
| 106 | |
| 107 | return output.item() |
| 108 | |
| 109 | |
| 110 | # define the prediction procedure |
no test coverage detected