为什么 vgg.prepare() 方法会创建给定图像的 9 个副本?

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

当我将 vgg.prepare() 应用于下图时,我得到了这个结果:

我使用这行代码:

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

并获取由给定图像的 9 个副本组合而成的图像:

我终于明白你做了什么...... 唯一的错误是 .reshape.

因为图像是转置,而不是重塑,你必须重新转置恢复原图。

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!