I’m a newbie of pytorch.
here is my load data function,
def get_data_loader(
        root,
        transform=None,
        target_transform=None,
        batch_size=32,
        shuffle=True,
        drop_last=False,
        **kwargs):
    """load data."""
    data = torchvision.datasets.ImageFolder(
        root=root,
        transform=transform,
        target_transform=target_transform)

    data_loader = torch.utils.data.DataLoader(
        data,
        batch_size=batch_size,
        shuffle=shuffle,
        num_workers=0,
        drop_last=drop_last,
        **kwargs)

    # tag 1
    # to device 
    data_loader = [[x[0].to(device), x[1].to(device)] for x in data_loader]
    # tag 2
    data_loader = cycle(data_loader)

    printsln("n_sample: %d, n_class: %d" % (len(data), len(data.classes)))
    return data_loader, data.classes

and this is my training iteration code,
    for i in range(20000):
        # train iteration
        optimizer = lr_schedule.inv_lr_scheduler(param_lr, optimizer, i, **schedule_param)
        optimizer.zero_grad()

        # tag 3
        if use_cycle:
            inputs_source, labels_source = next(iter_source)
        else:
            # not use cycle
            if i % len_train_source == 0:
                iter_source = iter(data_loader_source)

            inputs_source, labels_source = iter_source.next()

        # tag 4
        inputs_source, inputs_target = Variable(inputs_source).cuda(), Variable(inputs_target).cuda()

I just use cycleto make infinite iteration(tag 2, tag 3), but I get different result about use_cycle, it decrese my result.
Another, I preload data  in get_data_loader to GPU(tag 1), not in iteration load batch_data to GPU(tag 4), it will bosting running efficient, decrese running time, but I still get different result(decrese score).
I find some tutorail code, rarely use cycle to make infinite iteration, and no one load data to GPU without iteration training.
waiting for some indicate, thanks.