(self, test=False)
| 1219 | return eval_results |
| 1220 | |
| 1221 | def run_evaluation(self, test=False): |
| 1222 | # when testing make sure user defined a test step |
| 1223 | model = self.get_model() |
| 1224 | model.on_pre_performance_check() |
| 1225 | |
| 1226 | # select dataloaders |
| 1227 | if test: |
| 1228 | dataloaders = self.get_test_dataloaders() |
| 1229 | max_batches = self.num_test_batches |
| 1230 | else: |
| 1231 | # val |
| 1232 | dataloaders = self.get_val_dataloaders() |
| 1233 | max_batches = self.num_val_batches |
| 1234 | |
| 1235 | # init validation or test progress bar |
| 1236 | # main progress bar will already be closed when testing so initial position is free |
| 1237 | position = 2 * self.process_position + (not test) |
| 1238 | desc = 'Testing' if test else 'Validating' |
| 1239 | pbar = tqdm.tqdm(desc=desc, total=max_batches, leave=test, position=position, |
| 1240 | disable=not self.show_progress_bar, dynamic_ncols=True, |
| 1241 | unit='batch', file=sys.stdout) |
| 1242 | setattr(self, f'{"test" if test else "val"}_progress_bar', pbar) |
| 1243 | |
| 1244 | # run evaluation |
| 1245 | eval_results = self.evaluate(self.model, |
| 1246 | dataloaders, |
| 1247 | max_batches, |
| 1248 | test) |
| 1249 | if eval_results is not None: |
| 1250 | _, prog_bar_metrics, log_metrics, callback_metrics, _ = self.process_output( |
| 1251 | eval_results) |
| 1252 | |
| 1253 | # add metrics to prog bar |
| 1254 | self.add_tqdm_metrics(prog_bar_metrics) |
| 1255 | |
| 1256 | # log metrics |
| 1257 | self.log_metrics(log_metrics, {}) |
| 1258 | |
| 1259 | # track metrics for callbacks |
| 1260 | self.callback_metrics.update(callback_metrics) |
| 1261 | |
| 1262 | # hook |
| 1263 | model.on_post_performance_check() |
| 1264 | |
| 1265 | # add model specific metrics |
| 1266 | tqdm_metrics = self.training_tqdm_dict |
| 1267 | if not test: |
| 1268 | self.main_progress_bar.set_postfix(**tqdm_metrics) |
| 1269 | |
| 1270 | # close progress bar |
| 1271 | if test: |
| 1272 | self.test_progress_bar.close() |
| 1273 | else: |
| 1274 | self.val_progress_bar.close() |
| 1275 | |
| 1276 | # model checkpointing |
| 1277 | if self.proc_rank == 0 and self.checkpoint_callback is not None and not test: |
| 1278 | self.checkpoint_callback.on_epoch_end(epoch=self.current_epoch, |
no test coverage detected