def build_backbone(features, config): backbone_name = config.backbone_name is_training_bn = config.is_training_bn if 'efficientnet' in backbone_name: override_params = { 'relu_fn': tf.nn.swish, 'batch_norm': utils.batch_norm_class(is_training_bn), } 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)) _, endpoints = efficientnet_builder.build_model_base( features, backbone_name, training=is_training_bn, override_params=override_params) 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 {2: u2, 3: u3, 4: u4, 5: u5}
def test_efficientnet_b0_base(self): # Creates a base model using the model configuration. images = tf.zeros((1, 224, 224, 3), dtype=tf.float32) _, endpoints = efficientnet_builder.build_model_base( images, model_name='efficientnet-b0', training=False) # reduction_1 to reduction_5 should be in endpoints self.assertEqual(len(endpoints), 5)
def test_efficientnet_b0_base(self): # Creates a base model using the model configuration. images = tf.zeros((1, 224, 224, 3), dtype=tf.float32) _, endpoints = efficientnet_builder.build_model_base( images, model_name='efficientnet-b0', training=True) # reduction_1 to reduction_5 should be in endpoints self.assertIn('reduction_1', endpoints) self.assertIn('reduction_5', endpoints) # reduction_5 should be the last one: no reduction_6. self.assertNotIn('reduction_6', endpoints)
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 = { 'relu_fn': utils.backbone_relu_fn, 'batch_norm': utils.batch_norm_class(is_training_bn), } 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)) _, endpoints = efficientnet_builder.build_model_base( features, backbone_name, training=is_training_bn, override_params=override_params) 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 {2: u2, 3: u3, 4: u4, 5: u5}