Hi, I am searching for a way to load my images as I do it in Python. I just want to instantiate a DataLoader object and give a directory as a parameter. Why is it so complicated in C++? I found some code but it is kind of hard for me to understad it. Here it is…
#include <torch/torch.h>

// You can for example just read your data and directly store it as tensor.
torch::Tensor read_data(const std::string& loc)
{
    torch::Tensor tensor = ...

    // Here you need to get your data.

    return tensor;
};

class MyDataset : public torch::data::Dataset<MyDataset>
{
    private:
        torch::Tensor states_, labels_;

    public:
        explicit MyDataset(const std::string& loc_states, const std::string& loc_labels) 
            : states_(read_data(loc_states)),
              labels_(read_data(loc_labels) {   };

        torch::data::Example<> get(size_t index) override;
};

torch::data::Example<> MyDataset::get(size_t index)
{
    // You may for example also read in a .csv file that stores locations
    // to your data and then read in the data at this step. Be creative.
    return {states_[index], labels_[index]};
} 

What does this do? torch::data::Example<> get(size_t index) override; and where does the size_t index come from? Is it really necessary to build my own Dataset class? How do I push mit imaga data into the tensor in the read_data Method?
Thank you all