Beispiel #1
0
    def _assert_outputs_for_predict(self, configs):
        model_config = configs['model']

        with tf.Graph().as_default():
            features, _ = inputs.create_eval_input_fn(
                configs['eval_config'], configs['eval_input_config'],
                configs['model'])()
            detection_model_fn = functools.partial(model_builder.build,
                                                   model_config=model_config,
                                                   is_training=False)

            hparams = model_hparams.create_hparams(
                hparams_overrides='load_pretrained=false')

            model_fn = model.create_model_fn(detection_model_fn, configs,
                                             hparams)
            estimator_spec = model_fn(features, None,
                                      tf.estimator.ModeKeys.PREDICT)

            self.assertIsNone(estimator_spec.loss)
            self.assertIsNone(estimator_spec.train_op)
            self.assertIsNotNone(estimator_spec.predictions)
            self.assertIsNotNone(estimator_spec.export_outputs)
            self.assertIn(
                tf.saved_model.signature_constants.PREDICT_METHOD_NAME,
                estimator_spec.export_outputs)
Beispiel #2
0
    def _assert_outputs_for_train_eval(self,
                                       configs,
                                       mode,
                                       class_agnostic=False):
        model_config = configs['model']
        train_config = configs['train_config']
        with tf.Graph().as_default():
            if mode == tf.estimator.ModeKeys.TRAIN:
                features, labels = inputs.create_train_input_fn(
                    configs['train_config'], configs['train_input_config'],
                    configs['model'])()
                batch_size = train_config.batch_size
            else:
                features, labels = inputs.create_eval_input_fn(
                    configs['eval_config'], configs['eval_input_config'],
                    configs['model'])()
                batch_size = 1

            detection_model_fn = functools.partial(model_builder.build,
                                                   model_config=model_config,
                                                   is_training=True)

            hparams = model_hparams.create_hparams(
                hparams_overrides='load_pretrained=false')

            model_fn = model.create_model_fn(detection_model_fn, configs,
                                             hparams)
            estimator_spec = model_fn(features, labels, mode)

            self.assertIsNotNone(estimator_spec.loss)
            self.assertIsNotNone(estimator_spec.predictions)
            if class_agnostic:
                self.assertNotIn('detection_classes',
                                 estimator_spec.predictions)
            else:
                detection_classes = estimator_spec.predictions[
                    'detection_classes']
                self.assertEqual(batch_size,
                                 detection_classes.shape.as_list()[0])
                self.assertEqual(tf.float32, detection_classes.dtype)
            detection_boxes = estimator_spec.predictions['detection_boxes']
            detection_scores = estimator_spec.predictions['detection_scores']
            num_detections = estimator_spec.predictions['num_detections']
            self.assertEqual(batch_size, detection_boxes.shape.as_list()[0])
            self.assertEqual(tf.float32, detection_boxes.dtype)
            self.assertEqual(batch_size, detection_scores.shape.as_list()[0])
            self.assertEqual(tf.float32, detection_scores.dtype)
            self.assertEqual(tf.float32, num_detections.dtype)
            if mode == tf.estimator.ModeKeys.TRAIN:
                self.assertIsNotNone(estimator_spec.train_op)
            return estimator_spec
Beispiel #3
0
  def _assert_outputs_for_train_eval(self, configs, mode, class_agnostic=False):
    model_config = configs['model']
    train_config = configs['train_config']
    with tf.Graph().as_default():
      if mode == tf.estimator.ModeKeys.TRAIN:
        features, labels = inputs.create_train_input_fn(
            configs['train_config'],
            configs['train_input_config'],
            configs['model'])()
        batch_size = train_config.batch_size
      else:
        features, labels = inputs.create_eval_input_fn(
            configs['eval_config'],
            configs['eval_input_config'],
            configs['model'])()
        batch_size = 1

      detection_model_fn = functools.partial(
          model_builder.build, model_config=model_config, is_training=True)

      hparams = model_hparams.create_hparams(
          hparams_overrides='load_pretrained=false')

      model_fn = model.create_model_fn(detection_model_fn, configs, hparams)
      estimator_spec = model_fn(features, labels, mode)

      self.assertIsNotNone(estimator_spec.loss)
      self.assertIsNotNone(estimator_spec.predictions)
      if class_agnostic:
        self.assertNotIn('detection_classes', estimator_spec.predictions)
      else:
        detection_classes = estimator_spec.predictions['detection_classes']
        self.assertEqual(batch_size, detection_classes.shape.as_list()[0])
        self.assertEqual(tf.float32, detection_classes.dtype)
      detection_boxes = estimator_spec.predictions['detection_boxes']
      detection_scores = estimator_spec.predictions['detection_scores']
      num_detections = estimator_spec.predictions['num_detections']
      self.assertEqual(batch_size, detection_boxes.shape.as_list()[0])
      self.assertEqual(tf.float32, detection_boxes.dtype)
      self.assertEqual(batch_size, detection_scores.shape.as_list()[0])
      self.assertEqual(tf.float32, detection_scores.dtype)
      self.assertEqual(tf.float32, num_detections.dtype)
      if mode == tf.estimator.ModeKeys.TRAIN:
        self.assertIsNotNone(estimator_spec.train_op)
      return estimator_spec
Beispiel #4
0
  def _assert_outputs_for_predict(self, configs):
    model_config = configs['model']

    with tf.Graph().as_default():
      features, _ = inputs.create_eval_input_fn(
          configs['eval_config'],
          configs['eval_input_config'],
          configs['model'])()
      detection_model_fn = functools.partial(
          model_builder.build, model_config=model_config, is_training=False)

      hparams = model_hparams.create_hparams(
          hparams_overrides='load_pretrained=false')

      model_fn = model.create_model_fn(detection_model_fn, configs, hparams)
      estimator_spec = model_fn(features, None, tf.estimator.ModeKeys.PREDICT)

      self.assertIsNone(estimator_spec.loss)
      self.assertIsNone(estimator_spec.train_op)
      self.assertIsNotNone(estimator_spec.predictions)
      self.assertIsNotNone(estimator_spec.export_outputs)
      self.assertIn(tf.saved_model.signature_constants.PREDICT_METHOD_NAME,
                    estimator_spec.export_outputs)