# I get an error on model.fit

**URL:** <https://discuss.ai.google.dev/t/i-get-an-error-on-model-fit/32448>\
**Category:** General Discussion\
**Tags:** model\
**Created:** [April 1, 2024, 9:56am UTC](https://discuss.ai.google.dev/t/i-get-an-error-on-model-fit/32448 "2024-04-01T09:56:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladislav](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/vladislav/32/7203_2.png) [@Vladislav](https://discuss.ai.google.dev/u/Vladislav)\
**Post date:** [April 1, 2024, 9:56am UTC](https://discuss.ai.google.dev/t/i-get-an-error-on-model-fit/32448/1 "2024-04-01T09:56:06Z")

</div>

model\_history = model.fit(train\_dataset,  
epochs=epochs,  
#steps\_per\_epoch=dataset\_size // batch\_size,  
validation\_data=val\_dataset)

## I try to fit my model but I get this error:

InvalidArgumentError Traceback (most recent call last)  
Cell In[61], line 11  
7 batch\_size = 64  
9 model.compile(loss=tf.keras.losses.BinaryCrossentropy(), optimizer=RMSprop(learning\_rate=0.001), metrics=[‘accuracy’])  
—\> 11 model\_history = model.fit(train\_dataset,  
12 epochs=epochs,  
13 #steps\_per\_epoch=dataset\_size // batch\_size,  
14 validation\_data=val\_dataset)

File /opt/conda/lib/python3.10/site-packages/keras/src/utils/traceback\_utils.py:123, in filter\_traceback..error\_handler(\*args, \*\*kwargs)  
120 filtered\_tb = \_process\_traceback\_frames(e. **traceback** )  
121 # To get the full stack trace, call:  
122 # `keras.config.disable_traceback_filtering()`  
 → 123 raise e.with\_traceback(filtered\_tb) from None  
124 finally:  
125 del filtered\_tb

File /opt/conda/lib/python3.10/site-packages/tensorflow/python/eager/execute.py:53, in quick\_execute(op\_name, num\_outputs, inputs, attrs, ctx, name)  
51 try:  
52 ctx.ensure\_initialized()  
—\> 53 tensors = pywrap\_tfe.TFE\_Py\_Execute(ctx.\_handle, device\_name, op\_name,  
54 inputs, attrs, num\_outputs)  
55 except core.\_NotOkStatusException as e:  
56 if name is not None:

InvalidArgumentError: Graph execution error:

Detected at node IteratorGetNext defined at (most recent call last):  
File “/opt/conda/lib/python3.10/runpy.py”, line 196, in \_run\_module\_as\_main

File “/opt/conda/lib/python3.10/runpy.py”, line 86, in \_run\_code

File “/opt/conda/lib/python3.10/site-packages/ipykernel\_launcher.py”, line 17, in

File “/opt/conda/lib/python3.10/site-packages/traitlets/config/application.py”, line 1043, in launch\_instance

File “/opt/conda/lib/python3.10/site-packages/ipykernel/kernelapp.py”, line 701, in start

File “/opt/conda/lib/python3.10/site-packages/tornado/platform/asyncio.py”, line 195, in start

File “/opt/conda/lib/python3.10/asyncio/base\_events.py”, line 603, in run\_forever

File “/opt/conda/lib/python3.10/asyncio/base\_events.py”, line 1909, in \_run\_once

File “/opt/conda/lib/python3.10/asyncio/events.py”, line 80, in \_run

File “/opt/conda/lib/python3.10/site-packages/ipykernel/kernelbase.py”, line 534, in dispatch\_queue

File “/opt/conda/lib/python3.10/site-packages/ipykernel/kernelbase.py”, line 523, in process\_one

File “/opt/conda/lib/python3.10/site-packages/ipykernel/kernelbase.py”, line 429, in dispatch\_shell

File “/opt/conda/lib/python3.10/site-packages/ipykernel/kernelbase.py”, line 767, in execute\_request

File “/opt/conda/lib/python3.10/site-packages/ipykernel/ipkernel.py”, line 429, in do\_execute

File “/opt/conda/lib/python3.10/site-packages/ipykernel/zmqshell.py”, line 549, in run\_cell

File “/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3051, in run\_cell

File “/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3106, in \_run\_cell

File “/opt/conda/lib/python3.10/site-packages/IPython/core/async\_helpers.py”, line 129, in \_pseudo\_sync\_runner

File “/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3311, in run\_cell\_async

File “/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3493, in run\_ast\_nodes

File “/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3553, in run\_code

File “/tmp/ipykernel\_33/1529170660.py”, line 11, in

File “/opt/conda/lib/python3.10/site-packages/keras/src/utils/traceback\_utils.py”, line 118, in error\_handler

File “/opt/conda/lib/python3.10/site-packages/keras/src/backend/tensorflow/trainer.py”, line 323, in fit

File “/opt/conda/lib/python3.10/site-packages/keras/src/backend/tensorflow/trainer.py”, line 116, in one\_step\_on\_iterator

Incompatible shapes at component 0: expected [?,768,768,3] but got [64,1,768,768,3].  
[[{{node IteratorGetNext}}]] [Op:\_\_inference\_one\_step\_on\_iterator\_16980]

Please give me an advice how to fix it, I’ve tried but still doesn’t work

It’s UNET model

```auto
def unet():
    inputs = tf.keras.layers.Input(shape=(768,768,3))
    encoder_output, convs = encoder(inputs)
    
    bottle_neck = bottleneck(encoder_output)
    
    outputs = decoder(bottle_neck, convs)
    model = tf.keras.Model(inputs=inputs, outputs=outputs)
    
    return model

```

That’s the data I pass to model.fit

```auto
train_dataset.element_spec
(TensorSpec(shape=(None, 768, 768, 3), dtype=tf.float32, name=None),
 TensorSpec(shape=(None, 768, 768, 2), dtype=tf.float32, name=None))

val_dataset.element_spec
(TensorSpec(shape=(None, 768, 768, 3), dtype=tf.float32, name=None),
 TensorSpec(shape=(None, 768, 768, 2), dtype=tf.float32, name=None))

```

---

<div class="post-metadata">

**Author:** ![Kiran\_Sai\_Ramineni](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/kiran_sai_ramineni/32/8859_2.png) [@Kiran\_Sai\_Ramineni](https://discuss.ai.google.dev/u/Kiran_Sai_Ramineni)\
**Post date:** [April 4, 2024, 4:26am UTC](https://discuss.ai.google.dev/t/i-get-an-error-on-model-fit/32448/3 "2024-04-04T04:26:52Z")

</div>

Hi @Vladislav, The error is due to the shape mismatch between input defined and the data passed through the model. Even though the dataset shape matches the input shape defined may be in the data preprocessing or in the data preparation pipeline the batch dimension is getting extra dimension. Please make sure that the data is preprocessed correctly. To debug more about the cause of the error if possible could you please share the complete code and sample data to reproduce the issue. Thank You.

---

<div class="post-metadata">

**Author:** ![Vladislav](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/vladislav/32/7203_2.png) [@Vladislav](https://discuss.ai.google.dev/u/Vladislav)\
**Post date:** [April 4, 2024, 8:58am UTC](https://discuss.ai.google.dev/t/i-get-an-error-on-model-fit/32448/4 "2024-04-04T08:58:29Z")

</div>

Sure, I’d like to share the whole code, but actually it’s from Kaggle. Can I send an URL to my code on this platform?

That’s it: [Airbus v2.0 | Kaggle](https://www.kaggle.com/code/vladislav573/airbus-v2-0)

---

<div class="post-metadata">

**Author:** ![Kiran\_Sai\_Ramineni](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/kiran_sai_ramineni/32/8859_2.png) [@Kiran\_Sai\_Ramineni](https://discuss.ai.google.dev/u/Kiran_Sai_Ramineni)\
**Post date:** [April 5, 2024, 8:01am UTC](https://discuss.ai.google.dev/t/i-get-an-error-on-model-fit/32448/6 "2024-04-05T08:01:39Z")

</div>

Hi @Vladislav, If possible could you please share the small sample of the dataset because I am unable to use the entire dataset in my environment to debug the code. Thank You.

---

<div class="post-metadata">

**Author:** ![Vladislav](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/vladislav/32/7203_2.png) [@Vladislav](https://discuss.ai.google.dev/u/Vladislav)\
**Post date:** [April 5, 2024, 5:58pm UTC](https://discuss.ai.google.dev/t/i-get-an-error-on-model-fit/32448/8 "2024-04-05T17:58:38Z")

</div>

Sure, here’s a link for my Google Drive folder with 25 first images and a csv file with their rle encodings. Thank for your help, I truly appreciate it

[https://drive.google.com/drive/folders/191w6KRWamLC47eCgXgcRFk\_LQPooDhAu?usp=drive\_link](https://drive.google.com/drive/folders/191w6KRWamLC47eCgXgcRFk_LQPooDhAu?usp=drive_link)
