Arianna Ever
Arianna Ever

Reputation: 1

ValueError: Input 0 is incompatible with layer functional_1: expected shape=(None, 112, 112, 3), found shape=(None, 224, 224, 3)

I am trying to put a trained model into a Flask app. The thing is, both input image for the app are preprocessed the same way as for training the model. Still I get this error:

ValueError: Input 0 is incompatible with layer functional_1: expected shape=(None, 112, 112, 3), found shape=(None, 224, 224, 3)

Model training: ''' train_data.element_spec >>(TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name=None), TensorSpec(shape=(None, 400), dtype=tf.bool, name=None)) '''

Flask app: ''' IMG_SIZE=224 BATCH_SIZE=32

def preprocess_image(image_path, img_size = 224):
  image=tf.io.read_file(image_path)
  image=tf.image.decode_jpeg(image,channels=3)
  image=tf.image.convert_image_dtype(image,tf.float32)
  image = tf.image.resize(image,size=[IMG_SIZE,IMG_SIZE])
  return image


def create_data_batches(x,batch_size=32):
    print('Creating test data branches....')
    x=[x]
    data=tf.data.Dataset.from_tensor_slices((tf.constant(x)))
    data_batch=data.map(preprocess_image).batch(BATCH_SIZE)
    return data_batch
'''

So where does this expected shape=(None, 112, 112, 3) come from? There is not a single '112' in a code, so what am I doing wrong?

I will really appreciate any help. P.S. The model I am trying to work with is inception_v2. P.P.S. Saved trained model format id .h5

Upvotes: 0

Views: 1097

Answers (1)

user11530462
user11530462

Reputation:

This error occurs as a result of the model being trained with an image size of (112,112,3).

To solve the error replace this:

def preprocess_image(image_path, img_size = 224)

with this:

def preprocess_image(image_path, img_size = 112)

Upvotes: 0

Related Questions