【问题标题】:How predict more than one image in keras如何在keras中预测多个图像
【发布时间】:2019-11-13 11:43:49
【问题描述】:

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

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

【问题讨论】:

    标签: python keras deep-learning vgg-net


    【解决方案1】:

    50 中,您提到VGG16 接受形状为(224,224,3) 的输入,但是当您加载image 时,您将其重塑为(500,150528),这就是您收到错误的原因。将行 41 更改为

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

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2020-05-14
      • 1970-01-01
      • 2019-12-30
      • 1970-01-01
      • 2017-08-18
      • 2020-08-04
      • 2020-08-29
      • 2020-06-28
      • 1970-01-01
      相关资源
      最近更新 更多