MCPcopy Create free account
hub / github.com/10Ring/LAA-Net / test

Function test

lib/core_function.py:278–310  ·  view source on GitHub ↗
(cfg, model, critetion, epoch, data_loader, logger, writer, devices, valIters, metrics_base='combine')

Source from the content-addressed store, hash-verified

276
277
278def test(cfg, model, critetion, epoch, data_loader, logger, writer, devices, valIters, metrics_base='combine'):
279 calculate_acc = get_acc_mesure_func(metrics_base)
280 total_preds = torch.tensor([]).cuda().to(dtype=torch.float64)
281 total_labels = torch.tensor([]).cuda().to(dtype=torch.float64)
282
283 #Switch to test mode
284 model.eval()
285 test_dataloader = tqdm(data_loader, dynamic_ncols=True)
286 with torch.no_grad():
287 for b, (inputs, labels, vid_ids) in enumerate(test_dataloader):
288 inputs = inputs.to(dtype=torch.float64).cuda()
289 labels = labels.to(dtype=torch.float64).cuda()
290
291 outputs = model(inputs)
292 # Applying Flip test
293 if isinstance(outputs, list):
294 outputs = outputs[0]
295
296 #In case outputs contain a dict key
297 if isinstance(outputs, dict):
298 hm_outputs = outputs['hm']
299 cls_outputs = outputs['cls']
300
301 total_preds = torch.cat((total_preds, cls_outputs), 0)
302 total_labels = torch.cat((total_labels, labels), 0)
303
304 acc_ = calculate_acc(total_preds, targets=None, labels=total_labels, threshold=cfg.TEST.threshold)
305 auc_, ap_, ar_, mf1_ = bin_calculate_auc_ap_ar(total_preds, total_labels, metrics_base=metrics_base)
306
307 logger.info(f'Current ACC, AUC, AP, AR, mF1 for {cfg.DATASET.DATA.TEST.FAKETYPE} --- {cfg.DATASET.DATA.TEST.LABEL_FOLDER} -- \
308 {acc_*100} -- {auc_*100} -- {ap_*100} -- {ar_*100} -- {mf1_*100}')
309
310 return acc_, auc_, ap_, ar_

Callers

nothing calls this directly

Calls 2

get_acc_mesure_funcFunction · 0.90
bin_calculate_auc_ap_arFunction · 0.90

Tested by

no test coverage detected