Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 730b900

Browse files
committed
add DNN Net getUnconnectedOutLayers and getLayerNames bindings
1 parent d22fa8f commit 730b900

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

cc/modules/dnn/Net.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ NAN_MODULE_INIT(Net::Init) {
2020
Nan::SetPrototypeMethod(ctor, "setInputAsync", SetInputAsync);
2121
Nan::SetPrototypeMethod(ctor, "forward", Forward);
2222
Nan::SetPrototypeMethod(ctor, "forwardAsync", ForwardAsync);
23+
Nan::SetPrototypeMethod(ctor, "getLayerNames", GetLayerNames);
24+
Nan::SetPrototypeMethod(ctor, "getLayerNamesAsync", GetLayerNamesAsync);
25+
Nan::SetPrototypeMethod(ctor, "getUnconnectedOutLayers", GetUnconnectedOutLayers);
26+
Nan::SetPrototypeMethod(ctor, "getUnconnectedOutLayersAsync", GetUnconnectedOutLayersAsync);
2327

2428
target->Set(Nan::New("Net").ToLocalChecked(), ctor->GetFunction());
2529
};
@@ -63,4 +67,32 @@ NAN_METHOD(Net::ForwardAsync) {
6367
);
6468
}
6569

70+
NAN_METHOD(Net::GetLayerNames) {
71+
FF::SyncBinding(
72+
std::make_shared<NetBindings::GetLayerNamesWorker>(Net::Converter::unwrap(info.This())),
73+
"Net::GetLayerNames",
74+
info);
75+
}
76+
77+
NAN_METHOD(Net::GetLayerNamesAsync) {
78+
FF::AsyncBinding(
79+
std::make_shared<NetBindings::GetLayerNamesWorker>(Net::Converter::unwrap(info.This())),
80+
"Net::GetLayerNamesAsync",
81+
info);
82+
}
83+
84+
NAN_METHOD(Net::GetUnconnectedOutLayers) {
85+
FF::SyncBinding(
86+
std::make_shared<NetBindings::GetUnconnectedOutLayersWorker>(Net::Converter::unwrap(info.This())),
87+
"Net::GetUnconnectedOutLayers",
88+
info);
89+
}
90+
91+
NAN_METHOD(Net::GetUnconnectedOutLayersAsync) {
92+
FF::AsyncBinding(
93+
std::make_shared<NetBindings::GetUnconnectedOutLayersWorker>(Net::Converter::unwrap(info.This())),
94+
"Net::GetUnconnectedOutLayersAsync",
95+
info);
96+
}
97+
6698
#endif

cc/modules/dnn/Net.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class Net : public Nan::ObjectWrap {
2828
static NAN_METHOD(SetInputAsync);
2929
static NAN_METHOD(Forward);
3030
static NAN_METHOD(ForwardAsync);
31+
static NAN_METHOD(GetLayerNames);
32+
static NAN_METHOD(GetLayerNamesAsync);
33+
static NAN_METHOD(GetUnconnectedOutLayers);
34+
static NAN_METHOD(GetUnconnectedOutLayersAsync);
3135
};
3236

3337
#endif

cc/modules/dnn/NetBindings.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,47 @@ namespace NetBindings {
7979
}
8080
};
8181

82+
struct GetLayerNamesWorker : public CatchCvExceptionWorker {
83+
public:
84+
cv::dnn::Net self;
85+
GetLayerNamesWorker(cv::dnn::Net self) {
86+
this->self = self;
87+
}
88+
89+
std::vector<std::string> returnValue;
90+
91+
std::string executeCatchCvExceptionWorker() {
92+
std::vector<cv::String> layerNames = self.getLayerNames();
93+
std::vector<std::string> strings(
94+
layerNames.begin(),
95+
layerNames.end());
96+
returnValue = strings;
97+
return "";
98+
}
99+
100+
v8::Local<v8::Value> getReturnValue() {
101+
return StringArrayConverter::wrap(returnValue);
102+
}
103+
};
104+
105+
struct GetUnconnectedOutLayersWorker : public CatchCvExceptionWorker {
106+
public:
107+
cv::dnn::Net self;
108+
GetUnconnectedOutLayersWorker(cv::dnn::Net self) {
109+
this->self = self;
110+
}
111+
112+
std::vector<int> layerIndexes;
113+
114+
std::string executeCatchCvExceptionWorker() {
115+
layerIndexes = self.getUnconnectedOutLayers();
116+
return "";
117+
}
118+
119+
v8::Local<v8::Value> getReturnValue() {
120+
return IntArrayConverter::wrap(layerIndexes);
121+
}
122+
};
82123

83124
}
84125

0 commit comments

Comments
 (0)