My task is to convert a working Pytorch neural network from Python to C++, but I’m not well versed in C++ so I’m learning as I go. I’m having an issue passing my DataLoader batch data into the model. Like examples show https://pytorch.org/cppdocs/frontend.html 2 I’m attempting to pass my batch data, “batch” into the model like so:

for (size_t epoch = 0; epoch <= num_epochs; ++epoch)
{
// Initialize running metrics
double loss1 = 0.0;
  for (auto& batch: *train_dataloader1)
  {
  	//std::cout << batch << "\n";

  	optimizer.zero_grad();

  	// Forward pass
  	auto outputs = model->forward(batch.data); // Error here
  }

}

The errors I get when I try to build are “E1866 attribute does not apply to any entity” and “C3867 ‘std::vector<SingleExample,std::allocator<_Ty>>::data’: non-standard syntax; use ‘&’ to create a pointer to member.” From these errors I’ve gathered (possibly incorrectly) that I need to pass in model->forward(batch.data()), but then I have three errors: “E1866 attribute does not apply to any entity”, "E0415 no suitable constructor exists to convert from “torch::data::TensorExample *” to “at::Tensor”, and finally “C2664 ‘at::Tensor Autoencoder1Impl::forward(at::Tensor)’: cannot convert argument 1 from ‘_Ty *’ to ‘at::Tensor’”
So I’m stuck because every example I’ve found is passing in the batch data like above, but the error instructs (to my best knowledge) to pass in the data differently. Any help is greatly appreciated!
Here is my model:

#include <torch/torch.h>
#include “Models.h”
Autoencoder1Impl::Autoencoder1Impl(int64_t num_vars, int64_t layer_size)
: encoder(num_vars, layer_size), decoder(layer_size, num_vars)
{
register_module(“encoder”, encoder);
register_module(“decoder”, decoder);
}
torch::Tensor Autoencoder1Impl::forward(torch::Tensor x)
{
x = torch::sigmoid(encoder->forward(x));
x = decoder->forward(x);
return x;
}