MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / valid

Function valid

examples/pytorch/vit/ViT-quantization/main.py:128–163  ·  view source on GitHub ↗
(args, config, model, test_loader)

Source from the content-addressed store, hash-verified

126
127@torch.no_grad()
128def valid(args, config, model, test_loader):
129 # Validation!
130 eval_losses = AverageMeter()
131 acc1_meter = AverageMeter()
132 acc5_meter = AverageMeter()
133
134 logger.info("***** Running Validation *****")
135 logger.info(" Num steps = %d", len(test_loader))
136 logger.info(" Batch size = %d", args.eval_batch_size)
137
138 model.eval()
139 all_preds, all_label = [], []
140 loss_fct = torch.nn.CrossEntropyLoss()
141 for step, batch in enumerate(test_loader):
142 batch = tuple(t.to(args.device) for t in batch)
143 x, y = batch
144
145 logits, _ = model(x)
146
147 eval_loss = loss_fct(logits, y)
148 acc1, acc5 = accuracy(logits, y, topk=(1, 5))
149
150 eval_losses.update(eval_loss.item(), y.size(0))
151 acc1_meter.update(acc1.item(), y.size(0))
152 acc5_meter.update(acc5.item(), y.size(0))
153
154
155 if step % config.PRINT_FREQ == 0:
156 logger.info(
157 f'Test: [{step}/{len(test_loader)}]\t'
158 f'Loss {eval_losses.val:.4f} ({eval_losses.avg:.4f})\t'
159 f'Acc@1 {acc1_meter.val:.3f} ({acc1_meter.avg:.3f})\t'
160 f'Acc@5 {acc5_meter.val:.3f} ({acc5_meter.avg:.3f})')
161 logger.info(f' * Acc@1 {acc1_meter.avg:.3f} Acc@5 {acc5_meter.avg:.3f}')
162
163 return acc1_meter.avg
164
165def calib(args, config, model):
166 """ Calibrate the model """

Callers 2

calibFunction · 0.70
trainFunction · 0.70

Calls 6

updateMethod · 0.95
AverageMeterClass · 0.70
accuracyFunction · 0.70
infoMethod · 0.45
toMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected