# Dropout, SavedModel and TFserving

**URL:** <https://discuss.ai.google.dev/t/dropout-savedmodel-and-tfserving/26254>\
**Category:** General Discussion\
**Tags:** models\
**Created:** [November 1, 2022, 1:45am UTC](https://discuss.ai.google.dev/t/dropout-savedmodel-and-tfserving/26254 "2022-11-01T01:45:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BePequeno](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bepequeno/32/11200_2.png) [@BePequeno](https://discuss.ai.google.dev/u/BePequeno)\
**Post date:** [November 1, 2022, 1:45am UTC](https://discuss.ai.google.dev/t/dropout-savedmodel-and-tfserving/26254/1 "2022-11-01T01:45:03Z")

</div>

I’ve trained a neural network with **dropout** and I saved it using the `SavedModel` format.  
Now, I deployed it using tensorflow serving.

Everything works well but I’m wondering if the dropout is removed from the computation.  
Is the `SavedModel` format removes the dropout, as `model.forward(.., training=False)` would do. I guess it should since the `SavedModel` format is meant for inference but just to be sure.

Thank you all !

---

<div class="post-metadata">

**Author:** ![Amin\_Jigari](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/amin_jigari/32/13458_2.png) [@Amin\_Jigari](https://discuss.ai.google.dev/u/Amin_Jigari)\
**Post date:** [November 2, 2022, 6:52am UTC](https://discuss.ai.google.dev/t/dropout-savedmodel-and-tfserving/26254/3 "2022-11-02T06:52:26Z")

</div>

I am also getting the same issue mentioned above.

---

<div class="post-metadata">

**Author:** ![BePequeno](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bepequeno/32/11200_2.png) [@BePequeno](https://discuss.ai.google.dev/u/BePequeno)\
**Post date:** [November 3, 2022, 10:37am UTC](https://discuss.ai.google.dev/t/dropout-savedmodel-and-tfserving/26254/4 "2022-11-03T10:37:51Z")

</div>

I’ve done a small test to check if dropout **is** removed when exporting to saved model and infering with tensorflow serving.

The test is:

1. create dummy model with arbitrary weights and dropout
2. export to savedmodel
3. deploy using tensorflow serving
4. get inference multiple times and check if the output value changes.

Example:

_Create dummy model, test it and save it_

```auto
>> import tensorflow as tf
>> nn = tf.keras.Sequential([tf.keras.layers.Dense(1, kernel_initializer='ones'),   
                             tf.keras.layers.Dropout(0.25)])
>> a = tf.constant([[2.0]])
>> nn(a, training=False)
<tf.Tensor: shape=(1, 1), dtype=float32, numpy=array([[2.]], dtype=float32)>
>> tf.saved_model.save(nn, "test_dummy")

```

_Launch tensorflow serving_ ([documentation here](https://www.tensorflow.org/tfx/tutorials/serving/rest_simple#serve_your_model_with_tensorflow_serving))

_Get inferencefrom tf/serving_

```auto
$ curl -d '{"instances": [[2.0]]}' -X POST http://localhost:8501/v1/models/dummy:predict
{
    "predictions": [[2.0]
    ]
}

```

I did dozens of inference and never had a different value from 2.0 which the expected output when having no dropout.

Conclusion: I do think dropout (might be extended to batch normalization) are removed from savedmodel (or at least removed in tensorflow serving).

Tell me if you think I missed something 🙂  
Benoît.

---

<div class="post-metadata">

**Author:** ![FynnMartinGilbert](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/fynnmartingilbert/32/1490_2.png) [@FynnMartinGilbert](https://discuss.ai.google.dev/u/FynnMartinGilbert)\
**Post date:** [July 23, 2024, 7:43am UTC](https://discuss.ai.google.dev/t/dropout-savedmodel-and-tfserving/26254/6 "2024-07-23T07:43:44Z")

</div>

Is there a way of enabling dropout during inference time using tf-serving?
