| 46 | self.metric_cls = get_metric(config["metric"]) |
| 47 | |
| 48 | def eval(self): |
| 49 | self.model.eval() |
| 50 | raw_metrics = [] |
| 51 | total_frame = 0.0 |
| 52 | total_time = 0.0 |
| 53 | for i, batch in tqdm( |
| 54 | enumerate(self.validate_loader), |
| 55 | total=len(self.validate_loader), |
| 56 | desc="test model", |
| 57 | ): |
| 58 | with paddle.no_grad(): |
| 59 | start = time.time() |
| 60 | preds = self.model(batch["img"]) |
| 61 | boxes, scores = self.post_process( |
| 62 | batch, preds, is_output_polygon=self.metric_cls.is_output_polygon |
| 63 | ) |
| 64 | total_frame += batch["img"].shape[0] |
| 65 | total_time += time.time() - start |
| 66 | raw_metric = self.metric_cls.validate_measure(batch, (boxes, scores)) |
| 67 | raw_metrics.append(raw_metric) |
| 68 | metrics = self.metric_cls.gather_measure(raw_metrics) |
| 69 | print("FPS:{}".format(total_frame / total_time)) |
| 70 | return { |
| 71 | "recall": metrics["recall"].avg, |
| 72 | "precision": metrics["precision"].avg, |
| 73 | "fmeasure": metrics["fmeasure"].avg, |
| 74 | } |
| 75 | |
| 76 | |
| 77 | def init_args(): |