MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / eval

Method eval

tools/engine/trainer.py:536–575  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

534 self.logger.info(best_str)
535
536 def eval(self):
537 self.model.eval()
538 with torch.no_grad():
539 total_frame = 0.0
540 total_time = 0.0
541 pbar = tqdm(
542 total=len(self.valid_dataloader),
543 desc='eval model:',
544 position=0,
545 leave=True,
546 )
547 sum_images = 0
548 for idx, batch in enumerate(self.valid_dataloader):
549 batch_tensor = [t.to(self.device) for t in batch]
550 batch_numpy = [t.numpy() for t in batch]
551 start = time.time()
552 if self.scaler:
553 with torch.cuda.amp.autocast(
554 enabled=self.device.type == 'cuda'):
555 preds = self.model(batch_tensor[0],
556 data=batch_tensor[1:])
557 else:
558 preds = self.model(batch_tensor[0], data=batch_tensor[1:])
559
560 total_time += time.time() - start
561 # Obtain usable results from post-processing methods
562 # Evaluate the results of the current batch
563 post_result = self.post_process_class(preds, batch_numpy)
564 self.eval_class(post_result, batch_numpy)
565
566 pbar.update(1)
567 total_frame += len(batch[0])
568 sum_images += 1
569 # Get final metric,eg. acc or hmean
570 metric = self.eval_class.get_metric()
571
572 pbar.close()
573 self.model.train()
574 metric['fps'] = total_frame / total_time
575 return metric
576
577 def test_dataloader(self):
578 starttime = time.time()

Callers 10

mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
eval_stepMethod · 0.95
_init_torch_modelMethod · 0.45
mainFunction · 0.45
_init_torch_modelMethod · 0.45

Calls 3

updateMethod · 0.45
get_metricMethod · 0.45
trainMethod · 0.45

Tested by

no test coverage detected