def _make_noise_input(self, init):
"""
Creates an initial input (generated) image.
"""
# specify dimensions and create grid in Fourier domain
dims = tuple(self.net.blobs["data"].data.shape[2:]) + \
(self.net.blobs["data"].data.shape[1],)
grid = np.mgrid[0:dims[0], 0:dims[1]]
# create frequency representation for pink noise
Sf = (grid[0] - (dims[0] - 1) / 2.0) ** 2 + \
(grid[1] - (dims[1] - 1) / 2.0) ** 2
Sf[np.where(Sf == 0)] = 1
Sf = np.sqrt(Sf)
Sf = np.dstack((Sf ** int(init),) * dims[2])
# apply ifft to create pink noise and normalize
ifft_kernel = np.cos(2 * np.pi * np.random.randn(*dims)) + \
1j * np.sin(2 * np.pi * np.random.randn(*dims))
img_noise = np.abs(ifftn(Sf * ifft_kernel))
img_noise -= img_noise.min()
img_noise /= img_noise.max()
# preprocess the pink noise image
x0 = self.transformer.preprocess("data", img_noise)
return x0
style_transfer.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录