DCGAN tutorial -> make D see only grayscale

I’ve been working through the DCGAN tutorial and want to work with new datasets. I’ve brought in a grayscale set of Lego images, and while I could do the sensible thing and figure out how to convert the network to operate with a single color channel, I realized it would be much funnier to make the Detector colorblind so that the Generator could get away with making psychedelic colorful Lego instead of this boring gray.

I’m having a heck of a time doing it though. I tried doing a manual averaging of the color channels, like such:

        with torch.no_grad():
            for f in fake:
                f[0] = (f[0] + f[1] + f[2]) / 3
                f[1] = f[0]
                f[2] = f[0]

between when the fakes are generated and when they’re passed along to D. But I get an error complaining that it’s noticed an anomaly despite the no_grad.

Is there an easier way to do this? Or a fix I can use to make it not break?

thanks!

Your idea sounds like a fun project! :slight_smile:
Try to avoid the inplace operations and create a new tensor via:

f2 = f1.mean(1, keepdim=True)

and pass f2 to the discriminator.

1 Like

Thanks! I used that and changed the D to just 1 color channel elsewhere and it worked!

The whole thing came out more uniformly pink-plaid than I expected :smiley:

Data:
lego-start

Result:

Result:
pinkplaidlego

As maybe all of you would’ve guessed, it picks a hue at random each time I train it. I was hoping for blobs of color left over from early inaccurate generation, but thus far it’s consistently one major color with that same stripey-grid plaid texture within.