Exemple #1
0
    def test_model_variables(self):
        with tf.Graph().as_default():
            feats = tf.random.uniform([1, 512, 512, 3])
            efficientdet_arch_keras.efficientdet('efficientdet-d0')(feats)
            vars1 = [var.name for var in tf.global_variables()]

        with tf.Graph().as_default():
            feats = tf.random.uniform([1, 512, 512, 3])
            legacy_arch.efficientdet(feats, 'efficientdet-d0')
            vars2 = [var.name for var in tf.global_variables()]

        self.assertEqual(vars1, vars2)
Exemple #2
0
 def build_model(self, keras=False):
     tf.compat.v1.reset_default_graph()
     inputs_shape = [1, 512, 512, 3]
     inputs = tf.ones(shape=inputs_shape, name='input', dtype=tf.float32)
     if not keras:
         legacy_arch.efficientdet(inputs,
                                  model_name='efficientdet-d0',
                                  is_training_bn=False,
                                  image_size=512)
     else:
         efficientdet_arch_keras.efficientdet(inputs,
                                              model_name='efficientdet-d0',
                                              is_training_bn=False,
                                              image_size=512)
     return [n.name for n in tf.global_variables()]
    def test_model_variables(self):
        # TODO(tanmingxing): Re-enable this code once pass internal tests.
        feats = tf.ones([1, 512, 512, 3])
        model = efficientdet_arch_keras.efficientdet('efficientdet-d0')
        model(feats)
        vars1 = sorted([var.name for var in model.trainable_variables])
        vars2 = sorted([var.name for var in model.variables])
        with tf.Graph().as_default():
            feats = tf.ones([1, 512, 512, 3])
            model = efficientdet_arch_keras.efficientdet('efficientdet-d0')
            model(feats)
            vars3 = sorted([var.name for var in model.trainable_variables])
            vars4 = sorted([var.name for var in model.variables])
        with tf.Graph().as_default():
            feats = tf.ones([1, 512, 512, 3])
            legacy_arch.efficientdet(feats, 'efficientdet-d0')
            vars5 = sorted([var.name for var in tf.trainable_variables()])
            vars6 = sorted([var.name for var in tf.global_variables()])

        self.assertEqual(vars1, vars3)
        self.assertEqual(vars3, vars5)
        self.assertEqual(vars2, vars4)
        self.assertEqual(vars4, vars6)
Exemple #4
0
 def model_arch(feats, model_name=None, **kwargs):
   """Construct a model arch for keras models."""
   config = hparams_config.get_efficientdet_config(model_name)
   config.override(kwargs)
   model = efficientdet_arch_keras.efficientdet(model_name,
                                                config=config,
                                                feats=feats)
   # convert the list of model outputs to a dictionary with key=level.
   cls_out_list, box_out_list = model.outputs[0:5], model.outputs[5:]
   assert len(cls_out_list) == config.max_level - config.min_level + 1
   assert len(box_out_list) == config.max_level - config.min_level + 1
   cls_outputs, box_outputs = {}, {}
   for i in range(config.min_level, config.max_level + 1):
     cls_outputs[i] = cls_out_list[i - config.min_level]
     box_outputs[i] = box_out_list[i - config.min_level]
   return cls_outputs, box_outputs
Exemple #5
0
 def test_model_variables(self):
     feats = tf.ones([1, 512, 512, 3])
     model = efficientdet_arch_keras.efficientdet('efficientdet-d0')
     model(feats)
     vars1 = [var.name for var in model.trainable_variables]
     vars3 = [var.name for var in model.variables]
     with tf.Graph().as_default():
         feats = tf.ones([1, 512, 512, 3])
         legacy_arch.efficientdet(feats, 'efficientdet-d0')
         vars2 = [var.name for var in tf.trainable_variables()]
         vars4 = [var.name for var in tf.global_variables()]
     vars1.sort()
     vars2.sort()
     self.assertEqual(vars1, vars2)
     vars3.sort()
     vars4.sort()
     self.assertEqual(vars3, vars4)
Exemple #6
0
    def test_model_output(self):
        # TODO(fsx950223): Fix the test case
        inputs_shape = [1, 512, 512, 3]
        with tf.Session(graph=tf.Graph()) as sess:
            feats = tf.ones(inputs_shape)
            tf.random.set_random_seed(SEED)
            _, class_outputs1, box_outputs1 = efficientdet_arch_keras.efficientdet(
                'efficientdet-d0')(feats)
            sess.run(tf.global_variables_initializer())
            class_output1, box_output1 = sess.run([class_outputs1, box_outputs1])
        with tf.Session(graph=tf.Graph()) as sess:
            feats = tf.ones(inputs_shape)
            tf.random.set_random_seed(SEED)
            class_outputs2, box_outputs2 = legacy_arch.efficientdet(
                feats, 'efficientdet-d0')
            sess.run(tf.global_variables_initializer())
            class_output2, box_output2 = sess.run([class_outputs2, box_outputs2])

        for i in range(3, 8):
            self.assertAllEqual(class_output1[i], class_output2[i])
            self.assertAllEqual(box_output1[i], box_output2[i])
    def test_model_output(self):
        inputs_shape = [1, 512, 512, 3]
        config = hparams_config.get_efficientdet_config('efficientdet-d0')
        with tf.Session(graph=tf.Graph()) as sess:
            feats = tf.ones(inputs_shape)
            tf.random.set_random_seed(SEED)
            feats = efficientdet_arch_keras.build_backbone(feats, config)
            feats = efficientdet_arch_keras.build_feature_network(
                feats, config)
            feats = efficientdet_arch_keras.build_class_and_box_outputs(
                feats, config)
            sess.run(tf.global_variables_initializer())
            class_output1, box_output1 = sess.run(feats)
        with tf.Session(graph=tf.Graph()) as sess:
            feats = tf.ones(inputs_shape)
            tf.random.set_random_seed(SEED)
            feats = legacy_arch.efficientdet(feats, config=config)
            sess.run(tf.global_variables_initializer())
            class_output2, box_output2 = sess.run(feats)
        for i in range(3, 8):
            self.assertAllEqual(class_output1[i], class_output2[i])
            self.assertAllEqual(box_output1[i], box_output2[i])

        with tf.Session(graph=tf.Graph()) as sess:
            feats = tf.ones(inputs_shape)
            tf.random.set_random_seed(SEED)
            feats = efficientdet_arch_keras.efficientdet(config=config)(feats)
            sess.run(tf.global_variables_initializer())
            class_list, box_list = sess.run(feats)
            for i in range(config.min_level, config.max_level + 1):
                class_output3[i] = class_list[i - config.min_level]
                box_outputs3[i] = box_list[i - config.min_level]
        for i in range(3, 8):
            # Failing.
            self.assertAllEqual(class_output1[i], class_output3[i])
            self.assertAllEqual(box_output1[i], box_output3[i])