Skip to content

Commit

Permalink
evaluator update
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya1503 committed Jan 23, 2024
1 parent 2469970 commit 43794dc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions object_detection/detectron2_training-kfold.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@
" \n",
" def data_loader_mapper(self, batch):\n",
" return batch\n",
" \n",
"\n",
"\n",
" def run_hooks(self):\n",
" val_loss = self.validation()\n",
Expand All @@ -229,8 +231,9 @@
" self._trainer.has_finished = True\n",
"\n",
" def validation(self):\n",
" val_loader = build_detection_test_loader(self.cfg, self.cfg.DATASETS.TEST[0], evaluators=[evaluator])\n",
" # Define evaluator here\n",
" evaluator = COCOEvaluator(self.cfg.DATASETS.TEST[0], self.cfg, True, output_dir=\"./output/\")\n",
" val_loader = build_detection_test_loader(self.cfg, self.cfg.DATASETS.TEST[0], evaluators=[evaluator])\n",
" val_results = self._trainer.test(self.cfg, self.model, evaluators=[evaluator])[0]\n",
" val_loss = val_results[\"total_loss\"]\n",
" return val_loss\n",
Expand All @@ -256,9 +259,13 @@
" cfg.SOLVER.STEPS = [] # milestones where LR is reduced, in this case there's no decay\n",
" cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 128 # The \"RoIHead batch size\". \n",
" cfg.MODEL.ROI_HEADS.NUM_CLASSES = 80 \n",
" cfg.TEST.EVAL_PERIOD = 500\n",
" cfg.TEST.EVAL_PERIOD = 15000\n",
" os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)\n",
" trainer = Early_stopping(cfg, early_stop_patience=5, model_checkpoint_path=\"model_checkpoint.pth\")\n",
" # Specify evaluators during testing\n",
" evaluator = COCOEvaluator(cfg.DATASETS.TEST[0], cfg, True, output_dir=\"./output/\")\n",
" trainer.resume_or_load(resume=False)\n",
" trainer.test(cfg, trainer.model, evaluators=[evaluator])\n",
" trainer.resume_or_load(resume=False)\n",
" trainer.train();\n",
" return cfg\n"
Expand Down

0 comments on commit 43794dc

Please sign in to comment.