ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array with shape (142, 1) I'm trying to pass all my images (71 for each class) from folder 'train' to model.fit.
The method ReadImages get these images and resize them (because are too big 4288x2848)....

But when i run my code throws this error:

ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array with shape (142, 1)


This is my code:

def ReadImages(Path):
    LabelList = list()
    ImageCV = list()
    classes = ["nonPdr", "pdr"]

    # Get all subdirectories
    FolderList = os.listdir(Path)

    # Loop over each directory
    for File in FolderList:
        if(os.path.isdir(os.path.join(Path, File))):
           for index, Image in enumerate(os.listdir(os.path.join(Path, File))):
                # Convert the path into a file
                ImageCV.append(cv2.imread(os.path.join(Path, File) + os.path.sep + Image))
                ImageCV[index] = cv2.resize(ImageCV[index], (700, 600)) 

                # Add a label for each image and remove the file extension
                LabelList.append(classes.index(os.path.splitext(File)[0]))
        else:
            ImageCV.append(cv2.imread(os.path.join(Path, File) + os.path.sep + Image))    
            # Add a label for each image and remove the file extension
            LabelList.append(classes.index(os.path.splitext(File)[0]))
    return ImageCV, LabelList

model = Sequential()
model.add(Conv2D(64, kernel_size=(3,3), padding="same",activation="relu", input_shape=(605,700,3)))
model.add(MaxPooling2D((2, 2)))
model.add(Conv2D(128,  kernel_size=(4,4), padding="same",activation="relu"))
model.add(MaxPooling2D((2, 2)))
model.add(Flatten())
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='RMSprop', loss='binary_crossentropy', metrics=['accuracy'])

data, labels = ReadImages(TRAIN_DIR)
print(data[0])
model.fit(np.array(data), np.array(labels), epochs=10, batch_size=20)

model.save('model.h5')


detail: when I print (data[0]) it return:

  [0 0 0]
  [0 0 0]
  ...
  [1 0 0]
  [2 2 2]
  [0 0 0]]

 [[3 0 0]
  [3 0 0]
  [3 0 0]
  ...
  [2 0 0]
  [2 2 2]
  [0 0 0]]

 [[8 0 0]
  [8 0 0]
  [8 0 0]
  ...
  [2 0 0]
  [0 0 0]
  [0 0 0]]

 ...

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]]


What should I do to fix it? I appreciate any help
def ReadImages(Path):
    LabelList = list()
    ImageCV = list()
    classes = ["nonPdr", "pdr"]

   # Get all subdirectories
   FolderList = [f for f in os.listdir(Path) if not f.startswith('.')]
   print(FolderList)

   # Loop over each directory
   for File in FolderList:
      for index, Image in enumerate(os.listdir(os.path.join(Path, File))):
          # Convert the path into a file
          ImageCV.append(cv2.resize(cv2.imread(os.path.join(Path, File) + os.path.sep + Image), (600,700)))
          LabelList.append(classes.index(os.path.splitext(File)[0])) 

   return ImageCV, LabelList


A bit of change to your code after discussion in the chat room.