Learn feasibility constraints in GANs

I am currently experimenting with a W-GAN, my objective is to generate a particular type of 2-bit images (4 possible colors, let’s say: black, dark gray, light gray, white). I have a reasonable number of samples in my training dataset, and the W-GAN performs quite reasonably, i.e., it generates images that look quite similar to the examples.
On the other hand, I have some constraints on my images: for example, the number of white pixels has to be exactly one. My approach to make the generator learn this constraint was to add a “rule” in the discriminator, i.e., count the number of white pixels in the input image and if it’s not “legal”, then output 0, as in “certainly fake”.
The problem is that, by doing so, the discriminator and the generator’s losses diverge immediately, which means that I’m doing something wrong :slight_smile:

What’s a better approach to enforce this type of feasibility constraints?

you can re-design your loss by taking this constraint into consideration. e,g, the constraint could be a regularizer.