This repo contains the source code in my personal column (https://zhuanlan.zhihu.com/zhaoyeyu), implemented using Python 3.6. Including Natural Language Processing and Computer Vision projects, such as text generation, machine translation, deep convolution GAN and other actual combat code.
def _single_style_loss(self, a, g):
###############################
## TO DO
N = a.shape[3]
M = a.shape[1] * a.shape[2]
gram_a = self._gram_matrix(a, N, M)
gram_g = self._gram_matrix(g, N, M)
return tf.reduce_sum((gram_g - gram_a) ** 2) / (4 * (N ** 2) * (M ** 2))
在这里,a是style image的feature representation, g是generated image的feature representation。在计算generated image的格拉姆矩阵时候,调用了 self._gram_matrix(g, N, M)函数,但这里的输入N和M都是style image的数据。这样计算没有问题么?