[Tensorflow Serving] Issue : Tensor :0, specified in either feed_devices or fetch_devices was not found in the Graph

680 views
Skip to first unread message

Maxime Poulain

unread,
Apr 6, 2020, 6:19:30 AM4/6/20
to TensorFlow Extended (TFX)
Hello ! 
but you can see my problem in the following text :  

So, I have an issue using tensorflow serving with `SparseTensor` inputs.

I'm using :

 - Tensorflow 2.1.0
 - latest tensorflow-serving docker image

I have the following code to export model for serving :

```
def serving_input_fn():
    """Input function for serving"""
    def _sparse_to_dense_features_tensor(feature_indices, features_values):
        indices = feature_indices.indices
        indices = tf.transpose(indices)
        indices = tf.stack([indices[0], feature_indices.values])
        indices = tf.transpose(indices)
        return tf.sparse.to_dense(tf.SparseTensor(indices=indices, values=features_values.values,
                               dense_shape=np.array([1, 2112])))
    
    feature_spec = {'features_indices' : tf.io.VarLenFeature(tf.int64),
                        'features_values' : tf.io.VarLenFeature(tf.float32)
                   }
    
    raw_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
    raw_reatures = raw_input_fn().features
    feature_tensor = _sparse_to_dense_features_tensor(raw_reatures['features_indices'], raw_reatures['features_values'])
    return tf.estimator.export.ServingInputReceiver(feature_tensor, raw_reatures)

exported_model_dir = 'exported_model'

classifier.export_saved_model(exported_model_dir, serving_input_fn)
```

When I'm trying to predict using the REST API like following : 
```
curl -d "{\"inputs\":{\"features_values\": [10.0, 12.0], \"features_indices\": [3, 4]}}" \
```
I'm getting this issue : 
```
{ "error": "Tensor :0, specified in either feed_devices or fetch_devices was not found in the Graph" }
```

I have found some insights here : https://github.com/tensorflow/serving/issues/1100

This issue seems to come from the fact that `there is no name assigned to the SparseTensor` but there is no clear answer to deal with this problem... 

I don't know if I made a mistake, I would be happy if someone has a solution ! 

Thanks,

Maxime

Irene Giannoumis

unread,
Apr 6, 2020, 11:41:39 AM4/6/20
to Maxime Poulain, Pedram Pejman, TensorFlow Extended (TFX)
+Pedram Pejman to see if he can help with your serving issue

--
You received this message because you are subscribed to the Google Groups "TensorFlow Extended (TFX)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfx+uns...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfx/e32c2bd3-91bd-4bcf-9c2e-750d8c319cba%40tensorflow.org.

Pedram Pejman

unread,
Apr 6, 2020, 12:33:05 PM4/6/20
to TensorFlow Extended (TFX)
can you paste the output of `saved_model_cli show --dir <your savedmodel> --tag_set serve --signature_def <serving_default or whatever name you gave your signaturedef>`
More info on saved_model_cli: https://www.tensorflow.org/guide/saved_model


On Monday, April 6, 2020 at 8:41:39 AM UTC-7, Irene wrote:
+Pedram Pejman to see if he can help with your serving issue

To unsubscribe from this group and stop receiving emails from it, send an email to t...@tensorflow.org.

Maxime Poulain

unread,
Apr 6, 2020, 2:26:01 PM4/6/20
to TensorFlow Extended (TFX)
Hello, 

Thanks, to help me ! 

I hope it's you want,  the output of `saved_model_cli show --dir <your savedmodel> --tag_set serve --signature_def <serving_default or whatever name you gave your signaturedef>` is the following :

The given SavedModel SignatureDef contains the following input(s):
  inputs
['features_indices'] tensor_info:
      dtype
: DT_INT64
      shape
: (-1, -1)
      name
:
  inputs
['features_values'] tensor_info:
      dtype
: DT_FLOAT
      shape
: (-1, -1)
      name
:
The given SavedModel SignatureDef contains the following output(s):
  outputs
['class_ids'] tensor_info:
      dtype
: DT_FLOAT
      shape
: (1, 1827)
      name
: Cast:0
Method name is: tensorflow/serving/predict

Maybe this can also help you, I have these informations when I'm doing "curl -X GET http://localhost:8501/v1/models/my_model/metadata" : 
{
"model_spec":{
 
"name": "my_model",
 
"signature_name": "",
 
"version": "1586165717"
}
,
"metadata": {"signature_def": {
 
"signature_def": {
 
"serving_default": {
   
"inputs": {
   
"features_values": {
     
"coo_sparse": {
     
"values_tensor_name": "ParseExample/ParseExampleV2:3",
     
"indices_tensor_name": "ParseExample/ParseExampleV2:1",
     
"dense_shape_tensor_name": "ParseExample/ParseExampleV2:5"
     
},
     
"dtype": "DT_FLOAT",
     
"tensor_shape": {
     
"dim": [
       
{
       
"size": "-1",
       
"name": ""
       
},
       
{
       
"size": "-1",
       
"name": ""
       
}
     
],
     
"unknown_rank": false
     
}
   
},
   
"features_indices": {
     
"coo_sparse": {
     
"values_tensor_name": "ParseExample/ParseExampleV2:2",
     
"indices_tensor_name": "ParseExample/ParseExampleV2:0",
     
"dense_shape_tensor_name": "ParseExample/ParseExampleV2:4"
     
},
     
"dtype": "DT_INT64",
     
"tensor_shape": {
     
"dim": [
       
{
       
"size": "-1",
       
"name": ""
       
},
       
{
       
"size": "-1",
       
"name": ""
       
}
     
],
     
"unknown_rank": false
     
}
   
}
   
},
   
"outputs": {
   
"class_ids": {
     
"dtype": "DT_FLOAT",
     
"tensor_shape": {
     
"dim": [
       
{
       
"size": "1",
       
"name": ""
       
},
       
{
       
"size": "1827",
       
"name": ""
       
}
     
],
     
"unknown_rank": false
     
},
     
"name": "Cast:0"
   
}
   
},
   
"method_name": "tensorflow/serving/predict"
 
}
 
}
}
}
}

Thanks,

Maxime

Maxime Poulain

unread,
Apr 14, 2020, 2:46:33 PM4/14/20
to TensorFlow Extended (TFX)
Hello again !

Is there any one that can help me to handle this issue ?
Nobody is using Tensorflow Serving with SparseTensor ? Is it possible to do that ?

Thanks,

Maxime

Reply all
Reply to author
Forward
0 new messages