# ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 224, 224, 3), found shape=(224, 224, 3)

**URL:** <https://discuss.ai.google.dev/t/valueerror-input-0-of-layer-sequential-is-incompatible-with-the-layer-expected-shape-none-224-224-3-found-shape-224-224-3/32680>\
**Category:** General Discussion\
**Tags:** datasets, help\_request\
**Created:** [June 25, 2023, 3:27pm UTC](https://discuss.ai.google.dev/t/valueerror-input-0-of-layer-sequential-is-incompatible-with-the-layer-expected-shape-none-224-224-3-found-shape-224-224-3/32680 "2023-06-25T15:27:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ata\_Tekeli](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ata_tekeli/32/12900_2.png) [@Ata\_Tekeli](https://discuss.ai.google.dev/u/Ata_Tekeli)\
**Post date:** [June 25, 2023, 3:27pm UTC](https://discuss.ai.google.dev/t/valueerror-input-0-of-layer-sequential-is-incompatible-with-the-layer-expected-shape-none-224-224-3-found-shape-224-224-3/32680/1 "2023-06-25T15:27:26Z")

</div>

Hello, I’m working on malaria detection and diagnosis with TensorFlow and I’ve exposed to the value error problem stated in the link below. Even though I follow this [tutorial] and doing what instructor did, I found out that error. After starting to search for error and reading through the message, I couldn’t find anything and even though it says there is error, I couldn’t find any even according to error message. ([https://www.youtube.com/watch?v=IA3WxTTPXqQ](https://www.youtube.com/watch?v=IA3WxTTPXqQ))

```auto
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import tensorflow_datasets as tfds
from keras.layers import Conv2D, MaxPool2D, Dense, Flatten, InputLayer
from keras.optimizers import Adam
from keras.losses import BinaryCrossentropy

dataset, dataset_info = tfds.load('malaria',
                                  with_info=True,
                                  as_supervised=True,
                                  shuffle_files=True,
                                  split=['train'])

print(dataset)
print(dataset_info)

def splits(dataset, TRAIN_RATIO, VAL_RATIO, TEST_RATIO):
    DATASET_SIZE = len(dataset)

    train_dataset = dataset.take(int(TRAIN_RATIO * DATASET_SIZE))

    val_test_dataset = dataset.skip(int(TRAIN_RATIO * DATASET_SIZE))
    val_dataset = val_test_dataset.take(int(VAL_RATIO * DATASET_SIZE))

    test_dataset = val_test_dataset.skip(int(VAL_RATIO * DATASET_SIZE))
    return train_dataset, val_dataset, test_dataset

TRAIN_RATIO = 0.6
VAL_RATIO = 0.2
TEST_RATIO = 0.2

#dataset = tf.data.Dataset.range(10)
train_dataset, val_dataset, test_dataset = splits(dataset[0],
                                                  TRAIN_RATIO,
                                                  VAL_RATIO,
                                                  TEST_RATIO)
print(list(train_dataset.take(1).as_numpy_iterator()),
      list(val_dataset.take(1).as_numpy_iterator()),
      list(test_dataset.take(1).as_numpy_iterator()))

for data in dataset[0].take(4):
    print(data)

for i, (image, label) in enumerate(train_dataset.take(16)):
    ax = plt.subplot(4, 4, i + 1)
    plt.imshow(image)
    plt.title(dataset_info.features['label'].int2str(label))
    plt.axis('off')
    plt.show()

print(dataset_info.features['label'].int2str(0))

IM_SIZE = 224

def resize_rescale(image, label):
    return tf.image.resize(image, (IM_SIZE, IM_SIZE))/255.0, label

train_dataset = train_dataset.map(resize_rescale)

for image, label in train_dataset.take(1):
    print(image, label)

train_dataset = train_dataset.shuffle(buffer_size = 8,
                                      reshuffle_each_iteration = True)\
    .prefetch(tf.data.AUTOTUNE)

lenet_model = tf.keras.Sequential([
    InputLayer(input_shape=(IM_SIZE, IM_SIZE, 3)),

    Conv2D(filters = 6, kernel_size = 5, strides=1, padding='valid',
           activation= 'sigmoid'),
    MaxPool2D(pool_size=2, strides=2),

    Conv2D(filters = 16, kernel_size = 5, strides=1, padding='valid',
           activation= 'sigmoid'),
    MaxPool2D(pool_size=2, strides=2),

    Flatten(),

    Dense(100, activation= "sigmoid"),
    Dense(10, activation= "sigmoid"),
    Dense(1, activation= "sigmoid"),
])

print(lenet_model.summary())

lenet_model.compile(optimizer=Adam(learning_rate=0.01), loss=BinaryCrossentropy())

history = lenet_model.fit(train_dataset, validation_data = val_dataset,
                    epochs = 100, verbose = 1)

```

---

<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:** [June 26, 2023, 9:07am UTC](https://discuss.ai.google.dev/t/valueerror-input-0-of-layer-sequential-is-incompatible-with-the-layer-expected-shape-none-224-224-3-found-shape-224-224-3/32680/3 "2023-06-26T09:07:28Z")

</div>

Hi @Ata_Tekeli, You are getting this error because you are passing only input data to the model, but the model requires batch size also.

> [@Ata\_Tekeli](#):
>
> ```auto
> train_dataset = train_dataset.shuffle(buffer_size = 8,
> reshuffle_each_iteration = True)\
> .prefetch(tf.data.AUTOTUNE)
> 
> ```

In the above code line please add the batch size.

```auto
train_dataset = train_dataset.shuffle(buffer_size = 8,
                                      reshuffle_each_iteration = True)\
                                      .batch(32).prefetch(tf.data.AUTOTUNE)

```

Thank You.

---

<div class="post-metadata">

**Author:** ![Ata\_Tekeli](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ata_tekeli/32/12900_2.png) [@Ata\_Tekeli](https://discuss.ai.google.dev/u/Ata_Tekeli)\
**Post date:** [June 26, 2023, 9:26am UTC](https://discuss.ai.google.dev/t/valueerror-input-0-of-layer-sequential-is-incompatible-with-the-layer-expected-shape-none-224-224-3-found-shape-224-224-3/32680/4 "2023-06-26T09:26:41Z")

</div>

Right now working on it and made some headway, and did some progress yesterday, I’ll ask more depends on the progress.

---

<div class="post-metadata">

**Author:** ![Ata\_Tekeli](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ata_tekeli/32/12900_2.png) [@Ata\_Tekeli](https://discuss.ai.google.dev/u/Ata_Tekeli)\
**Post date:** [June 26, 2023, 9:34am UTC](https://discuss.ai.google.dev/t/valueerror-input-0-of-layer-sequential-is-incompatible-with-the-layer-expected-shape-none-224-224-3-found-shape-224-224-3/32680/5 "2023-06-26T09:34:02Z")

</div>

And now this is the code I worked with and has the error even though some progress is made

```auto
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import tensorflow_datasets as tfds
from keras.layers import Conv2D, MaxPool2D, Dense, Flatten, InputLayer
from keras.optimizers import Adam
from keras.losses import BinaryCrossentropy

dataset, dataset_info = tfds.load('malaria',
                                  with_info=True,
                                  as_supervised=True,
                                  shuffle_files=True,
                                  split=['train'])

print(dataset)
print(dataset_info)

def splits(dataset, TRAIN_RATIO, VAL_RATIO, TEST_RATIO):
    DATASET_SIZE = len(dataset)

    train_dataset = dataset.take(int(TRAIN_RATIO * DATASET_SIZE))

    val_test_dataset = dataset.skip(int(TRAIN_RATIO * DATASET_SIZE))
    val_dataset = val_test_dataset.take(int(VAL_RATIO * DATASET_SIZE))

    test_dataset = val_test_dataset.skip(int(VAL_RATIO * DATASET_SIZE))
    return train_dataset, val_dataset, test_dataset

TRAIN_RATIO = 0.6
VAL_RATIO = 0.2
TEST_RATIO = 0.2

#dataset = tf.data.Dataset.range(10)
train_dataset, val_dataset, test_dataset = splits(dataset[0],
                                                  TRAIN_RATIO,
                                                  VAL_RATIO,
                                                  TEST_RATIO)
print(list(train_dataset.take(1).as_numpy_iterator()),
      list(val_dataset.take(1).as_numpy_iterator()),
      list(test_dataset.take(1).as_numpy_iterator()))

for data in dataset[0].take(4):
    print(data)

for i, (image, label) in enumerate(train_dataset.take(16)):
    ax = plt.subplot(4, 4, i + 1)
    plt.imshow(image)
    plt.title(dataset_info.features['label'].int2str(label))
    plt.axis('off')
    plt.show()

print(dataset_info.features['label'].int2str(0))

IM_SIZE = 224
def resize_rescale(image, label):
    return tf.image.resize(image, (IM_SIZE, IM_SIZE))/255.0, label

train_dataset = train_dataset.map(resize_rescale)
val_dataset = val_dataset.map(resize_rescale)
test_dataset = test_dataset.map(resize_rescale)
print(train_dataset)
print(val_dataset)
print(test_dataset)

for image, label in train_dataset.take(1):
    print(image, label)

BATCH_SIZE = 32
train_dataset = train_dataset.shuffle(buffer_size = 8,
                                      reshuffle_each_iteration = True)\
    .prefetch(tf.data.AUTOTUNE)

val_dataset = val_dataset.shuffle(buffer_size = 8,
                                      reshuffle_each_iteration = True)\
    .prefetch(tf.data.AUTOTUNE)

print(train_dataset)
print(val_dataset)

lenet_model = tf.keras.Sequential([
    InputLayer(input_shape=(IM_SIZE, IM_SIZE, 3)),

    Conv2D(filters = 6, kernel_size = 5, strides=1, padding='valid',
           activation= 'sigmoid'),
    MaxPool2D(pool_size=2, strides=2),

    Conv2D(filters = 16, kernel_size = 5, strides=1, padding='valid',
           activation= 'sigmoid'),
    MaxPool2D(pool_size=2, strides=2),

    Flatten(),

    Dense(100, activation= "sigmoid"),
    Dense(10, activation= "sigmoid"),
    Dense(1, activation= "sigmoid"),
])

print(lenet_model.summary())

lenet_model.compile(optimizer=Adam(learning_rate=0.01), loss=BinaryCrossentropy())

history = lenet_model.fit(train_dataset, validation_data = val_dataset,
                    epochs = 100, verbose = 1)

```

---

<div class="post-metadata">

**Author:** ![Ata\_Tekeli](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/ata_tekeli/32/12900_2.png) [@Ata\_Tekeli](https://discuss.ai.google.dev/u/Ata_Tekeli)\
**Post date:** [June 26, 2023, 9:37am UTC](https://discuss.ai.google.dev/t/valueerror-input-0-of-layer-sequential-is-incompatible-with-the-layer-expected-shape-none-224-224-3-found-shape-224-224-3/32680/6 "2023-06-26T09:37:10Z")

</div>

Worked like a charm, thought that I could get away with defining batch size earlier on, did on both training and validation datasets
