Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / samples / validation_app / classification_set_generator.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <list>
8 #include <map>
9 #include <vector>
10 #include <string>
11 #include <memory>
12 #include <utility>
13
14 /**
15  * @class SetGenerator
16  * @brief A SetGenerator provides utility functions to read labels and create a multimap of images for pre-processing
17  */
18 class ClassificationSetGenerator {
19     std::map<std::string, int> _classes;
20
21     std::vector<std::pair<int, std::string>> validationMapFromTxt(const std::string& file);
22     std::vector<std::pair<int, std::string>> validationMapFromFolder(const std::string& dir);
23
24 protected:
25     std::list<std::string> getDirContents(const std::string& dir, bool includePath = true);
26
27
28 public:
29     /**
30      * @brief Reads file with a list of classes names. Every found line is considered to be
31      *        a class name with ID equal to line number - 1 (zero based)
32      * @param labels - name of a file with labels
33      * @return <class name, ID> map
34      */
35     std::map<std::string, int> readLabels(const std::string& labels);
36
37     /**
38      * @brief Creates a  vector of pairs <class id, path to picture> to reflect
39      * images data reflected by path provided
40      * @param path - can be a .txt file or a folder. In case of file parses it assuming format is
41      *               relative_path_from_folder_with_txt_extension/image_id. In case of folder searches
42      *               all subfolders which are named exactly like known classes and adds all containing
43      *               files to a map with ID corresponding to subfolder name
44      * @return vector of pairs {ID: IMAGEPATH} describing all found images. In case folder path was
45      *         provided and no class names are known returns empty map
46      */
47     std::vector<std::pair<int, std::string>> getValidationMap(const std::string& path);
48 };