【问题标题】:save predicted images to a folder将预测图像保存到文件夹
【发布时间】:2021-11-17 21:33:05
【问题描述】:

我正在使用 model.fit_generator() 来预测图像。我不断收到以下错误:

ValueError:检查输入时出错:预期 conv2d_29_input 有 4 个维度,但得到的数组形状为 (224, 224, 3) 我正在尝试将预测图像保存到文件夹中。

以下是我的代码:

data_list = []
batch_index = 0

while batch_index <= train_generator.batch_index:
    data = next(train_generator)
    data_list.append(data[0])
    batch_index = batch_index + 1

 for i in range(batch_index):
     for j in range(batch_size):
         predicted[i][j]= model.predict(data_list[i] [j])
         plt.imsave(os.path.join(path,'new_image'+ str(i)+ str(j)+ "_AE_.tiff"), predicted[i][j])

形状有什么问题?? 谢谢

【问题讨论】:

  • This answer 可能会有所帮助。
  • 很有帮助,谢谢。

标签: generative-adversarial-network image-formats


【解决方案1】:

以下是我解决问题的方法:

path='the data folder'

data_list = [] 
batch_index = 0
predicted=[]
n= len(train_generator)

while batch_index <= train_generator.batch_index:
    data = train_generator.next()
    data_list.append(data[0])
    batch_index = batch_index + 1

data_array = np.array(data_list, dtype= float)

    
predicted=model.predict(data_array)

for i in range(n):
    plt.imsave(os.path.join(path,'new_image'+ str(i)+"_AE.tiff"), predicted[i,])
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 2017-07-26
    • 2011-06-24
    相关资源
    最近更新 更多