How to downsample an image before feeding to generator

Xanthan: <p>Hello people, I’m fairly new to pytorch and I’m stuck with a problem.</p>
<p>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 <a href="https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html" rel="noopener nofollow ugc">this</a> tutorial notebook of pytorch dcgan as your reference to work.</p>
<p>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.</p>
<p>Any thoughts? Any help will be good.<br>
Thankyou.</p>

ptrblck: <aside class="quote no-group" data-username="Xanthan" data-post="1" data-topic="119185">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/xanthan/48/37484_2.png" class="avatar"> Xanthan:</div>
<blockquote>
<p>So how can I input an image to this so that the image gets downsampled to (batch_size, 100,1, 1) size</p>
</blockquote>
</aside>
<p>You could try to reshape the image into this shape, but might need to change the size of <code>dim1</code> depending on the input image shape.</p>
<aside class="quote no-group" data-username="Xanthan" data-post="1" data-topic="119185">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/xanthan/48/37484_2.png" class="avatar"> Xanthan:</div>
<blockquote>
<p>(so this would be the latent vector representation of this image)</p>
</blockquote>
</aside>
<p>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?</p>

Xanthan: <p>hello <a class="mention" href="/u/ptrblck">@ptrblck</a>. Firstly, thanks for replying.</p>
<aside class="quote no-group" data-username="ptrblck" data-post="2" data-topic="119185">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>You could try to reshape the image into this shape, but might need to change the size of <code>dim1</code> depending on the input image shape.</p>
</blockquote>
</aside>
<p>I think this won’t work as I want the generator to re-create that image.</p>
<aside class="quote no-group" data-username="ptrblck" data-post="2" data-topic="119185">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>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?</p>
</blockquote>
</aside>
<p>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?<br>
To give you more calrity, my application requires me to input the image inside the generator, like people do in <a href="https://phillipi.github.io/pix2pix/images/teaser_v3.png" rel="noopener nofollow ugc">these</a> applications.</p>

ptrblck: <p>Your use case sounds similar to the pix2pix models so you could check some implementations and reuse the logic for the generator.</p>