<p dir="auto"><strong>System information</strong>.</p>
<ul dir="auto">
<li>Have I written custom code (as opposed to using a stock example script provided in Keras):  No</li>
<li>OS Platform and Distribution (e.g., Linux Ubuntu 16.04):   Win10</li>
<li>TensorFlow installed from (source or binary):   Anaconda</li>
<li>TensorFlow version (use command below):  2.9.1</li>
<li>Python version:    3.9</li>
<li>GPU model and memory:  None</li>
</ul>
<p dir="auto"><strong>Describe the problem</strong>.<br>
I am going through Francois Chollet's book "Deep Learning with Python" and running the code in his Jupyter Notebooks with Keras: 2.9.0 , Tensorflow: 2.9.1.<br>
Notebook 6.3, (under the heading "1.6 Using recurrent dropout to fight overfitting") has a model following:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="model = Sequential()
model.add(layers.GRU(32, 
                     dropout=0.2,
                     recurrent_dropout=0.2,
                     input_shape=(None, float_data.shape[-1])))
model.add(layers.Dense(1))

model.compile(optimizer=RMSprop(), loss='mae')
history = model.fit_generator(train_gen,
                              steps_per_epoch=500,  
                              epochs=40,
                              validation_data=val_gen,
                              validation_steps=val_steps)"><pre class="notranslate"><span class="pl-s1">model</span> <span class="pl-c1">=</span> <span class="pl-v">Sequential</span>()
<span class="pl-s1">model</span>.<span class="pl-en">add</span>(<span class="pl-s1">layers</span>.<span class="pl-v">GRU</span>(<span class="pl-c1">32</span>, 
                     <span class="pl-s1">dropout</span><span class="pl-c1">=</span><span class="pl-c1">0.2</span>,
                     <span class="pl-s1">recurrent_dropout</span><span class="pl-c1">=</span><span class="pl-c1">0.2</span>,
                     <span class="pl-s1">input_shape</span><span class="pl-c1">=</span>(<span class="pl-c1">None</span>, <span class="pl-s1">float_data</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>])))
<span class="pl-s1">model</span>.<span class="pl-en">add</span>(<span class="pl-s1">layers</span>.<span class="pl-v">Dense</span>(<span class="pl-c1">1</span>))

<span class="pl-s1">model</span>.<span class="pl-en">compile</span>(<span class="pl-s1">optimizer</span><span class="pl-c1">=</span><span class="pl-v">RMSprop</span>(), <span class="pl-s1">loss</span><span class="pl-c1">=</span><span class="pl-s">'mae'</span>)
<span class="pl-s1">history</span> <span class="pl-c1">=</span> <span class="pl-s1">model</span>.<span class="pl-en">fit_generator</span>(<span class="pl-s1">train_gen</span>,
                              <span class="pl-s1">steps_per_epoch</span><span class="pl-c1">=</span><span class="pl-c1">500</span>,  
                              <span class="pl-s1">epochs</span><span class="pl-c1">=</span><span class="pl-c1">40</span>,
                              <span class="pl-s1">validation_data</span><span class="pl-c1">=</span><span class="pl-s1">val_gen</span>,
                              <span class="pl-s1">validation_steps</span><span class="pl-c1">=</span><span class="pl-s1">val_steps</span>)</pre></div>
<p dir="auto">Running parts 6.3.6 (recurrent dropout) and 6.3.7 (stacked recurrent layers)  gives the following training and validation losses:</p>
<p dir="auto">6.3.6<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/74046524/186118937-0f7ccf47-c025-4530-a8e0-e1e145f9e02f.png"><img src="https://user-images.githubusercontent.com/74046524/186118937-0f7ccf47-c025-4530-a8e0-e1e145f9e02f.png" alt="1661232542955" style="max-width: 100%;"></a></p>
<p dir="auto">6.3.7<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/74046524/186122056-82d61282-e6b9-4cd7-b822-9e52fb296c5c.png"><img src="https://user-images.githubusercontent.com/74046524/186122056-82d61282-e6b9-4cd7-b822-9e52fb296c5c.png" alt="1661246457143" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Describe the expected behavior</strong>.<br>
After using dropout it should solve the overfitting problem just like in the book.</p>
<p dir="auto"><strong>System information</strong>.</p>
<ul dir="auto">
<li>Have I written custom code (as opposed to using a stock example script provided in Keras: no</li>
<li>OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04</li>
<li>TensorFlow installed from (source or binary): binary</li>
<li>TensorFlow version (use command below): v2.4.0-rc4-71-g582c8d236cb 2.4.0</li>
<li>Python version: 3.8.5</li>
</ul>
<p dir="auto"><strong>Describe the problem</strong>.</p>
<p dir="auto">The error and warning messages seem to be different when <code class="notranslate">model(x)</code> is used instead of <code class="notranslate">model.predict(x)</code>  to make a prediction.<br>
Is this intentional and documented somewhere?<br>
For example, in the following simple model there is a warning when <code class="notranslate">model.predict(x)</code> is used, but none for <code class="notranslate">model(x)</code>.<br>
Moreover, it would be generally good to know which warnings (or errors) might not occur when a specific prediction method is used and also which warnings will be the same.</p>
<p dir="auto"><strong>Standalone code to reproduce the issue</strong>.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import numpy as np
model = keras.Sequential([
keras.layers.ReLU(threshold=3,  input_shape=(2,))])
x = tf.constant([[[[1,2,3,4,5]]]])
print (np.array2string(model(x).numpy(), separator=', '))
#print (np.array2string(model.predict(x), separator=', '))"><pre class="notranslate"><code class="notranslate">import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import numpy as np
model = keras.Sequential([
keras.layers.ReLU(threshold=3,  input_shape=(2,))])
x = tf.constant([[[[1,2,3,4,5]]]])
print (np.array2string(model(x).numpy(), separator=', '))
#print (np.array2string(model.predict(x), separator=', '))
</code></pre></div>