Example #1
0
    def cifar10_model_fn_helper(self, mode, version, multi_gpu=False):
        input_fn = cifar10_main.get_synth_input_fn()
        dataset = input_fn(True, '', _BATCH_SIZE)
        iterator = dataset.make_one_shot_iterator()
        features, labels = iterator.get_next()
        spec = cifar10_main.cifar10_model_fn(
            features, labels, mode, {
                'resnet_size': 32,
                'data_format': 'channels_last',
                'batch_size': _BATCH_SIZE,
                'version': version,
                'multi_gpu': multi_gpu
            })

        predictions = spec.predictions
        self.assertAllEqual(predictions['probabilities'].shape,
                            (_BATCH_SIZE, 10))
        self.assertEqual(predictions['probabilities'].dtype, tf.float32)
        self.assertAllEqual(predictions['classes'].shape, (_BATCH_SIZE, ))
        self.assertEqual(predictions['classes'].dtype, tf.int64)

        if mode != tf.estimator.ModeKeys.PREDICT:
            loss = spec.loss
            self.assertAllEqual(loss.shape, ())
            self.assertEqual(loss.dtype, tf.float32)

        if mode == tf.estimator.ModeKeys.EVAL:
            eval_metric_ops = spec.eval_metric_ops
            self.assertAllEqual(eval_metric_ops['accuracy'][0].shape, ())
            self.assertAllEqual(eval_metric_ops['accuracy'][1].shape, ())
            self.assertEqual(eval_metric_ops['accuracy'][0].dtype, tf.float32)
            self.assertEqual(eval_metric_ops['accuracy'][1].dtype, tf.float32)
    def cifar10_model_fn_helper(self, mode, resnet_version, dtype):
        input_fn = cifar10_main.get_synth_input_fn(dtype)
        dataset = input_fn(True, '', _BATCH_SIZE)
        iterator = dataset.make_initializable_iterator()
        features, labels = iterator.get_next()
        spec = cifar10_main.cifar10_model_fn(
            features, labels, mode, {
                'dtype': dtype,
                'resnet_size': 32,
                'data_format': 'channels_last',
                'batch_size': _BATCH_SIZE,
                'resnet_version': resnet_version,
                'loss_scale': 128 if dtype == tf.float16 else 1,
                'fine_tune': False,
            })

        predictions = spec.predictions
        self.assertAllEqual(predictions['probabilities'].shape,
                            (_BATCH_SIZE, 10))
        self.assertEqual(predictions['probabilities'].dtype, tf.float32)
        self.assertAllEqual(predictions['classes'].shape, (_BATCH_SIZE, ))
        self.assertEqual(predictions['classes'].dtype, tf.int64)

        if mode != tf.estimator.ModeKeys.PREDICT:
            loss = spec.loss
            self.assertAllEqual(loss.shape, ())
            self.assertEqual(loss.dtype, tf.float32)

        if mode == tf.estimator.ModeKeys.EVAL:
            eval_metric_ops = spec.eval_metric_ops
            self.assertAllEqual(eval_metric_ops['accuracy'][0].shape, ())
            self.assertAllEqual(eval_metric_ops['accuracy'][1].shape, ())
            self.assertEqual(eval_metric_ops['accuracy'][0].dtype, tf.float32)
            self.assertEqual(eval_metric_ops['accuracy'][1].dtype, tf.float32)
Example #3
0
  def cifar10_model_fn_helper(self, mode, resnet_version, dtype):
    input_fn = cifar10_main.get_synth_input_fn(dtype)
    dataset = input_fn(True, '', _BATCH_SIZE)
    iterator = tf.compat.v1.data.make_initializable_iterator(dataset)
    features, labels = iterator.get_next()
    spec = cifar10_main.cifar10_model_fn(
        features, labels, mode, {
            'dtype': dtype,
            'resnet_size': 32,
            'data_format': 'channels_last',
            'batch_size': _BATCH_SIZE,
            'resnet_version': resnet_version,
            'loss_scale': 128 if dtype == tf.float16 else 1,
            'fine_tune': False,
        })

    predictions = spec.predictions
    self.assertAllEqual(predictions['probabilities'].shape,
                        (_BATCH_SIZE, 10))
    self.assertEqual(predictions['probabilities'].dtype, tf.float32)
    self.assertAllEqual(predictions['classes'].shape, (_BATCH_SIZE,))
    self.assertEqual(predictions['classes'].dtype, tf.int64)

    if mode != tf.estimator.ModeKeys.PREDICT:
      loss = spec.loss
      self.assertAllEqual(loss.shape, ())
      self.assertEqual(loss.dtype, tf.float32)

    if mode == tf.estimator.ModeKeys.EVAL:
      eval_metric_ops = spec.eval_metric_ops
      self.assertAllEqual(eval_metric_ops['accuracy'][0].shape, ())
      self.assertAllEqual(eval_metric_ops['accuracy'][1].shape, ())
      self.assertEqual(eval_metric_ops['accuracy'][0].dtype, tf.float32)
      self.assertEqual(eval_metric_ops['accuracy'][1].dtype, tf.float32)
Example #4
0
  def cifar10_model_fn_helper(self, mode, version, multi_gpu=False):
    input_fn = cifar10_main.get_synth_input_fn()
    dataset = input_fn(True, '', _BATCH_SIZE)
    iterator = dataset.make_one_shot_iterator()
    features, labels = iterator.get_next()
    spec = cifar10_main.cifar10_model_fn(
        features, labels, mode, {
            'resnet_size': 32,
            'data_format': 'channels_last',
            'batch_size': _BATCH_SIZE,
            'version': version,
            'multi_gpu': multi_gpu
        })

    predictions = spec.predictions
    self.assertAllEqual(predictions['probabilities'].shape,
                        (_BATCH_SIZE, 10))
    self.assertEqual(predictions['probabilities'].dtype, tf.float32)
    self.assertAllEqual(predictions['classes'].shape, (_BATCH_SIZE,))
    self.assertEqual(predictions['classes'].dtype, tf.int64)

    if mode != tf.estimator.ModeKeys.PREDICT:
      loss = spec.loss
      self.assertAllEqual(loss.shape, ())
      self.assertEqual(loss.dtype, tf.float32)

    if mode == tf.estimator.ModeKeys.EVAL:
      eval_metric_ops = spec.eval_metric_ops
      self.assertAllEqual(eval_metric_ops['accuracy'][0].shape, ())
      self.assertAllEqual(eval_metric_ops['accuracy'][1].shape, ())
      self.assertEqual(eval_metric_ops['accuracy'][0].dtype, tf.float32)
      self.assertEqual(eval_metric_ops['accuracy'][1].dtype, tf.float32)
Example #5
0
    def _cifar10_model_fn_helper(self, mode, version, dtype, multi_gpu=False):
        with tf.Graph().as_default() as g:
            input_fn = cifar10_main.get_synth_input_fn()
            dataset = input_fn(True, '', _BATCH_SIZE)
            iterator = dataset.make_one_shot_iterator()
            features, labels = iterator.get_next()
            spec = cifar10_main.cifar10_model_fn(
                features, labels, mode, {
                    'dtype': dtype,
                    'resnet_size': 32,
                    'data_format': 'channels_last',
                    'batch_size': _BATCH_SIZE,
                    'version': version,
                    'loss_scale': 128 if dtype == tf.float16 else 1,
                    'multi_gpu': multi_gpu
                })

            predictions = spec.predictions
            self.assertAllEqual(predictions['probabilities'].shape,
                                (_BATCH_SIZE, 10))
            self.assertEqual(predictions['probabilities'].dtype, tf.float32)
            self.assertAllEqual(predictions['classes'].shape, (_BATCH_SIZE, ))
            self.assertEqual(predictions['classes'].dtype, tf.int64)

            if mode != tf.estimator.ModeKeys.PREDICT:
                loss = spec.loss
                self.assertAllEqual(loss.shape, ())
                self.assertEqual(loss.dtype, tf.float32)

            if mode == tf.estimator.ModeKeys.EVAL:
                eval_metric_ops = spec.eval_metric_ops
                self.assertAllEqual(eval_metric_ops['accuracy'][0].shape, ())
                self.assertAllEqual(eval_metric_ops['accuracy'][1].shape, ())
                self.assertEqual(eval_metric_ops['accuracy'][0].dtype,
                                 tf.float32)
                self.assertEqual(eval_metric_ops['accuracy'][1].dtype,
                                 tf.float32)

            for v in tf.trainable_variables():
                self.assertEqual(v.dtype.base_dtype, tf.float32)

            tensors_to_check = ('initial_conv:0', 'block_layer1:0',
                                'block_layer2:0', 'block_layer3:0',
                                'final_reduce_mean:0', 'final_dense:0')

            for tensor_name in tensors_to_check:
                tensor = g.get_tensor_by_name('resnet_model/' + tensor_name)
                self.assertEqual(
                    tensor.dtype, dtype,
                    'Tensor {} has dtype {}, while dtype {} was '
                    'expected'.format(tensor, tensor.dtype, dtype))
  def _cifar10_model_fn_helper(self, mode, version, dtype, multi_gpu=False):
    with tf.Graph().as_default() as g:
      input_fn = cifar10_main.get_synth_input_fn()
      dataset = input_fn(True, '', _BATCH_SIZE)
      iterator = dataset.make_one_shot_iterator()
      features, labels = iterator.get_next()
      spec = cifar10_main.cifar10_model_fn(
          features, labels, mode, {
              'dtype': dtype,
              'resnet_size': 32,
              'data_format': 'channels_last',
              'batch_size': _BATCH_SIZE,
              'version': version,
              'loss_scale': 128 if dtype == tf.float16 else 1,
              'multi_gpu': multi_gpu
          })

      predictions = spec.predictions
      self.assertAllEqual(predictions['probabilities'].shape,
                          (_BATCH_SIZE, 10))
      self.assertEqual(predictions['probabilities'].dtype, tf.float32)
      self.assertAllEqual(predictions['classes'].shape, (_BATCH_SIZE,))
      self.assertEqual(predictions['classes'].dtype, tf.int64)

      if mode != tf.estimator.ModeKeys.PREDICT:
        loss = spec.loss
        self.assertAllEqual(loss.shape, ())
        self.assertEqual(loss.dtype, tf.float32)

      if mode == tf.estimator.ModeKeys.EVAL:
        eval_metric_ops = spec.eval_metric_ops
        self.assertAllEqual(eval_metric_ops['accuracy'][0].shape, ())
        self.assertAllEqual(eval_metric_ops['accuracy'][1].shape, ())
        self.assertEqual(eval_metric_ops['accuracy'][0].dtype, tf.float32)
        self.assertEqual(eval_metric_ops['accuracy'][1].dtype, tf.float32)

      for v in tf.trainable_variables():
        self.assertEqual(v.dtype.base_dtype, tf.float32)

      tensors_to_check = ('initial_conv:0', 'block_layer1:0', 'block_layer2:0',
                          'block_layer3:0', 'final_reduce_mean:0',
                          'final_dense:0')

      for tensor_name in tensors_to_check:
        tensor = g.get_tensor_by_name('resnet_model/' + tensor_name)
        self.assertEqual(tensor.dtype, dtype,
                         'Tensor {} has dtype {}, while dtype {} was '
                         'expected'.format(tensor, tensor.dtype,
                                           dtype))
Example #7
0
    def cifar10_model_fn_helper(self, mode, version, multi_gpu=False):
        input_fn = cifar10_main.get_synth_input_fn()
        dataset = input_fn(True, "", _BATCH_SIZE)
        iterator = dataset.make_one_shot_iterator()
        features, labels = iterator.get_next()
        spec = cifar10_main.cifar10_model_fn(
            features,
            labels,
            mode,
            {
                "resnet_size": 32,
                "data_format": "channels_last",
                "batch_size": _BATCH_SIZE,
                "version": version,
                "multi_gpu": multi_gpu,
            },
        )

        predictions = spec.predictions
        self.assertAllEqual(predictions["probabilities"].shape,
                            (_BATCH_SIZE, 10))
        self.assertEqual(predictions["probabilities"].dtype, tf.float32)
        self.assertAllEqual(predictions["classes"].shape, (_BATCH_SIZE, ))
        self.assertEqual(predictions["classes"].dtype, tf.int64)

        if mode != tf.estimator.ModeKeys.PREDICT:
            loss = spec.loss
            self.assertAllEqual(loss.shape, ())
            self.assertEqual(loss.dtype, tf.float32)

        if mode == tf.estimator.ModeKeys.EVAL:
            eval_metric_ops = spec.eval_metric_ops
            self.assertAllEqual(eval_metric_ops["accuracy"][0].shape, ())
            self.assertAllEqual(eval_metric_ops["accuracy"][1].shape, ())
            self.assertEqual(eval_metric_ops["accuracy"][0].dtype, tf.float32)
            self.assertEqual(eval_metric_ops["accuracy"][1].dtype, tf.float32)