NELSONZHAO/zhihu

image_style_transfer中,格拉姆矩阵的疑惑

charmpeng opened this issue · 0 comments

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的数据。这样计算没有问题么?