TypeError: Cannot handle this data type: (1, 1, 28),

TypeError: Cannot handle this data type: (1, 1, 28),

PIL和numpy相互转换方式如下:

from PIL import Image#PIL image转成numpy
np_img = np.asarray(PIL_img)  #参数时PIL类型的图片
或 
np_img = np.array(PIL_img)#将array准成PIL image
Image.fromarray(np.uint8(np_img))

但是直接用Image.fromarray(np.uint8(data))转换会报错:TypeError: Cannot handle this data type: (1, 1, 28), |u1,为啥啊,我哭了,在网上搜了一圈也没找到答案,然后我从可以转换成功的代码入手,终于发现问题了,太难了也!
原来,PIL需要的格式是(W,H,C),而SVHN数据集的格式是(C,W,H)所以又要进行转换了,把(C,W,H)变为(W,H,C):

img.transpose(1,2,0)

然后,就可以愉快的转换了!

发布者:admin,转转请注明出处:http://www.yc00.com/news/1696794516a784591.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信