def test_resample_feature_map(self): feat = tf.random.uniform([1, 16, 16, 320]) for apply_bn in [True, False]: for training in [True, False]: for strategy in ['tpu', '']: with self.subTest(apply_bn=apply_bn, training=training, strategy=strategy): tf.random.set_random_seed(SEED) expect_result = legacy_arch.resample_feature_map( feat, name='resample_p0', target_height=8, target_width=8, target_num_channels=64, apply_bn=apply_bn, is_training=training, strategy=strategy) tf.random.set_random_seed(SEED) resample_layer = efficientdet_keras.ResampleFeatureMap( name='resample_p0', feat_level=0, target_num_channels=64, apply_bn=apply_bn, is_training_bn=training, strategy=strategy) all_feats = [tf.ones([1, 8, 8, 64])] actual_result = resample_layer(feat, training, all_feats) self.assertAllCloseAccordingToType( expect_result, actual_result)
def test_resample_var_names(self): with tf.Graph().as_default(): feat = tf.random.uniform([1, 16, 16, 320]) resample_layer = efficientdet_keras.ResampleFeatureMap( name='resample_p0', feat_level=0, target_num_channels=64) all_feats = [tf.ones([1, 8, 8, 64])] resample_layer(feat, True, all_feats) vars1 = sorted([var.name for var in tf.trainable_variables()]) with tf.Graph().as_default(): feat = tf.random.uniform([1, 16, 16, 320]) legacy_arch.resample_feature_map(feat, name='p0', target_height=8, target_width=8, target_num_channels=64) vars2 = sorted([var.name for var in tf.trainable_variables()]) self.assertEqual(vars1, vars2)