From 75ba619627959b774fea8caec7b6373ac95e98b5 Mon Sep 17 00:00:00 2001 From: Mingxing Tan Date: Mon, 30 Mar 2020 22:12:43 -0700 Subject: [PATCH] Update flops to use multi-adds and set var_exclude_expr for finetuning. --- efficientdet/det_model_fn.py | 1 + efficientdet/hparams_config.py | 3 ++- efficientdet/utils.py | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/efficientdet/det_model_fn.py b/efficientdet/det_model_fn.py index b25259d62..9d67de6a3 100644 --- a/efficientdet/det_model_fn.py +++ b/efficientdet/det_model_fn.py @@ -565,6 +565,7 @@ def scaffold_fn(): ckpt_scope=ckpt_scope, var_scope=var_scope, var_exclude_expr=params.get('var_exclude_expr', None)) + tf.train.init_from_checkpoint(checkpoint, var_map) return tf.train.Scaffold() diff --git a/efficientdet/hparams_config.py b/efficientdet/hparams_config.py index 256015e1e..9eb54a3bc 100644 --- a/efficientdet/hparams_config.py +++ b/efficientdet/hparams_config.py @@ -188,7 +188,8 @@ def default_detection_configs(): h.lr_decay_method = 'cosine' h.moving_average_decay = 0.9998 h.ckpt_var_scope = None # ckpt variable scope. - h.var_exclude_expr = None # exclude vars when loading pretrained ckpts. + # exclude vars when loading pretrained ckpts. + h.var_exclude_expr = '.*/class-predict/.*' # exclude class weights in default h.backbone_name = 'efficientnet-b1' h.backbone_config = None diff --git a/efficientdet/utils.py b/efficientdet/utils.py index 7bac3c66b..19d30e527 100644 --- a/efficientdet/utils.py +++ b/efficientdet/utils.py @@ -19,8 +19,8 @@ # gtype import from __future__ import print_function -import re import os +import re from absl import logging import numpy as np import tensorflow.compat.v1 as tf @@ -304,6 +304,8 @@ def num_params_flops(readable_format=True): options['output'] = 'none' flops = tf.profiler.profile( tf.get_default_graph(), options=options).total_float_ops + # We use flops to denote multiply-adds, which is counted as 2 ops in tfprof. + flops = flops // 2 if readable_format: nparams = float(nparams) * 1e-6 flops = float(flops) * 1e-9