<p>With the limited information that you provide, this is the simplest solution (I assume that your generator creates images from noise such as the <a href="https://arxiv.org/abs/1406.2661" rel="nofollow noreferrer">original gans</a>):</p>
<pre class="lang-py prettyprint-override"><code>import torch

def get_data(batch_size, generator, latent_dim=512):
    z = torch.randn(batch_size, latent_dim)
    return genenerator(z)

def dataloader(batch_size, generator, iteration, latent_dim=512):
    for i in range(iteration):
        yield(get_data(batch_size, generator, latent_dim))

batch_size = 64
generator = GANs(...)
iteration = 100
latent_dim = 512

loader = dataloader(batch_size, generator, iteration, latent_dim)
for images in loader:
    # do something
</code></pre>
How to convert a generator to a Pytorch Dataloader?
<p>I have a generator that creates synthetic data. How can I convert this into a PyTorch dataloader?</p>