I am using libtorch.
I tried to train classification with my own image data.
I concern if I load plenty of images, it must cause a memory issue.
This is my custom dataloader.
class ClassificationDataset : public torch::data::Dataset<CustomDataset> {
private:
	std::vector<torch::Tensor> images, labels;
	vector<string> image_list;
	int num_classes;

public:
	ClassificationDataset(std::string path, int num_cls) {
		vector<torch::Tensor> label_t = vector<torch::Tensor>(num_cls);
		for (int i = 0; i < num_cls; i++)
		{
			auto image_path = path + "\\" + to_string(i) + "\\";
			auto images = get_files_inDirectory(image_path, "*.jpg");
			for(auto img : images)
			{
				image_list.push_back(image_path + "\\" + img);
				auto label = torch::tensor(i);
				labels.push_back(label);
			}
		}
		images = process_images(image_list);
		
		num_classes = num_cls;
	};

	torch::data::Example<torch::Tensor, torch::Tensor> get(size_t index) override {
		torch::Tensor sample_img = images.at(index);
		torch::Tensor sample_label = labels.at(index);
		torch::data::Example<torch::Tensor, torch::Tensor> value{ sample_img, sample_label };
		return value;
	};

	torch::optional<size_t> size() const override {
		return labels.size();
	};

	std::vector<torch::Tensor> process_images(std::vector<std::string> list_images)
	{
		std::vector<torch::Tensor> tensor_images;
		for (auto image : list_images)
		{
			cv::Mat img = cv::imread(image);
			cv::resize(img, img, cv::Size(224, 224));

			torch::Tensor tensor_image = torch::from_blob(img.data, { img.rows, img.cols,3 }, at::kByte);
			tensor_image = tensor_image.toType(at::kFloat);
			tensor_image = tensor_image.div_(255);
			tensor_image = tensor_image.permute({ 2, 0, 1 });
			
			tensor_images.push_back(tensor_image);
		}

		return tensor_images;
	}

Then I use this dataloader.
        auto dataset_train = ClassificationDataset("D:\\train", num_classes).map(torch::data::transforms::Stack<>());
		auto data_loader_train = torch::data::make_data_loader(std::move(dataset_train), torch::data::DataLoaderOptions().batch_size(5).workers(4));

		auto dataset_val = ClassificationDataset("D:\\val", num_classes).map(torch::data::transforms::Stack<>());
		auto data_loader_val = torch::data::make_data_loader(std::move(dataset_val), torch::data::DataLoaderOptions().batch_size(2).workers(4));

If I use my code with 10000 images of train data, does it makes memory issue? right?
If it does, how can I fix it?