deeplabv3_resnet101.h
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// Created by DefTruth on 2021/6/7.
//
#ifndef LITE_AI_ORT_CV_DEEPLABV3_RESNET101_H
#define LITE_AI_ORT_CV_DEEPLABV3_RESNET101_H
#include "lite/ort/core/ort_core.h"
namespace ortcv
{
class LITE_EXPORTS DeepLabV3ResNet101
{
private:
Ort::Env ort_env;
Ort::Session *ort_session = nullptr;
std::vector<const char *> input_node_names;
std::vector<std::vector<int64_t>> dynamic_input_node_dims; // >=1 inputs.
unsigned int dynamic_input_height = 512; // init only, will change according to input mat.
unsigned int dynamic_input_width = 512; // init only, will change according to input mat.
unsigned int dynamic_input_tensor_size = 1; // init only, will change according to input mat.
Ort::MemoryInfo memory_info_handler = Ort::MemoryInfo::CreateCpu(
OrtArenaAllocator, OrtMemTypeDefault);
std::vector<const char *> output_node_names;
const LITEORT_CHAR *onnx_path = nullptr;
const char *log_id = nullptr;
unsigned int num_outputs = 1;
unsigned int num_inputs = 1;
std::vector<float> dynamic_input_values_handler;
protected:
const unsigned int num_threads; // initialize at runtime.
public:
// single input with dynamic height and width.
explicit DeepLabV3ResNet101(const std::string &_onnx_path, unsigned int _num_threads = 1);
~DeepLabV3ResNet101();
protected:
DeepLabV3ResNet101(const DeepLabV3ResNet101 &) = delete;
DeepLabV3ResNet101(DeepLabV3ResNet101 &&) = delete;
DeepLabV3ResNet101 &operator=(const DeepLabV3ResNet101 &) = delete;
DeepLabV3ResNet101 &operator=(DeepLabV3ResNet101 &&) = delete;
private:
const float mean_vals[3] = {0.485f, 0.456f, 0.406f};
const float scale_vals[3] = {1.f / 0.229f, 1.f / 0.224f, 1.f / 0.225f};
const char *class_names[20] = {
"aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow",
"diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa",
"train", "tvmonitor"
}; // 20 classes
private:
Ort::Value transform(const cv::Mat &mat);
void print_debug_string();
public:
void detect(const cv::Mat &mat, types::SegmentContent &content);
};
}
#endif //LITE_AI_ORT_CV_DEEPLABV3_RESNET101_H