# Deploying model on streamlit problem

**URL:** <https://discuss.ai.google.dev/t/deploying-model-on-streamlit-problem/28987>\
**Category:** General Discussion\
**Tags:** models, help\_request\
**Created:** [July 15, 2021, 4:35pm UTC](https://discuss.ai.google.dev/t/deploying-model-on-streamlit-problem/28987 "2021-07-15T16:35:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabbygab1233](https://avatars.discourse-cdn.com/v4/letter/g/3be4f8/32.png) [@gabbygab1233](https://discuss.ai.google.dev/u/gabbygab1233)\
**Post date:** [July 15, 2021, 4:35pm UTC](https://discuss.ai.google.dev/t/deploying-model-on-streamlit-problem/28987/1 "2021-07-15T16:35:28Z")

</div>

I’m trying to deploy my image classification model on streamlit but I encounter this warning message when I trying to make inferences using the app.

 ![image](https://d3qe71uytubmmx.cloudfront.net/original/2X/a/a9db6e288afbb02e99dafc1b5a888015a650ad93.png)

 ![image](https://d3qe71uytubmmx.cloudfront.net/original/2X/f/fe16ab1e44a45d9c0a1b25164bb1c3e46b634075.png)

---

<div class="post-metadata">

**Author:** ![Sean\_Moriarity](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/sean_moriarity/32/8001_2.png) [@Sean\_Moriarity](https://discuss.ai.google.dev/u/Sean_Moriarity)\
**Post date:** [July 15, 2021, 6:17pm UTC](https://discuss.ai.google.dev/t/deploying-model-on-streamlit-problem/28987/4 "2021-07-15T18:17:59Z")

</div>

The first image is just showing information about your platform. You can pretty much safely ignore them.

About the second image…Your inference function is a [tf.function](https://www.tensorflow.org/api_docs/python/tf/function) which constructs, optimizes, and compiles a static graph at runtime (by “tracing” the annotated function, outside the scope of this answer). The warning is telling you that each call to your predict function has to reconstruct, optimize, and compile a new graph. That ends up being really expensive, and you miss out on the performance benefits of `tf.function`.

To break it down, here’s what it’s telling you could be happening:

1. creating @tf.function repeatedly in a loop

```auto
while True:
  my_predict_function = lambda x: x * x
  my_tf_predict_function = tf.function(func=my_predict_function) # uh oh, this gets called every loop iteration
  my_tf_predict_function(tf.random.uniform((2, 2)))

```

If you’re not defining / redefining your model or predict function in a loop, this is unlikely to be the case.

1. passing tensors with different shapes

```auto
my_predict_function = lambda x: x * x
my_tf_predict_function = tf.function(func=my_predict_function)
my_tf_predict_function(tf.random.uniform((2, 2)))
my_tf_predict_function(tf.random.uniform((3, 2))) # different shapes, our graph was previously optimized on a shape of (2, 2)

```

If you’re passing images of different dimensions, this is likely the case.

1. passing Python objects instead of tensors

```auto
my_predict_function = lambda x, flag: x * x if flag else x
my_tf_predict_function = tf.function(func=my_predict_function)
input = tf.random.uniform((2, 2))
my_tf_predict_function(input, True) # the graph compiled is x * x
my_tf_predict_function(input, False) # we have to recompile because it takes a different path based on flag!

```

Notice how the graph changes based on `flag` which is a Python object and not a tensor. So even though the shapes are the same, the graph is different. If you control your model with some hyperparameters which are Python scalars or other Python objects, then it will need to recompile the graph every time you change a parameter.

---

<div class="post-metadata">

**Author:** ![gabbygab1233](https://avatars.discourse-cdn.com/v4/letter/g/3be4f8/32.png) [@gabbygab1233](https://discuss.ai.google.dev/u/gabbygab1233)\
**Post date:** [July 16, 2021, 5:10am UTC](https://discuss.ai.google.dev/t/deploying-model-on-streamlit-problem/28987/6 "2021-07-16T05:10:14Z")

</div>

Wow thanks, you explained it well.💯
