keras TypeError:无法解压缩不可迭代的JpegImageFile对象

t1rydlwq  于 2023-10-19  发布在  其他
关注(0)|答案(1)|浏览(258)

我在keras上运行一个模型,我有以下函数:

def result_show(test_data,filename):
    src_image, tar_image = test_data
    # generate image from source
    gen_image = model.predict(src_image)
    print(src_image.shape)
    src_image = src_image.reshape((256,256,1))
    print(src_image.shape)
    gen_image = np.squeeze(gen_image)

    gen_Lab = np.concatenate([src_image, gen_image],axis = 2)
    gen_rgb = lab2rgb(gen_Lab)
    gen_rgb = np.array(gen_rgb).astype('uint8')

    tar_image = tar_image[0,:,:,:]
    print(gen_image.shape,src_image.shape,tar_image.shape)
    tar_Lab = np.concatenate([src_image, tar_image],axis = 2)
    tar_rgb = lab2rgb(tar_Lab)
    tar_rgb = np.array(tar_rgb).astype('uint8')

    save_path = '/content/gdrive/MyDrive/Thesis/output/lab/'+filename

    # plot all three images
    plot_whole_images(src_image, gen_rgb, tar_rgb,save_path)

但每当我调用该函数时,它都会给我以下错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-42-657af1de80f7> in <cell line: 16>()
     14 # result_show(test_data, "sdfhkjsdf")
     15 
---> 16 result_show(test_data,"abcd")

<ipython-input-34-b1d19dfb20e1> in result_show(test_data, filename)
      1 def result_show(test_data,filename):
----> 2     src_image, tar_image = test_data
      3     # generate image from source
      4     gen_image = model.predict(src_image)
      5     print(src_image.shape)

TypeError: cannot unpack non-iterable JpegImageFile object

有什么问题怎么解决?Thanks in advance

ngynwnxp

ngynwnxp1#

问题可能是这行src_image, tar_image = test_data,在这行中,您试图将src_image和tar_image分配给test_data中的任何值。要做到这一点,存储在test_data中的值必须是可以解包/分配给两个新变量的值(即元组)。
错误消息TypeError: cannot unpack non-iterable JpegImageFile object告诉您,test_data中的任何内容都是不可迭代的/不能解包和赋值。我首先要确保test_data是你期望的类型。

相关问题