Help on read in MNIST dataset in label and data in libtorch

HI, All

I would like to read in libtorch with MNIST dataset, where the ptorch code is doing
raw_dataset = datasets.MNIST(’…/data’, train=True, download=True,
perm = np.random.permutation(raw_dataset.len())
for i in range(raw_dataset.len()):
datum, label = raw_dataset.getitem(perm[i])

In libtorch code, I write:
auto raw_dataset= torch::data::datasets::MNIST("…/data").map(torch::data::transforms::Normalize<>(0.13707,0.3081)).map(torch::data::transforms::Stack<>());

torch::Tensor perm=torch::randperm(sizeof(raw_dataset));

for (int i=0; i<sizeof(raw_dataset);i++)
torch::Tensor datum=raw_dataset.get_batch(perm([i])).data;
torch::Tensor label1=raw_dataset.get_batch(perm([i])).target;
//torch::Tensor datum=raw_dataset.targets;

I get the error “expected body of lambda expression” in (perm[i]), any suggestions to fix it please ?
Thanks a lot .

Much appreciated.

Hi, your code is perm([i]), you should use perm[i] in c++, no bracket. Can u try?

Thanks. That works.

Another inquiry is about:
return Tensordataset=(torch.FloatTensor(np.array(data)), torch.LongTensor(np.array(labels)))

I convert it in C++


No member named Floattensor

Any suggestion to modify that please ?

Thanks a lot.