Answers.Body: <p>The identity loss should already fulfill for what you're asking for, which means that if the problem is still there even with a strong weight for it then you should consider improving/cleaning up your data to remove the bias you observe.</p>
  <p>If you really don't like this idea, something close to what you're asking for are <a href="https://github.com/valerystrizh/pytorch-histogram-loss" rel="nofollow noreferrer">histogram based losses</a>, but be aware that they are mostly used in neural style transfer, so you will probably have to remove the identity loss to avoid conflicting losses and I wouldn't expect them to work as you think in preventing color biases, since they come from the data.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-04T10:33:07.937Z
Answers.LastActivityDate: 2022-04-04T10:33:07.937Z
Answers.UserDisplayName: Edoardo Guerriero
Body: <p>My neural network takes an image as an input and outputs another image. It's the generator of a cycleGAN.</p>
  <p>I would like to add (to the <code>discriminator loss</code>, the <code>cycle consistency loss</code> and the <code>identity loss</code>) a <code>colour consistency loss</code> i.e. i want the output image to globally have the same colours than the input image.</p>
  <p>Why? My problem is that the network &quot;tints&quot; my images too much in my opinion (a standard example is the following: my dataset has women that wear pink clothes more than men do and when i transform men into women, the GAN also transforms the clothes, and sort of adds a pink tint to the whole image). I know that adding this loss will encourage the network to &quot;not change anything&quot; though as any change would be a change in colours. <strong>Unless</strong> my loss looks at the averages of red, blue and green instead of looking at them pixel by pixel, which is what I'd like to go for.</p>
  <p>Not the main question but any thoughts on that are appreciated:
  any idea about how to implement it in Pytorch, or if it's already been implemented? Searches for colour consistency on GANs just give me GANs that take black and white photos and add colour to them.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-04T09:10:28.947Z
Comments.Text: Can you please put your **specific question** in the title? "Colour consistency loss neural networks" is not a question. If you're asking for code, that would be off-topic here.
Comments.UserDisplayName: nbro
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-04T09:23:55.137Z
Comments.Text: I'm asking if it makes sense and if there are some references of people that did it :) I edited my post thanks, sorry for not posting it correctly!
Comments.UserDisplayName: IHopeItWontBeAStupidQuestion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-04T09:27:35.193Z
Comments.Text: Ok, so you should edit your post to clarify that "Any idea about how to implement it in Pytorch, or if it's already been implemented?" is not your main question.
Comments.UserDisplayName: nbro
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-04T13:57:43.250Z
Comments.Text: Done! In the case that I'd want help on that specifically, stackoverflow is the stackexchange I should go to?
Comments.UserDisplayName: IHopeItWontBeAStupidQuestion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-04T14:22:41.420Z
Comments.Text: Yes, I think Stack Overflow would be a better option for programming questions.
Comments.UserDisplayName: nbro
Tags: <generative-adversarial-networks><pytorch><cycle-gan>
Title: Does a colour consistency loss in neural networks (cycleGAN) make sense?
UserDisplayName: IHopeItWontBeAStupidQuestion
ThreadText: # Does a colour consistency loss in neural networks (cycleGAN) make sense?
  
  (Asked by: username_0 on 2022-04-03)
  
  My neural network takes an image as an input and outputs another image. It's the generator of a cycleGAN.
  
  I would like to add (to the `discriminator loss`, the `cycle consistency loss` and the `identity loss`) a `colour consistency loss` i.e. i want the output image to globally have the same colours than the input image.
  
  Why? My problem is that the network "tints" my images too much in my opinion (a standard example is the following: my dataset has women that wear pink clothes more than men do and when i transform men into women, the GAN also transforms the clothes, and sort of adds a pink tint to the whole image). I know that adding this loss will encourage the network to "not change anything" though as any change would be a change in colours. **Unless** my loss looks at the averages of red, blue and green instead of looking at them pixel by pixel, which is what I'd like to go for.
  
  Not the main question but any thoughts on that are appreciated:
  any idea about how to implement it in Pytorch, or if it's already been implemented? Searches for colour consistency on GANs just give me GANs that take black and white photos and add colour to them.
  
  **Tags:** generative-adversarial-networks, pytorch, cycle-gan
  
  > **Comments:**
  > **username_1**: Can you please put your **specific question** in the title? "Colour consistency loss neural networks" is not a question. If you're asking for code, that would be off-topic here.  
  > **username_0**: I'm asking if it makes sense and if there are some references of people that did it :) I edited my post thanks, sorry for not posting it correctly!  
  > **username_1**: Ok, so you should edit your post to clarify that "Any idea about how to implement it in Pytorch, or if it's already been implemented?" is not your main question.  
  > **username_0**: Done! In the case that I'd want help on that specifically, stackoverflow is the stackexchange I should go to?  
  > **username_1**: Yes, I think Stack Overflow would be a better option for programming questions.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-04-04. Score: 2
  
  The identity loss should already fulfill for what you're asking for, which means that if the problem is still there even with a strong weight for it then you should consider improving/cleaning up your data to remove the bias you observe.
  
  If you really don't like this idea, something close to what you're asking for are [histogram based losses](https://github.com/valerystrizh/pytorch-histogram-loss), but be aware that they are mostly used in neural style transfer, so you will probably have to remove the identity loss to avoid conflicting losses and I wouldn't expect them to work as you think in preventing color biases, since they come from the data.
  
  
  ---
  
  