open-mmlab / mmgeneration

MMGeneration is a powerful toolkit for generative models, based on PyTorch and MMCV.
https://mmgeneration.readthedocs.io/en/latest/
Apache License 2.0
1.91k stars 230 forks source link

[Feature] Support of perceptual loss in style transfer #445

Open Taited opened 2 years ago

Taited commented 2 years ago

The manipulation of images could be seen as a conditioned generation. Therefore, the commonly used perceptual loss in style transfer is essential in some generation tasks. However, the mmgeneration only supports perceptual loss in the LPIP metric.

Is it possible to support the perceptual loss for style transfer as in the mmediting?

zengyh1900 commented 2 years ago

Please check this issue. Have we support perceptual loss in MMGeneration?

plyfager commented 2 years ago

Sure, it's an commonly used feature. We will add this to backlog. We will appreciate it a lot if you'd like to make a PR.

Taited commented 2 years ago

Thank you for your response. I am very willing to make a PR for adapting the perceptual loss from mmediting to mmgeneration. However, I have a few issues that need to discuss first.

  1. Should the perceptual loss be implemented within mmgen/models/losses/gen_auxiliary_loss.py? Or I should create a new file like mmgen/models/losses/perceptual_loss.py
  2. Should the class name PerceptualLoss be distinguished from the one in LPIP's PerceptualLoss? If it is true, what's your suggestions with the name?
plyfager commented 2 years ago

Here are my suggestion.

  1. You may implement the perceptual loss within mmgen/models/losses/gen_auxiliary_loss.py, then you can add it to your training config.
  2. Since perceptual loss here is mainly used to calculate PPL metric. You may just use the same class name.
plyfager commented 2 years ago
  1. In 1.x, we just remove PeceptualLoss class and use lpips package instead. You may also use this package for your class.
plyfager commented 2 years ago

Since now we are merging this repo into MMEditing. I also recommend you to try MMEdit-1.x and add this loss item there :).

Taited commented 2 years ago

Thank you for your suggestions.

I have a problem with the returned values. Typically, a loss module in mmgeneration returns one value. However, the PerceptualLoss often returns loss_percep and loss_style. Should the PerceptualLoss return a sum of these two losses or should I separate the loss_style into another loss module?