(self)
| 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() |
no test coverage detected