dataset_generator.h
Go to the documentation of this file.
1 /*
2 * ECVL - European Computer Vision Library
3 * Version: 0.3.4
4 * copyright (c) 2021, Università degli Studi di Modena e Reggio Emilia (UNIMORE), AImageLab
5 * Authors:
6 * Costantino Grana (costantino.grana@unimore.it)
7 * Federico Bolelli (federico.bolelli@unimore.it)
8 * Michele Cancilla (michele.cancilla@unimore.it)
9 * Laura Canalini (laura.canalini@unimore.it)
10 * Stefano Allegretti (stefano.allegretti@unimore.it)
11 * All rights reserved.
12 */
13 
14 #ifndef ECVL_DATASET_GENERATOR_H_
15 #define ECVL_DATASET_GENERATOR_H_
16 
17 #include <ecvl/core/filesystem.h>
18 #include <ecvl/dataset_parser.h>
19 
20 namespace ecvl
21 {
27 {
28 public:
29  const filesystem::path dataset_root_directory_;
30  std::vector<std::string> splits_;
31  std::vector<int> num_samples_;
38  GenerateDataset(const filesystem::path& dataset_root_directory) :
39  dataset_root_directory_(dataset_root_directory)
40  {
41  for (auto& p : filesystem::directory_iterator(dataset_root_directory_)) {
42  std::string tmp = p.path().stem().string();
43 
44  // Check if split folders exist
45  if (tmp == "training" || tmp == "validation" || tmp == "test") {
46  splits_.emplace_back(tmp);
47  }
48  }
49  num_samples_.resize(splits_.size());
50 
51  d_.name_ = dataset_root_directory_.stem().string();
52  d_.description_ = dataset_root_directory_.stem().string();
53  }
54 
55  virtual ~GenerateDataset() = default;
56 
61  void LoadImagesAndSplits();
62 
67  Dataset GetDataset() { return d_; }
68 
74  virtual int LoadSplitImages(const filesystem::path& split) = 0;
75 };
76 
89 {
90 public:
91  filesystem::path suffix_;
92  filesystem::path gt_name_;
101  GenerateSegmentationDataset(const filesystem::path& dataset_root_directory, filesystem::path suffix = "", filesystem::path gt_name = "") :
102  GenerateDataset{ dataset_root_directory },
103  suffix_{ suffix },
104  gt_name_{ gt_name }
105  {
107  }
108 
109  virtual int LoadSplitImages(const filesystem::path& split) override;
110 };
111 
122 {
123 public:
124 
131  GenerateClassificationDataset(const filesystem::path& dataset_root_directory) : GenerateDataset{ dataset_root_directory }
132  {
133  filesystem::path tmp;
134 
135  if (splits_.empty()) {
137  }
138  else {
139  // use the first split available to list all the classes
140  tmp = dataset_root_directory_ / splits_[0];
141  }
142 
143  for (auto& p : filesystem::directory_iterator(tmp)) {
144  if (filesystem::is_directory(p.path())) {
145  d_.classes_.push_back(p.path().stem().string());
146  }
147  }
148 
150  }
151 
152  virtual int LoadSplitImages(const filesystem::path& split) override;
153 };
154 } // namespace ecvl
155 
156 #endif // ECVL_DATASET_GENERATOR_H_
void LoadImagesAndSplits()
Call LoadSplitImages and load the splits with indexes of corresponding images.
GenerateClassificationDataset(const filesystem::path &dataset_root_directory)
GenerateClassificationDataset constructor.
std::vector< std::string > classes_
Vector with all the classes available in the Dataset.
std::string description_
Description of the Dataset.
virtual int LoadSplitImages(const filesystem::path &split) override
Load the path of images and labels of the specified split.
GenerateSegmentationDataset(const filesystem::path &dataset_root_directory, filesystem::path suffix="", filesystem::path gt_name="")
GenerateSegmentationDataset constructor.
Abstract class which fill the dataset object with name and description, features common to all types ...
filesystem::path gt_name_
path containing the ground truth name for images that share the same ground truth
virtual int LoadSplitImages(const filesystem::path &split)=0
Load the path of images and labels of the specified split.
std::vector< std::string > splits_
vector containing the splits found in the dataset directory, if present
const filesystem::path dataset_root_directory_
path containing the root directory of the dataset
filesystem::path suffix_
path containing the suffix or extension of ground truth images
ecvl::Dataset d_
Dataset object to fill.
Dataset GetDataset()
Return the Dataset object obtained from the directory structure.
std::vector< int > num_samples_
vector containing the number of samples for each split
virtual ~GenerateDataset()=default
GenerateDataset(const filesystem::path &dataset_root_directory)
GenerateDataset constructor.
std::string name_
Name of the Dataset.
Generate an ecvl::Dataset from a directory tree for a segmentation task.
DeepHealth Dataset.
Generate an ecvl::Dataset from a directory tree for a classification task.
virtual int LoadSplitImages(const filesystem::path &split) override
Load the path of images and labels of the specified split.