diff --git a/examples/bmn/eval.py b/examples/bmn/eval.py index ca3ef446bdf9335636e0eed4d59c543b59a83c9b..52f4091f7541e40190ffa2c29c653626b6844515 100644 --- a/examples/bmn/eval.py +++ b/examples/bmn/eval.py @@ -97,7 +97,7 @@ def test_bmn(args): eval_dataset = BmnDataset(eval_cfg, 'test') #model - model = bmn(config, args.dynamic, pretrained=args.weights is None) + model = bmn(config, pretrained=args.weights is None) model.prepare( loss_function=BmnLoss(config), metrics=BmnMetric( diff --git a/examples/bmn/predict.py b/examples/bmn/predict.py index 4b332c6df7fe7eb6f941bec4611f0f7b6d670752..45733bc40213528d7398707ef0ec1e3f1b2c48be 100644 --- a/examples/bmn/predict.py +++ b/examples/bmn/predict.py @@ -92,7 +92,7 @@ def infer_bmn(args): #data infer_dataset = BmnDataset(infer_cfg, 'infer') - model = bmn(config, args.dynamic, pretrained=args.weights is None) + model = bmn(config, pretrained=args.weights is None) model.prepare( metrics=BmnMetric( config, mode='infer'), diff --git a/examples/bmn/train.py b/examples/bmn/train.py index a520df805366a7635e6f8e002a9b2061d5d5a8c1..7bb4affdf288f6c51771ebcef47cf9aaabb14b22 100644 --- a/examples/bmn/train.py +++ b/examples/bmn/train.py @@ -136,7 +136,7 @@ def train_bmn(args): val_dataset = BmnDataset(val_cfg, 'valid') # model - model = bmn(config, args.dynamic, pretrained=False) + model = bmn(config, pretrained=False) optim = optimizer(config, parameter_list=model.parameters()) model.prepare( optimizer=optim, diff --git a/hapi/vision/models/bmn_model.py b/hapi/vision/models/bmn_model.py index c0fcb8c677778297f3b83e99c92ed2ba82ab60d0..4f503f9d55ad13875d0a80b674e1a4599155f24e 100644 --- a/hapi/vision/models/bmn_model.py +++ b/hapi/vision/models/bmn_model.py @@ -14,6 +14,7 @@ import paddle.fluid as fluid from paddle.fluid import ParamAttr +from paddle.fluid.framework import in_dygraph_mode import numpy as np import math @@ -131,9 +132,8 @@ class BMN(Model): Args: cfg (AttrDict): configs for BMN model - is_dygraph (bool): whether in dygraph mode, default True. """ - def __init__(self, cfg, is_dygraph=True): + def __init__(self, cfg): super(BMN, self).__init__() #init config @@ -142,7 +142,6 @@ class BMN(Model): self.prop_boundary_ratio = cfg.MODEL.prop_boundary_ratio self.num_sample = cfg.MODEL.num_sample self.num_sample_perbin = cfg.MODEL.num_sample_perbin - self.is_dygraph = is_dygraph self.hidden_dim_1d = 256 self.hidden_dim_2d = 128 @@ -197,7 +196,7 @@ class BMN(Model): sample_mask_array = get_interp1d_mask( self.tscale, self.dscale, self.prop_boundary_ratio, self.num_sample, self.num_sample_perbin) - if self.is_dygraph: + if in_dygraph_mode(): self.sample_mask = fluid.dygraph.base.to_variable( sample_mask_array) else: # static @@ -438,16 +437,15 @@ class BmnLoss(Loss): return loss -def bmn(cfg, is_dygraph=True, pretrained=True): +def bmn(cfg, pretrained=True): """BMN model Args: cfg (AttrDict): configs for BMN model - is_dygraph (bool): whether in dygraph mode, default True. pretrained (bool): If True, returns a model with pre-trained model on COCO, default True """ - model = BMN(cfg, is_dygraph=is_dygraph) + model = BMN(cfg) if pretrained: weight_path = get_weights_path(*(pretrain_infos['bmn'])) assert weight_path.endswith('.pdparams'), \