Override get() function to return tensor at location index
| 21 | } |
| 22 | // Override get() function to return tensor at location index |
| 23 | torch::data::Example<> get(size_t index) override{ |
| 24 | std::string image_path = image_paths.at(index); |
| 25 | cv::Mat image = cv::imread(image_path); |
| 26 | cv::resize(image, image, cv::Size(224, 224)); |
| 27 | int label = labels.at(index); |
| 28 | torch::Tensor img_tensor = torch::from_blob(image.data, { image.rows, image.cols, 3 }, torch::kByte).permute({ 2, 0, 1 }); // Channels x Height x Width |
| 29 | torch::Tensor label_tensor = torch::full({ 1 }, label); |
| 30 | return {img_tensor.clone(), label_tensor.clone()}; |
| 31 | } |
| 32 | // Return the length of data |
| 33 | torch::optional<size_t> size() const override { |
| 34 | return image_paths.size(); |
nothing calls this directly
no outgoing calls
no test coverage detected