示例#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_tensors keys must be strings"):
      export.ServingInputReceiver(
          features=features,
          receiver_tensors={
              1: array_ops.placeholder(dtypes.string, name="example0")})

    with self.assertRaisesRegexp(
        ValueError, "receiver_tensor example1 must be a Tensor"):
      export.ServingInputReceiver(
          features=features,
          receiver_tensors={"example1": [1]})
示例#2
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)
示例#3
0
    def serving_input_receiver_with_asset_fn():
      features, receiver_tensor = serving_input_receiver_fn()
      filename = ops.convert_to_tensor(vocab_file_name,
                                       dtypes.string,
                                       name='asset_filepath')
      ops.add_to_collection(ops.GraphKeys.ASSET_FILEPATHS, filename)
      features['bogus_filename'] = filename

      return export.ServingInputReceiver(features, receiver_tensor)
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
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": array_ops.placeholder(dtypes.string, name="example0"),
       u"example1": array_ops.placeholder(dtypes.string, name="example1"),
   }
   export.ServingInputReceiver(features, receiver_tensors)
示例#8
0
    def serving_input_receiver_fn():
        """An input function on serialized SequenceExample protos."""
        serialized_sequence_example = array_ops.placeholder(
            dtype=dtypes.string,
            shape=[default_batch_size],
            name="input_sequence_example_tensor")
        receiver_tensors = {"sequence_example": serialized_sequence_example}
        features = parse_from_sequence_example(
            serialized_sequence_example,
            input_size,
            context_feature_spec=context_feature_spec,
            example_feature_spec=example_feature_spec)

        return export_lib.ServingInputReceiver(features, receiver_tensors)
示例#9
0
 def test_receiver_wrong_type(self):
   feature = constant_op.constant(5)
   receiver_tensor = "not a tensor"
   with self.assertRaises(ValueError):
     _ = export.ServingInputReceiver(feature, receiver_tensor)
示例#10
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)
 def test_feature_labeled_tensor(self):
     feature = LabeledTensorMock()
     receiver_tensor = array_ops.placeholder(dtypes.string)
     _ = export.ServingInputReceiver(feature, receiver_tensor)
示例#12
0
 def serving_input_receiver_fn():
     return export.ServingInputReceiver(
         {'test-features': constant_op.constant([[1], [1]])},
         array_ops.placeholder(dtype=dtypes.string))
示例#13
0
 def serving_input_receiver_fn():
   return export.ServingInputReceiver(
       given_features, array_ops.placeholder(dtype=dtypes.string))