ProGamerGov / neural-style-pt

PyTorch implementation of neural style transfer algorithm
MIT License
834 stars 178 forks source link

Feature: Play with Covariance instead of Gram? #11

Open ghost opened 5 years ago

ghost commented 5 years ago

I watched a presentation from Artomatix and they have some arguments for using a covariance loss instead of a gram loss. You can flip between the two (I think it's correct..) by doing

class GramMatrix(nn.Module):

    def forward(self, input):
        B, C, H, W = input.size()
        x_flat = input.view(C, H * W)

        #Add this for covariance loss
        x_flat = x_flat - x_flat.mean(1).unsqueeze(1)

        return torch.mm(x_flat, x_flat.t())

I didn't experiment with it much, but using the default content/style at 1024, you get these: Gram Loss: gram

Covariance Loss: cov

I wouldn't say it's better, but it is interesting it adds more texture to the sky. Might have some utility for more textured styles?

Thoughts?

p.s. Nice implementation! Happy there's a true to jcjohson, cuda 10, pytorch impl