Why does vgg.prepare() method create 9 copies of the given image?

浪尽此生 提交于 2019-12-11 04:24:45

问题


I get this result when I apply vgg.prepare() to the following image:

I use this line of code:

Image.fromarray(np.uint8(vgg.prepare(pep).reshape(224,224,3)))

And get an image which is combined of 9 copies of the given image:


回答1:


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!


来源:https://stackoverflow.com/questions/53257608/why-does-vgg-prepare-method-create-9-copies-of-the-given-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!