title: ValueError: Error when checking input: expected input to have 4 dimensions, but got array with shape (859307, 1)
body: <p>I'm creating a convolutional autoencoder that takes in 16x16 images but I keep getting the following error: </p>
  
  <pre><code>Traceback (most recent call last):
    File "WTApruning.py", line 69, in &lt;module&gt;
      validation_data=(x_test, x_test))
    File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 709, in fit
      shuffle=shuffle)
    File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 2651, in _standardize_user_data
      exception_prefix='input')
    File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training_utils.py", line 376, in standardize_input_data
      'with shape ' + str(data_shape))
  ValueError: Error when checking input: expected input to have 4 dimensions, but got array with shape (859307, 1)
  </code></pre>
  
  <p>From other stack overflow posts such as this <a href="https://stackoverflow.com/questions/57222126/error-when-checking-input-expected-conv2d-6-input-to-have-4-dimensions-but-got">one</a>, it seems like I need to add another dimension for the colour channel but what would the other dimension I add be? </p>
  
  <p>Code</p>
  
  <pre><code>path = "..."
  CATEGORIES = ["x_train", "x_test"]
  count = 0
  data = []
  x_test, x_train = [], []
  for img in os.listdir(path):
      img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE)
      data.append(img_array)
  x_train, x_test = train_test_split(data, test_size = 0.1)
  x_train, x_test = train_test_split(data, test_size = 0.1)
  x_train = np.array(x_train)
  x_test = np.array(x_test)
  # just updated
  x_train = x_train.reshape(x_train,(len(x_train),16,16,1))
  x_test = x_test.reshape(x_test,(len(x_test),16,16,1))
  
  # ENCODER
  encoder_img = tf.keras.layers.Input(shape=(16,16,1), name="input")
  x = tf.keras.layers.Conv2D(1024, 1, activation='relu', kernel_initializer=keras.initializers.RandomUniform)(encoder_img)
  x = tf.keras.layers.MaxPooling2D(1)(x)
  x = tf.keras.layers.Conv2D(512, 1, activation='relu')(x)
  x = tf.keras.layers.MaxPooling2D(1)(x)
  encoder_output = tf.keras.layers.Conv2D(256, 3, activation='relu')(x)
  
  # DECODER
  x = tf.keras.layers.Conv2DTranspose(512, 1, activation='relu')(encoder_output)
  x = tf.keras.layers.UpSampling2D(1)(x)
  x = tf.keras.layers.Conv2DTranspose(1024, 1, activation='relu')(x)
  x = tf.keras.layers.UpSampling2D(1)(x)
  decoder_output = tf.keras.layers.Conv2DTranspose(1, 3, activation='relu')(x)
  # COMPILE
  autoencoder = tf.keras.Model(inputs=encoder_img, outputs=decoder_output, name='autoencoder')
  autoencoder.summary()
  
  autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
  autoencoder.fit(x_train, x_train,
                  epochs=20,
                  batch_size=128,
                  shuffle=True,
                  validation_data=(x_test, x_test))
  decoded_imgs = autoencoder.predict(x_test)
  </code></pre>
  
  <p>New Error after reshaping is added:</p>
  
  <pre><code>Traceback (most recent call last):
    File "WTApruning.py", line 43, in &lt;module&gt;
      x_train = x_train.reshape(x_train,(len(x_train),16,16,1))
  TypeError: only integer scalar arrays can be converted to a scalar index
  
  </code></pre>
  
  <p>Error without reshaping:</p>
  
  <pre><code>Traceback (most recent call last):
    File "WTApruning.py", line 68, in &lt;module&gt;
      validation_data=(x_test, x_test))
    File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 709, in fit
      shuffle=shuffle)
    File "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 2651, in _standardize_user_data
      exception_prefix='input')
   "/PycharmProjects/predictivemodel/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/training_utils.py", line 376, in standardize_input_data
      'with shape ' + str(data_shape))
  ValueError: Error when checking input: expected input to have 4 dimensions, but got array with shape (859307, 1)
  
  </code></pre>