当我将 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!