MCPcopy Index your code
hub / github.com/Closed11/Unsupervised-Image-Classification / accuracy

Function accuracy

eval_linear.py:160–173  ·  view source on GitHub ↗

Computes the precision@k for the specified values of k

(output, target, topk=(1,))

Source from the content-addressed store, hash-verified

158 scheduler.step()
159
160def accuracy(output, target, topk=(1,)):
161 """ Computes the precision@k for the specified values of k """
162 maxk = max(topk)
163 batch_size = target.size(0)
164
165 _, pred = output.topk(maxk, 1, True, True)
166 pred = pred.t()
167 correct = pred.eq(target.view(1, -1).expand_as(pred))
168
169 res = []
170 for k in topk:
171 correct_k = correct[:k].float().sum()
172 res.append(correct_k.mul_(100.0 / batch_size))
173 return res
174
175def train(train_loader, model, criterion, optimizer, epoch):
176 batch_time = AverageMeter()

Callers 2

trainFunction · 0.85
validateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected