Пример #1
0
 def _check_inputs(self, features, targets):
     if self._features_info is not None:
         logging.warning('Given features: %s, required signatures: %s.' %
                         (str(features), str(self._features_info)))
         if not tensor_signature.tensors_compatible(features,
                                                    self._features_info):
             raise ValueError(
                 'Features are incompatible with given information. '
                 'Given features: %s, required signatures: %s.' %
                 (str(features), str(self._features_info)))
     else:
         self._features_info = tensor_signature.create_signatures(features)
         logging.warning('Setting feature info to %s',
                         str(self._features_info))
     if targets is not None:
         if self._targets_info is not None:
             logging.warning('Given targets: %s, required signatures: %s.' %
                             (str(targets), str(self._targets_info)))
             if not tensor_signature.tensors_compatible(
                     targets, self._targets_info):
                 raise ValueError(
                     'Targets are incompatible with given information. '
                     'Given targets: %s, required signatures: %s.' %
                     (str(targets), str(self._targets_info)))
         else:
             self._targets_info = tensor_signature.create_signatures(
                 targets)
             logging.warning('Setting targets info to %s',
                             str(self._targets_info))
  def testUnknownShape(self):
    placeholder_unk = array_ops.placeholder(
        name='unk', shape=None, dtype=dtypes.string)
    placeholder_a = array_ops.placeholder(
        name='a', shape=[None], dtype=dtypes.string)
    placeholder_b = array_ops.placeholder(
        name='b', shape=[128, 2], dtype=dtypes.string)
    placeholder_c = array_ops.placeholder(
        name='c', shape=[128, 2], dtype=dtypes.int32)
    unk_signature = tensor_signature.create_signatures(placeholder_unk)
    # Tensors of same dtype match unk shape signature.
    self.assertTrue(
        tensor_signature.tensors_compatible(placeholder_unk, unk_signature))
    self.assertTrue(
        tensor_signature.tensors_compatible(placeholder_a, unk_signature))
    self.assertTrue(
        tensor_signature.tensors_compatible(placeholder_b, unk_signature))
    self.assertFalse(
        tensor_signature.tensors_compatible(placeholder_c, unk_signature))

    string_signature = tensor_signature.create_signatures(placeholder_a)
    int_signature = tensor_signature.create_signatures(placeholder_c)
    # Unk shape Tensor matche signatures same dtype.
    self.assertTrue(
        tensor_signature.tensors_compatible(placeholder_unk, string_signature))
    self.assertFalse(
        tensor_signature.tensors_compatible(placeholder_unk, int_signature))
Пример #3
0
    def testUnknownShape(self):
        placeholder_unk = array_ops.placeholder(name='unk',
                                                shape=None,
                                                dtype=dtypes.string)
        placeholder_a = array_ops.placeholder(name='a',
                                              shape=[None],
                                              dtype=dtypes.string)
        placeholder_b = array_ops.placeholder(name='b',
                                              shape=[128, 2],
                                              dtype=dtypes.string)
        placeholder_c = array_ops.placeholder(name='c',
                                              shape=[128, 2],
                                              dtype=dtypes.int32)
        unk_signature = tensor_signature.create_signatures(placeholder_unk)
        # Tensors of same dtype match unk shape signature.
        self.assertTrue(
            tensor_signature.tensors_compatible(placeholder_unk,
                                                unk_signature))
        self.assertTrue(
            tensor_signature.tensors_compatible(placeholder_a, unk_signature))
        self.assertTrue(
            tensor_signature.tensors_compatible(placeholder_b, unk_signature))
        self.assertFalse(
            tensor_signature.tensors_compatible(placeholder_c, unk_signature))

        string_signature = tensor_signature.create_signatures(placeholder_a)
        int_signature = tensor_signature.create_signatures(placeholder_c)
        # Unk shape Tensor matche signatures same dtype.
        self.assertTrue(
            tensor_signature.tensors_compatible(placeholder_unk,
                                                string_signature))
        self.assertFalse(
            tensor_signature.tensors_compatible(placeholder_unk,
                                                int_signature))
Пример #4
0
 def _check_inputs(self, features, labels):
     if self._features_info is not None:
         logging.debug('Given features: %s, required signatures: %s.',
                       str(features), str(self._features_info))
         if not tensor_signature.tensors_compatible(features,
                                                    self._features_info):
             raise ValueError(
                 'Features are incompatible with given information. '
                 'Given features: %s, required signatures: %s.' %
                 (str(features), str(self._features_info)))
     else:
         self._features_info = tensor_signature.create_signatures(features)
         logging.debug('Setting feature info to %s.',
                       str(self._features_info))
     if labels is not None:
         if self._labels_info is not None:
             logging.debug('Given labels: %s, required signatures: %s.',
                           str(labels), str(self._labels_info))
             if not tensor_signature.tensors_compatible(
                     labels, self._labels_info):
                 raise ValueError(
                     'Labels are incompatible with given information. '
                     'Given labels: %s, required signatures: %s.' %
                     (str(labels), str(self._labels_info)))
         else:
             self._labels_info = tensor_signature.create_signatures(labels)
             logging.debug('Setting labels info to %s',
                           str(self._labels_info))
Пример #5
0
  def testTensorSignatureCompatible(self):
    placeholder_a = tf.placeholder(name='test',
                                   shape=[None, 100],
                                   dtype=tf.int32)
    placeholder_b = tf.placeholder(name='another',
                                   shape=[256, 100],
                                   dtype=tf.int32)
    placeholder_c = tf.placeholder(name='mismatch',
                                   shape=[256, 100],
                                   dtype=tf.float32)
    signatures = tensor_signature.create_signatures(placeholder_a)
    self.assertTrue(tensor_signature.tensors_compatible(placeholder_a,
                                                        signatures))
    self.assertTrue(tensor_signature.tensors_compatible(placeholder_b,
                                                        signatures))
    self.assertFalse(tensor_signature.tensors_compatible(placeholder_c,
                                                         signatures))

    inputs = {'a': placeholder_a}
    signatures = tensor_signature.create_signatures(inputs)
    self.assertTrue(tensor_signature.tensors_compatible(inputs, signatures))
    self.assertFalse(tensor_signature.tensors_compatible(placeholder_a,
                                                         signatures))
    self.assertFalse(tensor_signature.tensors_compatible(placeholder_b,
                                                         signatures))
    self.assertFalse(tensor_signature.tensors_compatible(
        {'b': placeholder_b}, signatures))
    self.assertTrue(tensor_signature.tensors_compatible(
        {'a': placeholder_b,
         'c': placeholder_c}, signatures))
    self.assertFalse(tensor_signature.tensors_compatible(
        {'a': placeholder_c}, signatures))
 def testTensorSignatureExampleParserSingle(self):
   examples = tf.placeholder(name='example', shape=[None], dtype=tf.string)
   placeholder_a = tf.placeholder(name='test',
                                  shape=[None, 100],
                                  dtype=tf.int32)
   signatures = tensor_signature.create_signatures(placeholder_a)
   result = tensor_signature.create_example_parser_from_signatures(
       signatures, examples)
   self.assertTrue(tensor_signature.tensors_compatible(result, signatures))
   new_signatures = tensor_signature.create_signatures(result)
   self.assertTrue(new_signatures.is_compatible_with(signatures))
 def testTensorSignatureExampleParserSingle(self):
   examples = tf.placeholder(name='example', shape=[None], dtype=tf.string)
   placeholder_a = tf.placeholder(name='test',
                                  shape=[None, 100],
                                  dtype=tf.int32)
   signatures = tensor_signature.create_signatures(placeholder_a)
   result = tensor_signature.create_example_parser_from_signatures(
       signatures, examples)
   self.assertTrue(tensor_signature.tensors_compatible(result, signatures))
   new_signatures = tensor_signature.create_signatures(result)
   self.assertTrue(new_signatures.is_compatible_with(signatures))
 def testTensorSignatureExampleParserDict(self):
   examples = array_ops.placeholder(
       name='example', shape=[None], dtype=dtypes.string)
   placeholder_a = array_ops.placeholder(
       name='test', shape=[None, 100], dtype=dtypes.int32)
   placeholder_b = array_ops.placeholder(
       name='bb', shape=[None, 100], dtype=dtypes.float64)
   inputs = {'a': placeholder_a, 'b': placeholder_b}
   signatures = tensor_signature.create_signatures(inputs)
   result = tensor_signature.create_example_parser_from_signatures(signatures,
                                                                   examples)
   self.assertTrue(tensor_signature.tensors_compatible(result, signatures))
   new_signatures = tensor_signature.create_signatures(result)
   self.assertTrue(new_signatures['a'].is_compatible_with(signatures['a']))
   self.assertTrue(new_signatures['b'].is_compatible_with(signatures['b']))
Пример #9
0
 def _check_inputs(self, features, targets):
   if self._features_info is not None:
     if not tensor_signature.tensors_compatible(features, self._features_info):
       raise ValueError('Features are incompatible with given information. '
                        'Given features: %s, required signatures: %s.' %
                        (str(features), str(self._features_info)))
   else:
     self._features_info = tensor_signature.create_signatures(features)
   if self._targets_info is not None:
     if not tensor_signature.tensors_compatible(targets, self._targets_info):
       raise ValueError('Targets are incompatible with given information. '
                        'Given targets: %s, required signatures: %s.' %
                        (str(targets), str(self._targets_info)))
   else:
     self._targets_info = tensor_signature.create_signatures(targets)
 def testTensorSignatureExampleParserDict(self):
   examples = tf.placeholder(name='example', shape=[None], dtype=tf.string)
   placeholder_a = tf.placeholder(name='test',
                                  shape=[None, 100],
                                  dtype=tf.int32)
   placeholder_b = tf.placeholder(name='bb',
                                  shape=[None, 100],
                                  dtype=tf.float64)
   inputs = {'a': placeholder_a, 'b': placeholder_b}
   signatures = tensor_signature.create_signatures(inputs)
   result = tensor_signature.create_example_parser_from_signatures(
       signatures, examples)
   self.assertTrue(tensor_signature.tensors_compatible(result, signatures))
   new_signatures = tensor_signature.create_signatures(result)
   self.assertTrue(new_signatures['a'].is_compatible_with(signatures['a']))
   self.assertTrue(new_signatures['b'].is_compatible_with(signatures['b']))
Пример #11
0
    def testTensorSignatureCompatible(self):
        placeholder_a = array_ops.placeholder(name='test',
                                              shape=[None, 100],
                                              dtype=dtypes.int32)
        placeholder_b = array_ops.placeholder(name='another',
                                              shape=[256, 100],
                                              dtype=dtypes.int32)
        placeholder_c = array_ops.placeholder(name='mismatch',
                                              shape=[256, 100],
                                              dtype=dtypes.float32)
        placeholder_d = array_ops.placeholder(name='mismatch',
                                              shape=[128, 100],
                                              dtype=dtypes.int32)
        signatures = tensor_signature.create_signatures(placeholder_a)
        self.assertTrue(tensor_signature.tensors_compatible(None, None))
        self.assertFalse(tensor_signature.tensors_compatible(None, signatures))
        self.assertFalse(
            tensor_signature.tensors_compatible(placeholder_a, None))
        self.assertTrue(
            tensor_signature.tensors_compatible(placeholder_a, signatures))
        self.assertTrue(
            tensor_signature.tensors_compatible(placeholder_b, signatures))
        self.assertFalse(
            tensor_signature.tensors_compatible(placeholder_c, signatures))
        self.assertTrue(
            tensor_signature.tensors_compatible(placeholder_d, signatures))

        inputs = {'a': placeholder_a}
        signatures = tensor_signature.create_signatures(inputs)
        self.assertTrue(tensor_signature.tensors_compatible(
            inputs, signatures))
        self.assertFalse(
            tensor_signature.tensors_compatible(placeholder_a, signatures))
        self.assertFalse(
            tensor_signature.tensors_compatible(placeholder_b, signatures))
        self.assertFalse(
            tensor_signature.tensors_compatible({'b': placeholder_b},
                                                signatures))
        self.assertTrue(
            tensor_signature.tensors_compatible(
                {
                    'a': placeholder_b,
                    'c': placeholder_c
                }, signatures))
        self.assertFalse(
            tensor_signature.tensors_compatible({'a': placeholder_c},
                                                signatures))
 def testSparseTensorSignaturePlaceholders(self):
   tensor = tf.SparseTensor(values=[1.0, 2.0], indices=[[0, 2], [0, 3]],
                            shape=[5, 5])
   signature = tensor_signature.create_signatures(tensor)
   placeholder = tensor_signature.create_placeholders_from_signatures(
       signature)
   self.assertTrue(isinstance(placeholder, tf.SparseTensor))
   self.assertEqual(placeholder.values.dtype, tensor.values.dtype)
 def testSparseTensorSignaturePlaceholders(self):
   tensor = tf.SparseTensor(values=[1.0, 2.0], indices=[[0, 2], [0, 3]],
                            shape=[5, 5])
   signature = tensor_signature.create_signatures(tensor)
   placeholder = tensor_signature.create_placeholders_from_signatures(
       signature)
   self.assertTrue(isinstance(placeholder, tf.SparseTensor))
   self.assertEqual(placeholder.values.dtype, tensor.values.dtype)
Пример #14
0
  def testTensorSignaturePlaceholders(self):
    placeholder_a = tf.placeholder(name='test',
                                   shape=[None, 100],
                                   dtype=tf.int32)
    signatures = tensor_signature.create_signatures(placeholder_a)
    placeholder_out = tensor_signature.create_placeholders_from_signatures(
        signatures)
    self.assertEqual(placeholder_out.dtype, placeholder_a.dtype)
    self.assertEqual(placeholder_out.get_shape(), placeholder_a.get_shape())
    self.assertTrue(tensor_signature.tensors_compatible(placeholder_out,
                                                        signatures))

    inputs = {'a': placeholder_a}
    signatures = tensor_signature.create_signatures(inputs)
    placeholders_out = tensor_signature.create_placeholders_from_signatures(
        signatures)
    self.assertEqual(placeholders_out['a'].dtype, placeholder_a.dtype)
    self.assertEqual(placeholders_out['a'].get_shape(),
                     placeholder_a.get_shape())
    self.assertTrue(tensor_signature.tensors_compatible(placeholders_out,
                                                        signatures))
  def testTensorSignaturePlaceholders(self):
    placeholder_a = array_ops.placeholder(
        name='test', shape=[None, 100], dtype=dtypes.int32)
    signatures = tensor_signature.create_signatures(placeholder_a)
    placeholder_out = tensor_signature.create_placeholders_from_signatures(
        signatures)
    self.assertEqual(placeholder_out.dtype, placeholder_a.dtype)
    self.assertTrue(placeholder_out.get_shape().is_compatible_with(
        placeholder_a.get_shape()))
    self.assertTrue(
        tensor_signature.tensors_compatible(placeholder_out, signatures))

    inputs = {'a': placeholder_a}
    signatures = tensor_signature.create_signatures(inputs)
    placeholders_out = tensor_signature.create_placeholders_from_signatures(
        signatures)
    self.assertEqual(placeholders_out['a'].dtype, placeholder_a.dtype)
    self.assertTrue(placeholders_out['a'].get_shape().is_compatible_with(
        placeholder_a.get_shape()))
    self.assertTrue(
        tensor_signature.tensors_compatible(placeholders_out, signatures))
Пример #16
0
 def _check_inputs(self, features, targets):
     if self._features_info is not None:
         logging.warning("Given features: %s, required signatures: %s.", str(features), str(self._features_info))
         if not tensor_signature.tensors_compatible(features, self._features_info):
             raise ValueError(
                 "Features are incompatible with given information. "
                 "Given features: %s, required signatures: %s." % (str(features), str(self._features_info))
             )
     else:
         self._features_info = tensor_signature.create_signatures(features)
         logging.warning("Setting feature info to %s", str(self._features_info))
     if targets is not None:
         if self._targets_info is not None:
             logging.warning("Given targets: %s, required signatures: %s.", str(targets), str(self._targets_info))
             if not tensor_signature.tensors_compatible(targets, self._targets_info):
                 raise ValueError(
                     "Targets are incompatible with given information. "
                     "Given targets: %s, required signatures: %s." % (str(targets), str(self._targets_info))
                 )
         else:
             self._targets_info = tensor_signature.create_signatures(targets)
             logging.warning("Setting targets info to %s", str(self._targets_info))
Пример #17
0
 def _check_inputs(self, features, labels):
   if self._features_info is not None:
     logging.debug('Given features: %s, required signatures: %s.',
                   str(features), str(self._features_info))
     if not tensor_signature.tensors_compatible(features, self._features_info):
       raise ValueError('Features are incompatible with given information. '
                        'Given features: %s, required signatures: %s.' %
                        (str(features), str(self._features_info)))
   else:
     self._features_info = tensor_signature.create_signatures(features)
     logging.debug('Setting feature info to %s.', str(self._features_info))
   if labels is not None:
     if self._labels_info is not None:
       logging.debug('Given labels: %s, required signatures: %s.',
                     str(labels), str(self._labels_info))
       if not tensor_signature.tensors_compatible(labels, self._labels_info):
         raise ValueError('Labels are incompatible with given information. '
                          'Given labels: %s, required signatures: %s.' %
                          (str(labels), str(self._labels_info)))
     else:
       self._labels_info = tensor_signature.create_signatures(labels)
       logging.debug('Setting labels info to %s', str(self._labels_info))
 def testSparseTensorCompatible(self):
   t = tf.SparseTensor(
       indices=[[0, 0], [1, 2]], values=[1, 2], dense_shape=[3, 4])
   signatures = tensor_signature.create_signatures(t)
   self.assertTrue(tensor_signature.tensors_compatible(t, signatures))
 def testTensorSignatureNone(self):
   self.assertEqual(None, tensor_signature.create_signatures(None))
Пример #20
0
 def testTensorSignatureNone(self):
     self.assertEqual(None, tensor_signature.create_signatures(None))
Пример #21
0
 def testSparseTensorCompatible(self):
     t = sparse_tensor.SparseTensor(indices=[[0, 0], [1, 2]],
                                    values=[1, 2],
                                    dense_shape=[3, 4])
     signatures = tensor_signature.create_signatures(t)
     self.assertTrue(tensor_signature.tensors_compatible(t, signatures))