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