Commit 8380cfa7 authored by Yuxin Wu's avatar Yuxin Wu

[FasterRCNN] write evaluation to monitors

parent 230efcc1
...@@ -129,6 +129,7 @@ def eval_on_dataflow(df, detect_func): ...@@ -129,6 +129,7 @@ def eval_on_dataflow(df, detect_func):
# https://github.com/pdollar/coco/blob/master/PythonAPI/pycocoEvalDemo.ipynb # https://github.com/pdollar/coco/blob/master/PythonAPI/pycocoEvalDemo.ipynb
def print_evaluation_scores(json_file): def print_evaluation_scores(json_file):
ret = {}
assert config.BASEDIR and os.path.isdir(config.BASEDIR) assert config.BASEDIR and os.path.isdir(config.BASEDIR)
annofile = os.path.join( annofile = os.path.join(
config.BASEDIR, 'annotations', config.BASEDIR, 'annotations',
...@@ -139,9 +140,12 @@ def print_evaluation_scores(json_file): ...@@ -139,9 +140,12 @@ def print_evaluation_scores(json_file):
cocoEval.evaluate() cocoEval.evaluate()
cocoEval.accumulate() cocoEval.accumulate()
cocoEval.summarize() cocoEval.summarize()
ret['mAP(bbox)'] = cocoEval.stats[0]
if config.MODE_MASK: if config.MODE_MASK:
cocoEval = COCOeval(coco, cocoDt, 'segm') cocoEval = COCOeval(coco, cocoDt, 'segm')
cocoEval.evaluate() cocoEval.evaluate()
cocoEval.accumulate() cocoEval.accumulate()
cocoEval.summarize() cocoEval.summarize()
ret['mAP(segm)'] = cocoEval.stats[0]
return ret
...@@ -8,7 +8,6 @@ import cv2 ...@@ -8,7 +8,6 @@ import cv2
import shutil import shutil
import itertools import itertools
import tqdm import tqdm
import math
import numpy as np import numpy as np
import json import json
import tensorflow as tf import tensorflow as tf
...@@ -313,7 +312,9 @@ class EvalCallback(Callback): ...@@ -313,7 +312,9 @@ class EvalCallback(Callback):
logger.get_logger_dir(), 'outputs{}.json'.format(self.global_step)) logger.get_logger_dir(), 'outputs{}.json'.format(self.global_step))
with open(output_file, 'w') as f: with open(output_file, 'w') as f:
json.dump(all_results, f) json.dump(all_results, f)
print_evaluation_scores(output_file) scores = print_evaluation_scores(output_file)
for k, v in scores.items():
self.trainer.monitors.put_scalar(k, v)
def _trigger_epoch(self): def _trigger_epoch(self):
if self.epoch_num in self.epochs_to_eval: if self.epoch_num in self.epochs_to_eval:
...@@ -359,8 +360,8 @@ if __name__ == '__main__': ...@@ -359,8 +360,8 @@ if __name__ == '__main__':
else: else:
logger.set_logger_dir(args.logdir) logger.set_logger_dir(args.logdir)
print_config() print_config()
stepnum = 300 stepnum = 500
warmup_epoch = max(math.ceil(500.0 / stepnum), 5) warmup_epoch = 3
factor = get_batch_factor() factor = get_batch_factor()
cfg = TrainConfig( cfg = TrainConfig(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment