Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / samples / validation_app / SSDObjectDetectionProcessor.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <iostream>
8 #include <limits>
9 #include <map>
10 #include <memory>
11 #include <string>
12 #include <vector>
13 #include <list>
14 #include <utility>
15
16 #include "ObjectDetectionProcessor.hpp"
17
18 using namespace std;
19
20 class SSDObjectDetectionProcessor : public ObjectDetectionProcessor {
21 protected:
22     std::map<std::string, std::list<DetectedObject>> processResult(std::vector<std::string> files) {
23         std::map<std::string, std::list<DetectedObject>> detectedObjects;
24
25         std::string firstOutputName = this->outInfo.begin()->first;
26         const auto detectionOutArray = inferRequest.GetBlob(firstOutputName);
27         const float *box = detectionOutArray->buffer().as<float*>();
28
29         const size_t maxProposalCount = outputDims[1];
30         const size_t objectSize = outputDims[0];
31
32         for (size_t b = 0; b < batch; b++) {
33             string fn = files[b];
34             std::list<DetectedObject> dr = std::list<DetectedObject>();
35             detectedObjects.insert(std::pair<std::string, std::list<DetectedObject>>(fn, dr));
36         }
37
38         for (size_t i = 0; i < maxProposalCount; i++) {
39             float image_id = box[i * objectSize + 0];
40             float label = box[i * objectSize + 1];
41             float confidence = box[i * objectSize + 2];
42             float xmin = box[i * objectSize + 3] * inputDims[0];
43             float ymin = box[i * objectSize + 4] * inputDims[1];
44             float xmax = box[i * objectSize + 5] * inputDims[0];
45             float ymax = box[i * objectSize + 6] * inputDims[1];
46
47             if (image_id < 0 /* better than check == -1 */) {
48                 break;  // Finish
49             }
50
51             detectedObjects[files[static_cast<size_t>(image_id)]].push_back(
52                 DetectedObject(static_cast<int>(label), xmin, ymin, xmax, ymax, confidence));
53         }
54
55         return detectedObjects;
56     }
57
58 public:
59     SSDObjectDetectionProcessor(const std::string& flags_m, const std::string& flags_d, const std::string& flags_i, const std::string& subdir, int flags_b,
60             double threshold,
61             InferencePlugin plugin, CsvDumper& dumper,
62             const std::string& flags_a, const std::string& classes_list_file) :
63
64                 ObjectDetectionProcessor(flags_m, flags_d, flags_i, subdir, flags_b, threshold,
65                         plugin, dumper, flags_a, classes_list_file, PreprocessingOptions(false, ResizeCropPolicy::Resize), true) { }
66 };