TheoriginalMMM / conditional-GAN-pix2pix

0 stars 0 forks source link

Multiclass semantic segmantation with GAN-pix2pix #2

Closed ceydahzl closed 8 months ago

ceydahzl commented 9 months ago

First of all, I congratulate you for your work. I want to try your work for multiclass segmentation, but I can't find what to do to change the BCEloss function you use. Can you help with this?

TheoriginalMMM commented 8 months ago

Hello and thank you for your kind words about this work!

To adapt our Pix2Pix GAN for multiclass semantic segmentation, please follow these steps:

  1. Instance Normalization: Replace nn.BatchNorm2d with nn.InstanceNorm2d in the CNNBlock (discriminator) and Block (generator) classes to improve training stability.
  2. Multiclass Loss Function: Switch the generator's loss function to CrossEntropyLoss, which is suitable for multiclass tasks. Adjust the final layer of the generator to have a number of channels equal to the number of classes in your task.
  3. Output Dimensions: Ensure that the generator's output has one channel for each segmentation class.
  4. Training: Continue using BCELoss for the discriminator. For the generator, use CrossEntropyLoss for the segmentation maps, possibly in combination with L1Loss for regularization.
  5. Data Preparation: Your data should be prepared for multiclass segmentation, with each pixel in the segmentation masks correctly labeled according to the class index.

I hope these guidelines help you in your multiclass segmentation project. Please don't hesitate to get back to me if you have any more questions or need further assistance.

Good luck with your project!