Esempio n. 1
0
    def test_serving_input_receiver_receiver_tensors_invalid(self):
        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]),
        }

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

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

        with self.assertRaisesRegexp(
                ValueError, "receiver_tensor example1 must be a Tensor"):
            export.ServingInputReceiver(features=features,
                                        receiver_tensors={"example1": [1]})
Esempio n. 2
0
 def test_multi_feature_single_receiver(self):
     features = {
         "foo": constant_op.constant(5),
         "bar": constant_op.constant(6)
     }
     receiver_tensor = constant_op.constant(["test"])
     _ = export.ServingInputReceiver(features, receiver_tensor)
Esempio n. 3
0
 def test_multi_feature_single_receiver(self):
     features = {
         "foo": constant_op.constant(5),
         "bar": constant_op.constant(6)
     }
     receiver_tensor = array_ops.placeholder(dtypes.string)
     _ = export.ServingInputReceiver(features, receiver_tensor)
Esempio n. 4
0
 def test_multi_feature_multi_receiver(self):
   features = {"foo": constant_op.constant(5),
               "bar": constant_op.constant(6)}
   receiver_tensors = {
       "baz": constant_op.constant(5),
       "qux": constant_op.constant(6)
   }
   _ = export.ServingInputReceiver(features, receiver_tensors)
Esempio n. 5
0
 def test_single_feature_single_receiver(self):
   feature = tf.constant(5)
   receiver_tensor = tf.constant(["test"])
   input_receiver = export.ServingInputReceiver(feature, receiver_tensor)
   # single feature is automatically named
   feature_key, = input_receiver.features.keys()
   self.assertEqual("feature", feature_key)
   # single receiver is automatically named
   receiver_key, = input_receiver.receiver_tensors.keys()
   self.assertEqual("input", receiver_key)
Esempio n. 6
0
  def test_serving_input_receiver_features_invalid(self):
    receiver_tensors = {
        "example0": tf.constant(["test0"], name="example0"),
        u"example1": tf.constant(["test1"], name="example1"),
    }

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

    with self.assertRaisesRegexp(ValueError,
                                 "feature keys must be strings or ints"):
      export.ServingInputReceiver(
          features={42.2: tf.constant([1])}, receiver_tensors=receiver_tensors)

    with self.assertRaisesRegexp(
        ValueError, "feature feature1 must be a Tensor or SparseTensor"):
      export.ServingInputReceiver(
          features={"feature1": [1]}, receiver_tensors=receiver_tensors)
Esempio n. 7
0
 def test_multi_feature_multi_receiver(self):
     features = {
         "foo": constant_op.constant(5),
         "bar": constant_op.constant(6)
     }
     receiver_tensors = {
         "baz": array_ops.placeholder(dtypes.int64),
         "qux": array_ops.placeholder(dtypes.float32)
     }
     _ = export.ServingInputReceiver(features, receiver_tensors)
Esempio n. 8
0
 def test_single_feature_single_receiver(self):
     feature = constant_op.constant(5)
     receiver_tensor = array_ops.placeholder(dtypes.string)
     input_receiver = export.ServingInputReceiver(feature, receiver_tensor)
     # single feature is automatically named
     feature_key, = input_receiver.features.keys()
     self.assertEqual("feature", feature_key)
     # single receiver is automatically named
     receiver_key, = input_receiver.receiver_tensors.keys()
     self.assertEqual("input", receiver_key)
Esempio n. 9
0
    def test_serving_input_receiver_features_invalid(self):
        receiver_tensors = {
            "example0": array_ops.placeholder(dtypes.string, name="example0"),
            u"example1": array_ops.placeholder(dtypes.string, name="example1"),
        }

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

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

        with self.assertRaisesRegexp(
                ValueError,
                "feature feature1 must be a Tensor or SparseTensor"):
            export.ServingInputReceiver(features={"feature1": [1]},
                                        receiver_tensors=receiver_tensors)
Esempio n. 10
0
 def test_serving_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]),
   }
   receiver_tensors = {
       "example0": constant_op.constant(["test0"], name="example0"),
       u"example1": constant_op.constant(["test1"], name="example1"),
   }
   export.ServingInputReceiver(features, receiver_tensors)
Esempio n. 11
0
 def serving_input_receiver_fn():
     return export.ServingInputReceiver(
         {'test-features': constant_op.constant([[1], [1]])},
         array_ops.placeholder(dtype=dtypes.string))
Esempio n. 12
0
 def test_receiver_wrong_type(self):
   feature = tf.constant(5)
   receiver_tensor = "not a tensor"
   with self.assertRaises(ValueError):
     _ = export.ServingInputReceiver(feature, receiver_tensor)
Esempio n. 13
0
 def test_feature_labeled_tensor(self):
   feature = LabeledTensorMock()
   receiver_tensor = tf.constant(["test"])
   _ = export.ServingInputReceiver(feature, receiver_tensor)
Esempio n. 14
0
 def test_feature_wrong_type(self):
     feature = "not a tensor"
     receiver_tensor = constant_op.constant(["test"])
     with self.assertRaises(ValueError):
         _ = export.ServingInputReceiver(feature, receiver_tensor)
Esempio n. 15
0
 def test_feature_labeled_tensor(self):
     feature = LabeledTensorMock()
     receiver_tensor = array_ops.placeholder(dtypes.string)
     _ = export.ServingInputReceiver(feature, receiver_tensor)
Esempio n. 16
0
 def test_feature_wrong_type(self):
     feature = "not a tensor"
     receiver_tensor = array_ops.placeholder(dtypes.string)
     with self.assertRaises(ValueError):
         _ = export.ServingInputReceiver(feature, receiver_tensor)