How predict more than one image in keras

Question:

I Am trying to run a project from github , I am trying to cluster images, but when I run the project I get an error ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (500, 150528)
I tried to debug the project and I found that it caused by those two functions

def load_images(self):
    self.images = []
    for image in self.image_paths:
        self.images.append(
            cv2.cvtColor(cv2.resize(cv2.imread(self.folder_path + "\" + image), (224, 224)), cv2.COLOR_BGR2RGB))
    self.images = np.float32(self.images).reshape(len(self.images), -1)
    self.images /= 255
    print("n " + str(
        self.max_examples) + " images from the "" + self.folder_path + "" folder have been loaded in a random order.")

and

pred = VGG16.predict(self.images)

I am not quite sure if am using it correctly or the project need some modifications
but how can I adapt the code to predict the images in the array?

Asked By: Exorcismus

||

Answers:

In like 50 you have mentioned that VGG16 accepts inputs of shape (224,224,3) but when you load the image you reshape it into (500,150528) that’s why you get an error. Change line 41 into

self.images = np.float32(self.images).reshape(len(self.images), 224,224,3)