Skip to content

Commit

Permalink
Update flops to use multi-adds and set var_exclude_expr for finetuning.
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxingtan committed Mar 31, 2020
1 parent c470de8 commit 75ba619
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions efficientdet/det_model_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion efficientdet/hparams_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion efficientdet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 75ba619

Please sign in to comment.