In the document,

  
      pytorch.org
  
  
    

Template Class Dataset — PyTorch master documentation 4



  
  
    
    
  
  


get() return type is torch::data::Example<>. Example is a template with default types of 2 torch::Tensor.
template<typename  Data = Tensor, typename Target`  = Tensor>
Is there a way to customize the types? I would like get() to return
torch::data::Example<torch::Tensor, std::string>. If in my custom dataset, I define my get() as
torch::data::Example<torch::Tensor, std::string> get(size_t index) override;

the compiler complains
error: return type is neither identical to nor covariant with return type "torch::data::Example<at::Tensor, at::Tensor>" of overridden virtual function "torch::data::datasets::Dataset<Self, SingleExample>::get [with Self=CustomDataset, SingleExample=torch::data::Example<at::Tensor, at::Tensor>]"
      torch::data::Example<torch::Tensor, std::string> get(size_t index) override;