Fail to train cGAN - train_loader is not defined

heitorvc: <p>Hello everyone,</p>
<p>I’m working on a Conditional GAN to estimate flow field data in a porous medium (here is the link for the <a href="https://github.com/heitorvitorc/DL_Project/blob/main/flow_field_cGAN.ipynb" rel="noopener nofollow ugc">notebook</a>). In my research, I provide for the Generator a binary cropped mesh image (representing a section of  the porous medium), and it will learn to estimate the flow field in the black region as an output image. The Discriminator will then tell if the provided image is real or fake.  The model is still far from functional, as I’m struggling to generate new training data. I have the following case:</p>
<pre><code class="lang-auto">class adversarialModel(object):

    def __init__(self, num_epochs=500, samples=3, batch=5, betas=(0.5,0.5), g_lr = 0.001, d_lr = 0.001,

                 size = 64, data_path = './models', channels_img = 1, channels_noise =  64, features_g = 16,

                 features_d = 16, dataloader = train_loader, transforms = None):

(...)
</code></pre>
<pre><code class="lang-auto"># Get mesh and velocity data paths

mesh_paths = glob.glob('./mesh_data/*.tif')

vel_paths = glob.glob('./vel_data/*.tif')

total_samples = len(mesh_paths)

train_size = 0.85

# Separate training samples

train_mesh_paths = mesh_paths[:int(total_samples*train_size)]

train_vel_paths = vel_paths[:int(total_samples*train_size)]
train_data = mesh_vel_dataset(train_mesh_paths, train_vel_paths, train=True)

train_loader = DataLoader(train_data, batch_size = 5, shuffle = True)

test_data = mesh_vel_dataset(test_mesh_paths, test_vel_paths, train=False)

test_loader = DataLoader(test_data, batch_size = 5, shuffle = False)

</code></pre>
<p>So now I need to train the model.</p>
<p><code>model = adversarialModel(num_epochs=100, dataloader = train_loader)</code></p>
<p>However, after I run this cell, I get the following error:<br>
Traceback (most recent call last):</p>
<pre><code class="lang-auto">&gt;   File "d:/deep_learning/Computer_Vision/Projeto/model_run_v2.py", line 133, in &lt;module&gt;
&gt;     class adversarialModel(object):
&gt;   File "d:/deep_learning/Computer_Vision/Projeto/model_run_v2.py", line 136, in adversarialModel
&gt;     features_d = 16, dataloader = train_loader, transforms = None):
&gt; NameError: name 'train_loader' is not defined
</code></pre>
<p>This looks like a simple error, but I’m stuck in it for a week. It seems that the training data is not defined, but as I inspect the variable, It looks completely fine. If I am not asking for much, I would appreciate if someone could help me with that.</p>

mathematics: <p>May be You’ve defined not <code>train_loader</code>  in model arugment. I think   you shouldn’t put train_loader directly in argument,before <code>train_loader</code> was defined , so only data_loader would be fine.</p>
<aside class="quote no-group quote-modified" data-username="heitorvc" data-post="1" data-topic="100938">
<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/heitorvc/48/30385_2.png" class="avatar"> heitorvc:</div>
<blockquote>
<pre><code class="lang-auto">        ....         features_d = 16, dataloader, transforms = None):
</code></pre>
</blockquote>
</aside>

heitorvc: <p>Thanks for the reply, you have fixed my one-week-lasting error!</p>