Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / ie_preprocess_data.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <map>
8 #include <string>
9 #include <memory>
10
11 #include "ie_blob.h"
12 #include "ie_input_info.hpp"
13 #include "ie_profiling.hpp"
14
15 namespace InferenceEngine {
16
17 class PreprocEngine;
18
19 /**
20  * @brief This class stores pre-process information for exact input
21  */
22 class INFERENCE_ENGINE_API_CLASS(PreProcessData) {
23     /**
24      * @brief ROI blob.
25      */
26     Blob::Ptr _roiBlob = nullptr;
27     Blob::Ptr _tmp1 = nullptr;
28     Blob::Ptr _tmp2 = nullptr;
29
30     /**
31      * @brief Pointer-to-implementation (PIMPL) hiding preprocessing implementation details.
32      * BEWARE! Will be shared among copies!
33      */
34     std::shared_ptr<PreprocEngine> _preproc;
35
36     InferenceEngine::ProfilingTask perf_resize {"Resize"};
37     InferenceEngine::ProfilingTask perf_reorder_before {"Reorder before"};
38     InferenceEngine::ProfilingTask perf_reorder_after {"Reorder after"};
39     InferenceEngine::ProfilingTask perf_preprocessing {"Preprocessing"};
40
41 public:
42     /**
43      * @brief Sets ROI blob to be resized and placed to the default input blob during pre-processing.
44      * @param blob ROI blob.
45      */
46     void setRoiBlob(const Blob::Ptr &blob);
47
48     /**
49      * @brief Gets pointer to the ROI blob used for a given input.
50      * @return Blob pointer.
51      */
52     Blob::Ptr getRoiBlob() const;
53
54     /**
55      * @brief Executes input pre-processing with a given resize algorithm.
56      * @param outBlob pre-processed output blob to be used for inference.
57      * @param algorithm resize algorithm.
58      * @param serial disable OpenMP threading if the value set to true.
59      * @param batchSize batch size for pre-processing.
60      */
61     void execute(Blob::Ptr &outBlob, const ResizeAlgorithm &algorithm, bool serial,
62                  int batchSize = -1);
63
64     static void isApplicable(const Blob::Ptr &src, const Blob::Ptr &dst);
65 };
66
67 //----------------------------------------------------------------------
68 //
69 // Implementation-internal types and functions and macros
70 //
71 //----------------------------------------------------------------------
72
73 namespace Resize {
74
75 static inline uint8_t saturateU32toU8(uint32_t v) {
76     return static_cast<uint8_t>(v > UINT8_MAX ? UINT8_MAX : v);
77 }
78
79 void resize_bilinear_u8(const Blob::Ptr inBlob, Blob::Ptr outBlob, uint8_t* buffer);
80
81 void resize_area_u8_downscale(const Blob::Ptr inBlob, Blob::Ptr outBlob, uint8_t* buffer);
82
83 int getResizeAreaTabSize(int dst_go, int ssize, int dsize, float scale);
84
85 void computeResizeAreaTab(int src_go, int dst_go, int ssize, int dsize, float scale,
86                           uint16_t* si, uint16_t* alpha, int max_count);
87
88 void generate_alpha_and_id_arrays(int x_max_count, int dcols, const uint16_t* xalpha, uint16_t* xsi,
89                                   uint16_t** alpha, uint16_t** sxid);
90
91 enum BorderType {
92     BORDER_CONSTANT  =  0,
93     BORDER_REPLICATE =  1,
94 };
95
96 struct Border {
97     BorderType  type;
98     int32_t     value;
99 };
100
101 }  // namespace Resize
102
103 //----------------------------------------------------------------------
104
105 }  // namespace InferenceEngine