MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / train

Method train

samples/python/network_api_pytorch_mnist/model.py:85–104  ·  view source on GitHub ↗
(epoch)

Source from the content-addressed store, hash-verified

83 def learn(self, num_epochs=2):
84 # Train the network for a single epoch
85 def train(epoch):
86 self.network.train()
87 optimizer = optim.SGD(self.network.parameters(), lr=self.learning_rate, momentum=self.sgd_momentum)
88 for batch, (data, target) in enumerate(self.train_loader):
89 data, target = Variable(data), Variable(target)
90 optimizer.zero_grad()
91 output = self.network(data)
92 loss = F.nll_loss(output, target)
93 loss.backward()
94 optimizer.step()
95 if batch % self.log_interval == 0:
96 print(
97 "Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}".format(
98 epoch,
99 batch * len(data),
100 len(self.train_loader.dataset),
101 100.0 * batch / len(self.train_loader),
102 loss.data.item(),
103 )
104 )
105
106 # Test the network
107 def test(epoch):

Callers 3

trainFunction · 0.80
evaluatingFunction · 0.80
mainFunction · 0.80

Calls 4

VariableClass · 0.85
printFunction · 0.85
backwardMethod · 0.45
stepMethod · 0.45

Tested by

no test coverage detected