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)
Example #2
0
 def test_resample_feature_map(self):
     feat = tf.random.uniform([1, 16, 16, 320])
     for apply_fn in [True, False]:
         for is_training in [True, False]:
             for use_tpu in [True, False]:
                 with self.subTest(apply_fn=apply_fn,
                                   is_training=is_training,
                                   use_tpu=use_tpu):
                     tf.random.set_random_seed(111111)
                     expect_result = efficientdet_arch.resample_feature_map(
                         feat,
                         name='resample_p0',
                         target_height=8,
                         target_width=8,
                         target_num_channels=64,
                         apply_bn=apply_fn,
                         is_training=is_training,
                         use_tpu=use_tpu)
                     tf.random.set_random_seed(111111)
                     actual_result = efficientdet_arch_keras.ResampleFeatureMap(
                         name='resample_p0',
                         target_height=8,
                         target_width=8,
                         target_num_channels=64,
                         apply_bn=apply_fn,
                         is_training=is_training,
                         use_tpu=use_tpu)(feat)
                     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)
    def test_var_names(self):
        with tf.Graph().as_default():
            feat = tf.random.uniform([1, 16, 16, 320])
            resample_layer = efficientdet_arch_keras.ResampleFeatureMap(
                name='resample_p0',
                target_height=8,
                target_width=8,
                target_num_channels=64)
            resample_layer(feat)
            vars1 = [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 = [var.name for var in tf.trainable_variables()]

        self.assertEqual(vars1, vars2)