Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
VicZlq opened this issue Jun 20, 2020 · 9 comments
Open

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

VicZlq opened this issue Jun 20, 2020 · 9 comments

Comments

@VicZlq
Copy link

VicZlq commented Jun 20, 2020

您好,我在训练的时候,出现这个问题
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
Copy link

XueiuR commented Jun 26, 2020

我也遇到了同样的问题,环境是使用的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
Copy link
Author

VicZlq commented Jun 26, 2020 via email

@XueiuR
Copy link

XueiuR commented Jun 26, 2020

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

@VicZlq
Copy link
Author

VicZlq commented Jun 27, 2020 via email

@XueiuR
Copy link

XueiuR commented Jun 27, 2020

我将/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
Copy link

XueiuR commented Jun 27, 2020

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

@Easonshow
Copy link

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

@hs457681503
Copy link

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

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

@savitha91
Copy link

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants