data loader is not defined but I have imported it
This is a baseline model from github; I try to produce its result
dataloader.py, models.py have been put in the same direction with this scripts
from __future__ import print_function

import sys
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import torch.backends.cudnn as cudnn

import torchvision
import torchvision.transforms as transforms


import os
import sys
import time 
import argparse
import datetime

from torch.autograd import Variable

if __name__ == '__main__':
    import dataloader as dataloader
    import models as models

parser = argparse.ArgumentParser(description='PyTorch Clothing-1M Training')
parser.add_argument('--lr', default=0.0008, type=float, help='learning_rate')
parser.add_argument('--start_epoch', default=2, type=int)
parser.add_argument('--num_epochs', default=3, type=int)
parser.add_argument('--batch_size', default=32, type=int)
parser.add_argument('--optim_type', default='SGD')
parser.add_argument('--seed', default=7)
parser.add_argument('--gpuid', default=1, type=int)
parser.add_argument('--id', default='cross_entropy')
args = parser.parse_args()


# Training
def train(epoch):
    net.train()
    train_loss = 0
    correct = 0
    total = 0
    
    learning_rate = args.lr
    if epoch &gt; args.start_epoch:
        learning_rate=learning_rate/10        
        
    for param_group in optimizer.param_groups:
        param_group['lr'] = learning_rate

    print('\n=&gt; %s Training Epoch #%d, LR=%.4f' %(args.id,epoch, learning_rate))
    for batch_idx, (inputs, targets) in enumerate(train_loader):
        optimizer.zero_grad()
        inputs, targets = Variable(inputs), Variable(targets)
        outputs = net(inputs)               # Forward Propagation
        loss = criterion(outputs, targets)  # Loss
        loss.backward()  # Backward Propagation
        optimizer.step() # Optimizer update

        train_loss += loss.data[0]
        _, predicted = torch.max(outputs.data, 1)
        total += targets.size(0)
        correct += predicted.eq(targets.data).cpu().sum()

loader = dataloader.clothing_dataloader(batch_size=args.batch_size,num_workers=5,shuffle=True)
train_loader,val_loader = loader.run()

best_acc = 0

# Model
net = models.resnet50(pretrained=True)
net.fc = nn.Linear(2048,14)

criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(net.parameters(), lr=args.lr, momentum=0.9, weight_decay=1e-3)

for epoch in range(1, 1+args.num_epochs):
    train(epoch)  # raise error  !! (this is found by debugging)



This is the traceback
Traceback (most recent call last):
....  File &quot;d:\MLNT\MLNT\baseline.py&quot;, line 143, in &lt;module&gt;
    loader = dataloader.clothing_dataloader(batch_size=args.batch_size,num_workers=5,shuffle=True)
NameError: name 'dataloader' is not defined

during the debugging, &quot;dataloader&quot; and &quot;models&quot; exist as variables
[1]: https://i.stack.imgur.com/QAXvi.png
this is debugging traceback:
Exception has occurred: NameError       (note: full exception trace is shown but execution is paused at: &lt;module&gt;)
name 'dataloader' is not defined
  File &quot;D:\MLNT\MLNT\baseline.py&quot;, line 143, in &lt;module&gt;
    loader = dataloader.clothing_dataloader(batch_size=args.batch_size,num_workers=5,shuffle=True)
  File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt; (Current frame)


If you are importing this file in another one, the condition __name__ == '__main__' won't be True, as such both dataloader and models won't be imported into your file.
if __name__ == '__main__':
    import dataloader as dataloader
    import models as models

Instead, you could import both straight away as:
import dataloader as dataloader    
import models as models

