Exemple #1
0
  def test_input_receiver_raw_values(self):
    """Tests that no errors are raised when input is expected."""
    features = {
        "feature0":
            tf.constant([0]),
        u"feature1":
            tf.constant([1]),
        "feature2":
            tf.sparse.SparseTensor(
                indices=[[0, 0]], values=[1], dense_shape=[1, 1]),
        42:  # ints are allowed in the `features` dict
            tf.constant([3]),
    }

    labels = {
        "classes": tf.constant([0] * 100),
        43:  # ints are allowed in the `labels` dict
            tf.constant([3]),
    }

    receiver_tensors = {
        "example0": tf.constant(["test0"], name="example0"),
        u"example1": tf.constant(["test1"], name="example1"),
    }
    rec = export.SupervisedInputReceiver(features["feature2"], labels,
                                         receiver_tensors)
    self.assertIsInstance(rec.features, tf.sparse.SparseTensor)

    rec = export.SupervisedInputReceiver(features, labels["classes"],
                                         receiver_tensors)
    self.assertIsInstance(rec.labels, tf.Tensor)
Exemple #2
0
  def test_input_receiver_receiver_tensors_invalid(self):
    features = {
        "feature0":
            tf.constant([0]),
        u"feature1":
            tf.constant([1]),
        "feature2":
            tf.sparse.SparseTensor(
                indices=[[0, 0]], values=[1], dense_shape=[1, 1]),
    }
    labels = tf.constant([0])

    with self.assertRaisesRegexp(ValueError,
                                 "receiver_tensors must be defined"):
      export.SupervisedInputReceiver(
          features=features, labels=labels, receiver_tensors=None)

    with self.assertRaisesRegexp(ValueError,
                                 "receiver_tensor keys must be strings"):
      export.SupervisedInputReceiver(
          features=features,
          labels=labels,
          receiver_tensors={1: tf.constant(["test"], name="example0")})

    with self.assertRaisesRegexp(ValueError,
                                 "receiver_tensor example1 must be a Tensor"):
      export.SupervisedInputReceiver(
          features=features, labels=labels, receiver_tensors={"example1": [1]})
Exemple #3
0
    def test_input_receiver_raw_values(self):
        """Tests that no errors are raised when input is expected."""
        features = {
            "feature0":
            constant_op.constant([0]),
            u"feature1":
            constant_op.constant([1]),
            "feature2":
            sparse_tensor.SparseTensor(indices=[[0, 0]],
                                       values=[1],
                                       dense_shape=[1, 1]),
        }

        labels = {
            "classes": constant_op.constant([0] * 100),
        }

        receiver_tensors = {
            "example0": array_ops.placeholder(dtypes.string, name="example0"),
            u"example1": array_ops.placeholder(dtypes.string, name="example1"),
        }
        rec = export.SupervisedInputReceiver(features["feature2"], labels,
                                             receiver_tensors)
        self.assertIsInstance(rec.features, sparse_tensor.SparseTensor)

        rec = export.SupervisedInputReceiver(features, labels["classes"],
                                             receiver_tensors)
        self.assertIsInstance(rec.labels, ops.Tensor)
 def test_multi_feature_multi_receiver(self):
   features = {"foo": constant_op.constant(5),
               "bar": constant_op.constant(6)}
   labels = {"value": constant_op.constant(5)}
   receiver_tensors = {"baz": constant_op.constant(5),
                       "qux": constant_op.constant(6)}
   _ = export.SupervisedInputReceiver(features, labels, receiver_tensors)
Exemple #5
0
 def test_multi_feature_single_receiver(self):
     features = {
         "foo": constant_op.constant(5),
         "bar": constant_op.constant(6)
     }
     labels = {"value": constant_op.constant(5)}
     receiver_tensor = constant_op.constant(["test"])
     _ = export.SupervisedInputReceiver(features, labels, receiver_tensor)
Exemple #6
0
 def test_multi_feature_single_receiver(self):
     features = {
         "foo": constant_op.constant(5),
         "bar": constant_op.constant(6)
     }
     labels = {"value": constant_op.constant(5)}
     receiver_tensor = array_ops.placeholder(dtypes.string)
     _ = export.SupervisedInputReceiver(features, labels, receiver_tensor)
Exemple #7
0
  def test_single_feature_single_receiver(self):
    feature = tf.constant(5)
    label = tf.constant(5)
    receiver_tensor = tf.constant(["test"])
    input_receiver = export.SupervisedInputReceiver(feature, label,
                                                    receiver_tensor)

    # single receiver is automatically named
    receiver_key, = input_receiver.receiver_tensors.keys()
    self.assertEqual("input", receiver_key)
Exemple #8
0
    def test_single_feature_single_receiver(self):
        feature = constant_op.constant(5)
        label = constant_op.constant(5)
        receiver_tensor = array_ops.placeholder(dtypes.string)
        input_receiver = export.SupervisedInputReceiver(
            feature, label, receiver_tensor)

        # single receiver is automatically named
        receiver_key, = input_receiver.receiver_tensors.keys()
        self.assertEqual("input", receiver_key)
Exemple #9
0
 def test_multi_feature_multi_receiver(self):
     features = {
         "foo": constant_op.constant(5),
         "bar": constant_op.constant(6)
     }
     labels = {"value": constant_op.constant(5)}
     receiver_tensors = {
         "baz": array_ops.placeholder(dtypes.int64),
         "qux": array_ops.placeholder(dtypes.float32)
     }
     _ = export.SupervisedInputReceiver(features, labels, receiver_tensors)
  def test_input_receiver_constructor(self):
    """Tests that no errors are raised when input is expected."""
    features = {
        "feature0": constant_op.constant([0]),
        u"feature1": constant_op.constant([1]),
        "feature2": sparse_tensor.SparseTensor(
            indices=[[0, 0]], values=[1], dense_shape=[1, 1]),
    }
    labels = {
        "classes": constant_op.constant([0] * 100),
    }

    receiver_tensors = {
        "example0": constant_op.constant(["test0"], name="example0"),
        u"example1": constant_op.constant(["test1"], name="example1"),
    }
    export.SupervisedInputReceiver(features, labels, receiver_tensors)
  def test_input_receiver_features_invalid(self):
    features = constant_op.constant([0] * 100)
    labels = constant_op.constant([0])
    receiver_tensors = {
        "example0": constant_op.constant(["test0"], name="example0"),
        u"example1": constant_op.constant(["test1"], name="example1"),
    }

    with self.assertRaisesRegexp(ValueError, "features must be defined"):
      export.SupervisedInputReceiver(
          features=None,
          labels=labels,
          receiver_tensors=receiver_tensors)

    with self.assertRaisesRegexp(ValueError, "feature keys must be strings"):
      export.SupervisedInputReceiver(
          features={1: constant_op.constant([1])},
          labels=labels,
          receiver_tensors=receiver_tensors)

    with self.assertRaisesRegexp(ValueError, "label keys must be strings"):
      export.SupervisedInputReceiver(
          features=features,
          labels={1: constant_op.constant([1])},
          receiver_tensors=receiver_tensors)

    with self.assertRaisesRegexp(
        ValueError, "feature feature1 must be a Tensor or SparseTensor"):
      export.SupervisedInputReceiver(
          features={"feature1": [1]},
          labels=labels,
          receiver_tensors=receiver_tensors)

    with self.assertRaisesRegexp(
        ValueError, "feature must be a Tensor or SparseTensor"):
      export.SupervisedInputReceiver(
          features=[1],
          labels=labels,
          receiver_tensors=receiver_tensors)

    with self.assertRaisesRegexp(
        ValueError, "label must be a Tensor or SparseTensor"):
      export.SupervisedInputReceiver(
          features=features,
          labels=100,
          receiver_tensors=receiver_tensors)
Exemple #12
0
 def test_feature_labeled_tensor(self):
   feature = LabeledTensorMock()
   label = tf.constant(5)
   receiver_tensor = tf.constant(["test"])
   _ = export.SupervisedInputReceiver(feature, label, receiver_tensor)
Exemple #13
0
 def test_feature_labeled_tensor(self):
     feature = LabeledTensorMock()
     label = constant_op.constant(5)
     receiver_tensor = array_ops.placeholder(dtypes.string)
     _ = export.SupervisedInputReceiver(feature, label, receiver_tensor)