-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathDetectionNetworkBindings.cpp
More file actions
207 lines (200 loc) · 10.6 KB
/
Copy pathDetectionNetworkBindings.cpp
File metadata and controls
207 lines (200 loc) · 10.6 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <pybind11/cast.h>
#include <memory>
#include "Common.hpp"
#include "NodeBindings.hpp"
#include "depthai/capabilities/ImgFrameCapability.hpp"
#include "depthai/modelzoo/Zoo.hpp"
#include "depthai/pipeline/DeviceNodeGroup.hpp"
#include "depthai/pipeline/Node.hpp"
#include "depthai/pipeline/NodeGroup.hpp"
#include "depthai/pipeline/Pipeline.hpp"
#include "depthai/pipeline/node/DetectionNetwork.hpp"
#include "depthai/utility/CompilerWarnings.hpp"
void bind_detectionnetwork(pybind11::module& m, void* pCallstack) {
using namespace dai;
using namespace dai::node;
auto detectionNetwork = ADD_NODE_DERIVED(DetectionNetwork, DeviceNodeGroup);
detectionNetwork.attr("Model") = daiNodeModule.attr("NeuralNetwork").attr("Model");
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Call the rest of the type defines, then perform the actual bindings
Callstack* callstack = (Callstack*)pCallstack;
auto cb = callstack->top();
callstack->pop();
cb(m, pCallstack);
// Actual bindings
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// DetectionNetwork Properties
// detectionNetworkProperties.def_readwrite("parser", &DetectionNetworkProperties::parser);
// DetectionNetwork Node
detectionNetwork
#define DETECTION_NETWORK_BUILD_ARGS Node::Output &input, NNArchive &nnArchive
#define DETECTION_NETWORK_BUILD_PYARGS py::arg("input"), py::arg("nnArchive")
#define DETECTION_NETWORK_ARGS float confidenceThreshold
#define DETECTION_NETWORK_PYARGS py::arg("confidenceThreshold") = 0.5
// TODO (Zimamazim) Automatically fetch default arguments to avoid duplicity
#define DETECTION_NETWORK_CODE(OP) self OP setConfidenceThreshold(confidenceThreshold);
.def(
"build",
[](DetectionNetwork& self, DETECTION_NETWORK_BUILD_ARGS, DETECTION_NETWORK_ARGS) {
self.build(input, nnArchive);
DETECTION_NETWORK_CODE(.)
return std::static_pointer_cast<DetectionNetwork>(self.shared_from_this());
},
DETECTION_NETWORK_BUILD_PYARGS,
DETECTION_NETWORK_PYARGS)
.def(
"build",
[](DetectionNetwork& self,
const std::shared_ptr<Camera>& input,
NNModelDescription modelDesc,
std::optional<float> fps,
std::optional<dai::ImgResizeMode> resizeMode) { return self.build(input, DetectionNetwork::Model{std::move(modelDesc)}, fps, resizeMode); },
py::arg("input"),
py::arg("model"),
py::arg("fps") = std::nullopt,
py::arg_v("resizeMode", dai::ImgResizeMode::CROP, "dai.ImgResizeMode.CROP"),
DOC(dai, node, DetectionNetwork, build))
.def(
"build",
[](DetectionNetwork& self,
const std::shared_ptr<Camera>& input,
const NNArchive& nnArchive,
std::optional<float> fps,
std::optional<dai::ImgResizeMode> resizeMode) { return self.build(input, DetectionNetwork::Model{nnArchive}, fps, resizeMode); },
py::arg("input"),
py::arg("nnArchive"),
py::arg("fps") = std::nullopt,
py::arg_v("resizeMode", dai::ImgResizeMode::CROP, "dai.ImgResizeMode.CROP"),
DOC(dai, node, DetectionNetwork, build))
.def(
"build",
[](DetectionNetwork& self,
const std::shared_ptr<Camera>& input,
const std::string& model,
std::optional<float> fps,
std::optional<dai::ImgResizeMode> resizeMode) { return self.build(input, DetectionNetwork::Model{model}, fps, resizeMode); },
py::arg("input"),
py::arg("model"),
py::arg("fps") = std::nullopt,
py::arg_v("resizeMode", dai::ImgResizeMode::CROP, "dai.ImgResizeMode.CROP"),
DOC(dai, node, DetectionNetwork, build))
.def(
"build",
[](DetectionNetwork& self, const std::shared_ptr<Camera>& input, const DetectionNetwork::Model& model, const ImgFrameCapability& capability) {
return self.build(input, model, capability);
},
py::arg("input"),
py::arg("model"),
py::arg("capability"),
DOC(dai, node, DetectionNetwork, build, 3))
#ifdef DEPTHAI_HAVE_OPENCV_SUPPORT
.def(
"build",
[](DetectionNetwork& self, const std::shared_ptr<ReplayVideo>& input, NNModelDescription modelDesc, std::optional<float> fps) {
return self.build(input, DetectionNetwork::Model{std::move(modelDesc)}, fps);
},
py::arg("input"),
py::arg("model"),
py::arg("fps") = std::nullopt,
DOC(dai, node, DetectionNetwork, build, 4))
.def(
"build",
[](DetectionNetwork& self, const std::shared_ptr<ReplayVideo>& input, const std::string& model, std::optional<float> fps) {
return self.build(input, DetectionNetwork::Model{NNModelDescription{model}}, fps);
},
py::arg("input"),
py::arg("model"),
py::arg("fps") = std::nullopt,
DOC(dai, node, DetectionNetwork, build, 4))
.def(
"build",
[](DetectionNetwork& self, const std::shared_ptr<ReplayVideo>& input, const NNArchive& nnArchive, std::optional<float> fps) {
return self.build(input, DetectionNetwork::Model{nnArchive}, fps);
},
py::arg("input"),
py::arg("nnArchive"),
py::arg("fps") = std::nullopt,
DOC(dai, node, DetectionNetwork, build, 4))
#endif
.def(py::init<const std::shared_ptr<Device>&>(), py::arg("device"))
.def("setBlobPath", &DetectionNetwork::setBlobPath, py::arg("path"), DOC(dai, node, DetectionNetwork, setBlobPath))
.def("setNumPoolFrames", &DetectionNetwork::setNumPoolFrames, py::arg("numFrames"), DOC(dai, node, DetectionNetwork, setNumPoolFrames))
.def("setNumInferenceThreads",
&DetectionNetwork::setNumInferenceThreads,
py::arg("numThreads"),
DOC(dai, node, DetectionNetwork, setNumInferenceThreads))
.def("setNumNCEPerInferenceThread",
&DetectionNetwork::setNumNCEPerInferenceThread,
py::arg("numNCEPerThread"),
DOC(dai, node, DetectionNetwork, setNumNCEPerInferenceThread))
.def("getNumInferenceThreads", &DetectionNetwork::getNumInferenceThreads, DOC(dai, node, DetectionNetwork, getNumInferenceThreads))
.def("setNNArchive",
py::overload_cast<const NNArchive&>(&DetectionNetwork::setNNArchive),
py::arg("archive"),
DOC(dai, node, DetectionNetwork, setNNArchive))
.def("setNNArchive",
py::overload_cast<const NNArchive&, int>(&DetectionNetwork::setNNArchive),
py::arg("archive"),
py::arg("numShaves"),
DOC(dai, node, DetectionNetwork, setNNArchive))
.def("setFromModelZoo",
py::overload_cast<NNModelDescription, bool>(&DetectionNetwork::setFromModelZoo),
py::arg("description"),
py::arg("useCached") = false,
DOC(dai, node, DetectionNetwork, setFromModelZoo))
.def("setBlob", py::overload_cast<dai::OpenVINO::Blob>(&DetectionNetwork::setBlob), py::arg("blob"), DOC(dai, node, DetectionNetwork, setBlob))
.def("setBlob",
py::overload_cast<const std::filesystem::path&>(&DetectionNetwork::setBlob),
py::arg("path"),
DOC(dai, node, DetectionNetwork, setBlob, 2))
.def("setModelPath", &DetectionNetwork::setModelPath, py::arg("modelPath"), DOC(dai, node, DetectionNetwork, setModelPath))
.def("setNumShavesPerInferenceThread",
&DetectionNetwork::setNumShavesPerInferenceThread,
py::arg("numShavesPerInferenceThread"),
DOC(dai, node, DetectionNetwork, setNumShavesPerInferenceThread))
.def("setBackend", &DetectionNetwork::setBackend, py::arg("setBackend"), DOC(dai, node, DetectionNetwork, setBackend))
.def("setBackendProperties",
&DetectionNetwork::setBackendProperties,
py::arg("setBackendProperties"),
DOC(dai, node, DetectionNetwork, setBackendProperties))
// Detection specific properties
.def_property_readonly(
"input",
[](const DetectionNetwork& n) { return &n.neuralNetwork->input; },
py::return_value_policy::reference_internal,
DOC(dai, node, NeuralNetwork, input))
.def_property_readonly(
"out",
[](const DetectionNetwork& n) { return &n.detectionParser->out; },
py::return_value_policy::reference_internal,
DOC(dai, node, DetectionNetwork, out))
.def_property_readonly(
"outNetwork",
[](const DetectionNetwork& n) { return &n.neuralNetwork->out; },
py::return_value_policy::reference_internal,
DOC(dai, node, DetectionNetwork, outNetwork))
.def_property_readonly(
"passthrough",
[](const DetectionNetwork& n) { return &n.neuralNetwork->passthrough; },
py::return_value_policy::reference_internal,
DOC(dai, node, NeuralNetwork, passthrough))
.def_property_readonly(
"detectionParser",
[](DetectionNetwork& n) { return &(*n.detectionParser); },
py::return_value_policy::reference_internal,
DOC(dai, node, DetectionNetwork, detectionParser))
.def_property_readonly(
"neuralNetwork",
[](DetectionNetwork& n) { return &(*n.neuralNetwork); },
py::return_value_policy::reference_internal,
DOC(dai, node, DetectionNetwork, neuralNetwork))
.def("setConfidenceThreshold", &DetectionNetwork::setConfidenceThreshold, py::arg("thresh"), DOC(dai, node, DetectionNetwork, setConfidenceThreshold))
.def("getClasses", &DetectionNetwork::getClasses, DOC(dai, node, DetectionNetwork, getClasses))
.def("getConfidenceThreshold", &DetectionNetwork::getConfidenceThreshold, DOC(dai, node, DetectionNetwork, getConfidenceThreshold));
// ALIAS
// daiNodeModule.attr("DetectionNetwork").attr("Properties") = detectionNetworkProperties;
}