title: keras' preprocess_input led to ValueError: Data cardinality is ambiguous
body: <p>I'm using keras for a regression model. I'm trying to fine tune the VGG16. Everything was working. After I added the <code>tensorflow.keras.applications.vgg16.preprocess_input</code> to preprocess the images according to the VGG16 I got the following error :</p>
  <blockquote>
  <p>ValueError: Data cardinality is ambiguous:
  x sizes: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  y sizes: 422
  Make sure all arrays contain the same number of samples.</p>
  </blockquote>
  <p>After loading the images, I loop through theme and apply this:</p>
  <pre><code>from keras.preprocessing.image import img_to_array
  
  images = []
  for img in loaded_images:
      img = img_to_array(img)
      img = img.reshape((1, img.shape[0], img.shape[1], img.shape[2]))
      img = preprocess_input(img)
      images.append(img)
  
  actual = actual.reshape(1,-1)
  assert len(images) == len(actual)
  </code></pre>
  <p>After that I partition the images into train, valid and testing set as follows:</p>
  <p><strong>Edit</strong>:</p>
  <pre><code>train_images,test_images, train_actual_score , test_actual_score = train_test_split(images, scaled_train_mos, test_size=0.20, random_state=42)
  </code></pre>
  <p>Finally I call the <code>fit</code> func :</p>
  <pre><code>history = model.fit(x=train_images, y=train_actual_score, validation_data=(test_images, test_actual_score), epochs=30, batch_size=8, verbose=2)
  </code></pre>
  <p><strong>Update</strong>:</p>
  <p>Here is a <a href="https://colab.research.google.com/drive/1_yqIkVU4H9b8k-sMPGf-FjH7Dzy6s7PO?usp=sharing" rel="nofollow noreferrer">standalone code</a> to reproduce the above issue.</p>