Accessing one element from data_loader

hi,
I would like to get just one batch from the data_loader and push it through the model. I use the MNIST cpp example to make the data loader as:

auto train_loader = torch::data::make_data_loadertorch::data::samplers::SequentialSampler(std::move(train_dataset), batch_size);

But how do I access say the first or tenth batch? I don’t want to use the for loop iterator.

I tried train_loader.get(1) or train_loader.next() but they don’t work.

this may help you, just return 10 first sample from dataset

trainset = torchvision.datasets.MNIST(root=DtSetRootPath, train=True,download=True)
trainset.data=trainset.data[0:10,:,:,:]
trainloader = torch.utils.data.DataLoader(trainset, batch_size=10,shuffle=True,num_workers=0)

testset = torchvision.datasets.MNIST(root=DtSetRootPath, train=False,download=True)
testset.data=testset.data[0:10,]
testloader = torch.utils.data.DataLoader(testset, batch_size=10,shuffle=True, num_workers=0)

return trainloader,testloader

Thank you so much! This is very helpful. I also found a way to access trainload as

auto dat=train_loader->begin()
auto& eg2=dat->data;

I seem to have not interpreted train_loader’s type properly.
thanks,
Sushmita