MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / get_cost

Function get_cost

ann_class2/pytorch_batchnorm.py:95–107  ·  view source on GitHub ↗
(model, loss, inputs, labels)

Source from the content-addressed store, hash-verified

93
94# similar to train() but not doing the backprop step
95def 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

Callers 1

Calls 1

forwardMethod · 0.45

Tested by

no test coverage detected