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

Function valid

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

Source from the content-addressed store, hash-verified

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