About converting from pytorch to C++ in looping over dataset

Hi, All

I have an inquiry on converting from pytorch to C++ in looping over dataset. The python code is;
unlabel_loader1 = DataLoader(self.unlabeled, batch_size = self.args.batch_size, shuffle=True, drop_last=True, num_workers = 4)
for (unlabel1, _label1) in unlabel_loader1:
batch_num += 1

I convert to C++ with libtorch as:
auto unlabel1 = torch::data::datasets::MNIST("/path/MNISTv2",
torch::data::datasets::MNIST::Mode::kTrain).map(
torch::data::transforms::Normalize<>(0.13707, 0.3081)).map(torch::data::transforms::Stack<>());
auto unlabel_loader1 = torch::data::make_data_loadertorch::data::samplers::SequentialSampler(unlabel1, torch::data::DataLoaderOptions().batch_size(args.batch_size).workers(4).drop_last(
true));

But I am not sure how shall I translate " for (unlabel1, _label1) in unlabel_loader1:" into C++.
Any comments are appreciated.

Thanks in advance.

This tutorial gives you an end-to-end example of the C++ Frontend using the MNIST dataset.

Thanks for the comments.

The pytorch code is:
" unlabel_loader1 = DataLoader(self.unlabeled, batch_size = self.args.batch_size, shuffle=True, drop_last=True, num_workers = 4)
unlabel_loader2 = DataLoader(self.unlabeled, batch_size = self.args.batch_size, shuffle=True, drop_last=True, num_workers = 4).iter()
label_loader = DataLoader(tile_labeled, batch_size = self.args.batch_size, shuffle=True, drop_last=True, num_workers = 4).iter()

        batch_num = 0
        for (unlabel1, _label1) in unlabel_loader1:
            batch_num += 1
            unlabel2, _label2 = unlabel_loader2.next()
            x, y = label_loader.next() "

I write it this way in C++:

int batch_num = 0;
auto udata_loader = unlabel_loader1->begin();
auto udata_loader2= unlabel_loader2->begin();
auto ldata_loader = label_loader->begin();
for (int idx = 0; idx < args.iter; idx++)
{
std::cout << “process in the iter loop” << std::endl;
batch_num = batch_num + 1;

            if (udata_loader == unlabel_loader1->end())
                udata_loader = unlabel_loader1->begin();
            torch::Tensor unlabel1 = udata_loader->data;

            ++udata_loader;
            if (udata_loader2 == unlabel_loader2->end())
                udata_loader2 = unlabel_loader2->begin();
            torch::Tensor unlabel2 = udata_loader2->data;

            ++udata_loader2;
            if (ldata_loader == label_loader->end())
                ldata_loader = label_loader->begin();
            torch::Tensor x = ldata_loader->data;
            torch::Tensor y = ldata_loader->target;

            ++ldata_loader;

May I ask if this translation is accurate please ? Thanks.