Deeper DCGAN with AE stabilizer - AEGeAN

username: tymokvo
cooked: <p>Hi All,</p>
<p>Just thought I’d share a project that I finished recently. Uses a very deep DCGAN and parallel training as an autoencoder to generate large images pretty reliably with some interesting results. Seems to avoid mode collapse/recover from it better than a regular gan.</p>
<p>I also have a version that generates at 512x512 which is a lot lighter on memory that I can add if anyone is interested.</p>
<p>If something is broken, post an issue and I’ll try to fix it.</p>
<p>Enjoy!</p>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">
      <a href="https://github.com/tymokvo/AEGeAN" target="_blank" rel="nofollow noopener">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars3.githubusercontent.com/u/12144028?s=400&amp;v=4" class="thumbnail onebox-avatar" width="400" height="400">

<h3><a href="https://github.com/tymokvo/AEGeAN" target="_blank" rel="nofollow noopener">tymokvo/AEGeAN</a></h3>

<p>Deeper DCGAN with AE stabilization. Contribute to tymokvo/AEGeAN development by creating an account on GitHub.</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


username: smth
cooked: <p>Thanks for sharing Tyler. This is pretty cool. It reminds me of <a href="https://arxiv.org/abs/1609.03126">EBGAN</a> which has an autoencoding GAN formulation.</p>

username: thesix
cooked: <p>Hi there,</p>
<p>I’m quite new to mytorch and machine learning.  Still I tried this net and got nowhere.  All it produced were darkish images that became brighter over time (100 epochs) but no useful images were produced.  The image here is a downsampled version of the last <code>fake_samples.png</code></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/4/49b6253818ac67eeaedf03c91678e55ab9b36ee5.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/49b6253818ac67eeaedf03c91678e55ab9b36ee5" title="fake_samples_epoch_99"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/4/49b6253818ac67eeaedf03c91678e55ab9b36ee5_2_500x500.jpeg" alt="fake_samples_epoch_99" data-base62-sha1="aw56cxab1WlbFtJNs1a16FM9YP3" width="500" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/4/49b6253818ac67eeaedf03c91678e55ab9b36ee5_2_500x500.jpeg, https://discuss.pytorch.org/uploads/default/original/2X/4/49b6253818ac67eeaedf03c91678e55ab9b36ee5.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/4/49b6253818ac67eeaedf03c91678e55ab9b36ee5.jpeg 2x" data-dominant-color="EFF1E3"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">fake_samples_epoch_99</span><span class="informations">512×512 113 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>My experiments with the original DCGAN are quite satisfying, but I’m looking for higher resolution output <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=12" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>
<p>I had to make some modifications before being able to run it without errors.  First thing I had to change was use the <code>dataset</code> construction from DCGAN:</p>
<pre><code class="lang-auto">dataset = transforms.Compose([
           transforms.Resize(image_size),
           transforms.CenterCrop(image_size),
           transforms.ToTensor(),
           transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
           ]))
</code></pre>
<p>Using the original construction of <code>dataset</code> resulted in this error:</p>
<pre><code class="lang-auto">/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py:1474: UserWarning: Using a target size (torch.Size([4, 3, 1024, 1365])) that is different to the input size (torch.Size([4, 3, 1024, 1024])) is deprecated. Please ensure they have the same size.
  "Please ensure they have the same size.".format(target.size(), input.size()))
Traceback (most recent call last):
  File "/root/code/AEGeAN/AEGeAN_run.py", line 161, in &lt;module&gt;
    reconstruction_loss = criterion(reconstructed, input)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/loss.py", line 433, in forward
    reduce=self.reduce)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py", line 1477, in binary_cross_entropy
    "!= input nelement ({})".format(target.nelement(), input.nelement()))
ValueError: Target and input must have the same number of elements. target nelement (16773120) != input nelement (12582912)
</code></pre>
<p>To get rid of some deprecation warnings I replaced all statements like <code>fake_samples_loss.data[0]</code> with <code>fake_samples_loss.item()</code> in the output.</p>
<p>I am running <code>pytorch 0.4.0</code> here.  My input for the tests consists of 500 images from <a href="http://mapillary.com" rel="noopener nofollow ugc">mapillary.com</a> (2048x1536).  Besides the above mentioned changes I only reduced <code>n_iter</code> to 100, reduced printing of status lines/saving of images and models and switched to .png images (.gif produced the same results btw.).</p>
<p>Maybe you can answer some of my questions:</p>
<ul>
<li>what type of images did you use as input?</li>
<li>what mistaks(s) am I making? <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=12" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></li>
<li>is this a problem or a warning that can be ignored for now:</li>
</ul>
<pre><code class="lang-auto">/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py:1474: UserWarning: Using a target size (torch.Size([4])) that is different to the input size (torch.Size([4, 1])) is deprecated. Please ensure they have the same size.
  "Please ensure they have the same size.".format(target.size(), input.size()))
</code></pre>
<p>Thanks for any hints!</p>

username: tymokvo
cooked: <p>Hi! Thanks for asking, and sorry you are having trouble.</p>
<p>Are you resizing the images to 1024x1024? One of the tradeoffs that this makes is that it is expecting only RGB images at that size. Thus, the network architecture is not very flexible.</p>
<p>Try using the <code>torchvision.transforms.Resize</code> with a size of <code>(1024, 1024)</code> on your input and see if that helps.</p>
<p>Also, I haven’t used this repo with the newer releases of PyTorch (I believe I developed it on 0.2 something) so you are bound to see some deprecation warnings.</p>
<p>Hope that helps! <img src="https://discuss.pytorch.org/images/emoji/apple/smile.png?v=6" title=":smile:" class="emoji" alt=":smile:"></p>

username: thesix
cooked: <p>Hi and thanks for replying,</p>
<aside class="quote no-group" data-username="tymokvo" data-post="4" data-topic="4386">
<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/tymokvo/48/9527_2.png" class="avatar"> tymokvo:</div>
<blockquote>
<p>Try using the <code>torchvision.transforms.Resize</code> with a size of <code>(1024, 1024)</code> on your input and see if that helps.</p>
</blockquote>
</aside>
<p>I thought using <code>transforms.CenterCrop(image_size)</code>  should do the trick;  but will try what you propose anyhow <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=12" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>

username: thesix
cooked: <p>Hi,</p>
<p>did what you suggested, but that didn’t alter the output <img src="https://discuss.pytorch.org/images/emoji/apple/cry.png?v=6" title=":cry:" class="emoji" alt=":cry:"></p>

username: tymokvo
cooked: <p>Can you post the errors that you are seeing? Looking at your original post again, it looks like you may be comparing images of different sizes in the loss function.</p>
<p>Hard to tell without seeing the exceptions, though.</p>

username: tomotake
cooked: <p>If you can add 512x512 version into github, it helps. Thank you. Great work</p>