taoxugit / AttnGAN

MIT License
1.33k stars 420 forks source link

TypeError: Cannot handle this data type: (1, 1, 12), |u1 #80

Open VicZlq opened 4 years ago

VicZlq commented 4 years ago

您好,我在训练的时候,出现这个问题 File "/home/anaconda3/envs/pt/lib/python3.7/site-packages/PIL/Image.py", line 2716, in fromarray raise TypeError("Cannot handle this data type: %s, %s" % typekey) TypeError: Cannot handle this data type: (1, 1, 12), |u1 我安装的PIL7.1.2的版本,是因为版本的问题么? 请问有人遇到过同样的问题么?如何解决的呢?谢谢

XueiuR commented 4 years ago

我也遇到了同样的问题,环境是使用的google的colab平台 报错如下

/content/gdrive/My Drive/code/AttnGAN/code/miscc/utils.py:236: RuntimeWarning: invalid value encountered in true_divide
  one_map = (one_map - minV) / (maxV - minV)
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 2680, in fromarray
    mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1, 12), '|u1')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 146, in <module>
    gen_example(dataset.wordtoix, algo)  # generate images for customized captions
  File "main.py", line 83, in gen_example
    algo.gen_example(data_dic)
  File "/content/gdrive/My Drive/code/AttnGAN/code/trainer.py", line 514, in gen_example
    [attn_maps[j]], att_sze)
  File "/content/gdrive/My Drive/code/AttnGAN/code/miscc/utils.py", line 245, in build_super_images2
    PIL_att = Image.fromarray(np.uint8(one_map))
  File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 2682, in fromarray
    raise TypeError("Cannot handle this data type: %s, %s" % typekey)
TypeError: Cannot handle this data type: (1, 1, 12), |u1

请问你解决了吗?

VicZlq commented 4 years ago

您好,我在py3.7的版本下没有解决该问题,后来换到了2.7是可以正常运行的。

赵柳

邮箱:18130039283@163.com |

签名由 网易邮箱大师 定制

On 06/26/2020 22:31, XueiuR wrote:

我也遇到了同样的问题,环境是使用的google的colab平台 报错如下

/content/gdrive/My Drive/code/AttnGAN/code/miscc/utils.py:236: RuntimeWarning: invalid value encountered in true_divide

one_map = (one_map - minV) / (maxV - minV)

Traceback (most recent call last):

File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 2680, in fromarray

mode, rawmode = _fromarray_typemap[typekey]

KeyError: ((1, 1, 12), '|u1')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "main.py", line 146, in

gen_example(dataset.wordtoix, algo)  # generate images for customized captions

File "main.py", line 83, in gen_example

algo.gen_example(data_dic)

File "/content/gdrive/My Drive/code/AttnGAN/code/trainer.py", line 514, in gen_example

[attn_maps[j]], att_sze)

File "/content/gdrive/My Drive/code/AttnGAN/code/miscc/utils.py", line 245, in build_super_images2

PIL_att = Image.fromarray(np.uint8(one_map))

File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 2682, in fromarray

raise TypeError("Cannot handle this data type: %s, %s" % typekey)

TypeError: Cannot handle this data type: (1, 1, 12), |u1

请问你解决了吗?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

XueiuR commented 4 years ago

好的 感谢! 我的是python3.6,最后将25625612的向量截断为2562563了,然后可以运行,不知道会不会产生比较大的影响

VicZlq commented 4 years ago

好的!如果您跑出来了结果请告诉我一下修改方法!感谢!

赵柳

邮箱:18130039283@163.com |

签名由 网易邮箱大师 定制

On 06/27/2020 01:59, XueiuR wrote:

好的 感谢! 我的是python3.6,最后将25625612的向量截断为2562563了,然后可以运行,不知道会不会产生比较大的影响

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

XueiuR commented 4 years ago

我将/code/miscc/util.py文件中,第243行的PIL_att = Image.fromarray(np.uint8(one_map))修改为PIL_att = Image.fromarray(np.uint8(one_map)[:,:,0:3]),第251行的row.append(np.concatenate([one_map, middle_pad], 1))修改为row.append(np.concatenate([one_map[:,:,0:3], middle_pad], 1)),然后重新运行,就可以生成图片结果了。 因为我才刚开始接触GAN和CV,所以我不确定这种修改方式会不会对生成的结果产生什么影响。

XueiuR commented 4 years ago

我刚才也试了使用python2.7运行,效果会比经过我修改后使用python3生成的图片,从直观效果上看会好很多

Easonshow commented 4 years ago

您好,我最近也在研究attngan 也遇到了这个问题一直不知道怎么解决?方便加个好友吗 ,相互学习一下,QQ 1014976349

hs457681503 commented 4 years ago

我刚才也试了使用python2.7运行,效果会比经过我修改后使用python3生成的图片,从直观效果上看会好很多

你好,我也出现了这个问题,请问你是怎么改的代码呢?可以加我吗?qq是 457681503

savitha91 commented 4 years ago

Hi, regarding the issue, replace the line one_map = skimage.transform.pyramid_expand(one_map, sigma=20, upscale=vis_size // att_sze) with this one_map = skimage.transform.pyramid_expand(one_map, sigma=20, upscale=vis_size // att_sze, multichannel=True) inside the method utils.build_super_images2()