agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 1 | /** |
Sébastien Blin | cb783e3 | 2021-02-12 11:34:10 -0500 | [diff] [blame] | 2 | * Copyright (C) 2020-2021 Savoir-faire Linux Inc. |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 3 | * |
| 4 | * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 | * USA. |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #include "TFInference.h" |
| 25 | |
| 26 | // OpenCV headers |
| 27 | #include <opencv2/core.hpp> |
| 28 | // STL |
| 29 | #include <array> |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 30 | #include <iostream> |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 31 | #include <tuple> |
| 32 | #include <vector> |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 33 | |
| 34 | namespace jami { |
| 35 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 36 | class PluginInference : public TensorflowInference |
| 37 | { |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 38 | public: |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 39 | /** |
| 40 | * @brief PluginInference |
| 41 | * Is a type of supervised learning where we detect objects in images |
| 42 | * Draw a bounding boxes around them |
| 43 | * @param model |
| 44 | */ |
| 45 | PluginInference(TFModel model); |
| 46 | ~PluginInference(); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 47 | |
| 48 | #ifdef TFLITE |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 49 | /** |
| 50 | * @brief getInput |
| 51 | * Returns the input where to fill the data |
| 52 | * Use this method if you know what you are doing, all the necessary checks |
| 53 | * on dimensions must be done on your part |
| 54 | * @return std::tuple<uint8_t *, std::vector<int>> |
| 55 | * The first element in the tuple is the pointer to the storage location |
| 56 | * The second element is a dimensions vector that will helps you make |
| 57 | * The necessary checks to make your data size match the input one |
| 58 | */ |
| 59 | std::pair<uint8_t*, std::vector<int>> getInput(); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 60 | |
| 61 | #else |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 62 | void ReadTensorFromMat(const cv::Mat& image); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 63 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 64 | #endif // TFLITE |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 65 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 66 | std::vector<float> masksPredictions() const; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 67 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 68 | /** |
| 69 | * @brief setExpectedImageDimensions |
| 70 | * Sets imageWidth and imageHeight from the sources |
| 71 | */ |
| 72 | void setExpectedImageDimensions(); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 73 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 74 | // Getters |
| 75 | int getImageWidth() const; |
| 76 | int getImageHeight() const; |
| 77 | int getImageNbChannels() const; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 78 | |
| 79 | private: |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 80 | int imageWidth = 0; |
| 81 | int imageHeight = 0; |
| 82 | int imageNbChannels = 0; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 83 | }; |
| 84 | } // namespace jami |