dataset_generator.h
Go to the documentation of this file.
1 /*
2 * ECVL - European Computer Vision Library
3 * Version: 1.0.0
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  if (filesystem::is_directory(p)) {
43  splits_.emplace_back(p.path().stem().string());
44  }
45  }
46  num_samples_.resize(splits_.size());
47 
48  d_.name_ = dataset_root_directory_.stem().string();
49  d_.description_ = dataset_root_directory_.stem().string();
50  }
51 
52  virtual ~GenerateDataset() = default;
53 
58  void LoadImagesAndSplits();
59 
64  Dataset GetDataset() { return d_; }
65 
71  virtual int LoadSplitImages(const filesystem::path& split) = 0;
72 };
73 
86 {
87 public:
88  filesystem::path suffix_;
89  filesystem::path gt_name_;
98  GenerateSegmentationDataset(const filesystem::path& dataset_root_directory, filesystem::path suffix = "", filesystem::path gt_name = "") :
99  GenerateDataset{ dataset_root_directory },
100  suffix_{ suffix },
101  gt_name_{ gt_name }
102  {
104  }
105 
106  virtual int LoadSplitImages(const filesystem::path& split) override;
107 };
108 
119 {
120 public:
121 
128  GenerateClassificationDataset(const filesystem::path& dataset_root_directory) : GenerateDataset{ dataset_root_directory }
129  {
130  filesystem::path tmp;
131 
132  if (splits_.empty()) {
134  }
135  else {
136  // use the first split available to list all the classes
137  tmp = dataset_root_directory_ / splits_[0];
138  }
139 
140  for (auto& p : filesystem::directory_iterator(tmp)) {
141  if (filesystem::is_directory(p.path())) {
142  d_.classes_.push_back(p.path().stem().string());
143  }
144  }
145 
147  }
148 
149  virtual int LoadSplitImages(const filesystem::path& split) override;
150 };
151 } // namespace ecvl
152 
153 #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.
Definition: any.h:69
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.