如何预测喀拉拉邦不止一张图像

时间:2019-11-13 11:43:49

标签: python keras deep-learning vgg-net

我正在尝试从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)

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

1 个答案:

答案 0 :(得分:1)

就像50一样,您提到VGG16接受形状为(224,224,3)的输入,但是在加载image时将其重塑为(500,150528),这就是为什么得到一个错误。将行41更改为

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

希望这会有所帮助!