def build_backbone(features, config): """Builds backbone model. Args: features: input tensor. config: config for backbone, such as is_training and backbone name. Returns: An arrray of features (starting from min_level) from the output of the backbone model with strides of 8, 16 and 32. Raises: ValueError: if backbone_name is not supported. """ backbone_name = config.backbone_name is_training = config.is_training_bn if 'efficientnet' in backbone_name: override_params = { 'batch_norm': utils.batch_norm_class(is_training, config.strategy), 'relu_fn': functools.partial(utils.activation_fn, act_type=config.act_type), } if 'b0' in backbone_name: override_params['survival_prob'] = 0.0 if config.backbone_config is not None: override_params['blocks_args'] = ( efficientnet_builder.BlockDecoder().encode( config.backbone_config.blocks)) override_params['data_format'] = config.data_format model_builder = backbone_factory.get_model_builder(backbone_name) _, endpoints = model_builder.build_model_base( features, backbone_name, training=is_training, override_params=override_params) all_feats = [ features, endpoints['reduction_1'], endpoints['reduction_2'], endpoints['reduction_3'], endpoints['reduction_4'], endpoints['reduction_5'], ] else: raise ValueError( 'backbone model {} is not supported.'.format(backbone_name)) # Only return features within the expected levels. return all_feats[config.min_level:config.max_level + 1]
def build_backbone(features, config): """Builds backbone model. Args: features: input tensor. config: config for backbone, such as is_training_bn and backbone name. Returns: A dict from levels to the feature maps from the output of the backbone model with strides of 8, 16 and 32. Raises: ValueError: if backbone_name is not supported. """ backbone_name = config.backbone_name is_training_bn = config.is_training_bn if 'efficientnet' in backbone_name: override_params = { 'batch_norm': utils.batch_norm_class(is_training_bn, config.strategy), 'relu_fn': functools.partial(utils.activation_fn, act_type=config.act_type), } if 'b0' in backbone_name: override_params['survival_prob'] = 0.0 if config.backbone_config is not None: override_params['blocks_args'] = ( efficientnet_builder.BlockDecoder().encode( config.backbone_config.blocks)) override_params['data_format'] = config.data_format model_builder = backbone_factory.get_model_builder(backbone_name) _, endpoints = model_builder.build_model_base( features, backbone_name, training=is_training_bn, override_params=override_params) print(endpoints.keys()) print(backbone_name) u1 = endpoints['reduction_1'] u2 = endpoints['reduction_2'] u3 = endpoints['reduction_3'] u4 = endpoints['reduction_4'] u5 = endpoints['reduction_5'] else: raise ValueError( 'backbone model {} is not supported.'.format(backbone_name)) return {0: features, 1: u1, 2: u2, 3: u3, 4: u4, 5: u5}