如何在keras中预测多张图像

How predict more than one image in keras

我正在尝试 运行 来自 github 的一个项目,我正在尝试对图像进行聚类,但是当我 运行 这个项目时,我得到一个错误 ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (500, 150528) 我尝试调试项目,发现是这两个函数引起的

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.")

pred = VGG16.predict(self.images)

我不太确定是否正确使用它或项目需要一些修改 但我如何调整代码以预测数组中的图像?

喜欢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变成

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

希望对您有所帮助!