为什么vgg.prepare()方法创建给定图像的9个副本? [英] Why does vgg.prepare() method create 9 copies of the given image?
本文介绍了为什么vgg.prepare()方法创建给定图像的9个副本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将vgg.prepare()应用于以下图像时,会得到以下结果:
I get this result when I apply vgg.prepare() to the following image:
我使用以下代码行:
Image.fromarray(np.uint8(vgg.prepare(pep).reshape(224,224,3)))
并获得包含给定图像的9个副本的图像:
And get an image which is combined of 9 copies of the given image:
推荐答案
我终于明白了你的所作所为...
唯一的错误是.reshape
.
I finally got what you did...
the only mistake is .reshape
.
由于图像是转置的,而不是重塑的,因此必须重新转置才能恢复原始图像.
Because the image is transposed, not reshaped, you have to re-transpose to restore the original image.
pep = pep.transpose((1, 2, 0)) # transpose
pep += [103.939, 116.779, 123.68] # un-normalize
pep = pep.astype(np.uint8) # revert dtype
pep = np.flip(pep, axis=2) # BGR -> RGB
PIL_image = Image.fromarray(pep) # finally got the original!
这篇关于为什么vgg.prepare()方法创建给定图像的9个副本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文