How to downsample an image before feeding to generator

Hello people, I’m fairly new to pytorch and I’m stuck with a problem.

I want to input an image into the generator of a DCGAN instead of a noise vector (the reason for this I have mentioned below). You may take this tutorial notebook of pytorch dcgan as your reference to work.

As you can see that the generator accepts an input of a latent vector of size: (batch_size, 100,1, 1). So how can I input an image to this so that the image gets downsampled to (batch_size, 100,1, 1) size (so this would be the latent vector representation of this image) and so the generator tries to generate that image back.

Any thoughts? Any help will be good.
Thankyou.

You could try to reshape the image into this shape, but might need to change the size of dim1 depending on the input image shape.

This wouldn’t be the case, if you are reshaping the input (my previous suggestion), so I assume you want to train another model to create the latent representation for each image and feed these representations to the DCGAN in another step?

hello @ptrblck. Firstly, thanks for replying.

I think this won’t work as I want the generator to re-create that image.

umm…yes, but if possible I want to incorporate that feature in the same model by modifications/additions. So my main question was, how should I do that? Should I use convolution layers to achieve that or is there an another method that people use?
To give you more calrity, my application requires me to input the image inside the generator, like people do in these applications.

Your use case sounds similar to the pix2pix models so you could check some implementations and reuse the logic for the generator.