mirror of
https://github.com/opencv/opencv.git
synced 2025-07-31 01:47:12 +08:00
Merge pull request #25709 from dkurt:wrap_addLayer
* Wrap dnn addLayer * Add typing stubs
This commit is contained in:
parent
bef5a87680
commit
3700f9e1e9
@ -533,7 +533,7 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
* @param params parameters which will be used to initialize the creating layer.
|
||||
* @returns unique identifier of created layer, or -1 if a failure will happen.
|
||||
*/
|
||||
int addLayer(const String &name, const String &type, const int &dtype, LayerParams ¶ms);
|
||||
CV_WRAP int addLayer(const String &name, const String &type, const int &dtype, LayerParams ¶ms);
|
||||
|
||||
/** @overload Datatype of output blobs set to default CV_32F */
|
||||
int addLayer(const String &name, const String &type, LayerParams ¶ms);
|
||||
@ -541,7 +541,7 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
/** @brief Adds new layer and connects its first input to the first output of previously added layer.
|
||||
* @see addLayer()
|
||||
*/
|
||||
int addLayerToPrev(const String &name, const String &type, const int &dtype, LayerParams ¶ms);
|
||||
CV_WRAP int addLayerToPrev(const String &name, const String &type, const int &dtype, LayerParams ¶ms);
|
||||
|
||||
/** @overload */
|
||||
int addLayerToPrev(const String &name, const String &type, LayerParams ¶ms);
|
||||
|
@ -71,6 +71,22 @@ PyObject* pyopencv_from(const dnn::LayerParams& lp)
|
||||
return dict;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, dnn::LayerParams &lp, const ArgInfo& info)
|
||||
{
|
||||
CV_Assert(PyDict_Check(o));
|
||||
PyObject *key, *value;
|
||||
Py_ssize_t pos = 0;
|
||||
std::string keyName;
|
||||
while (PyDict_Next(o, &pos, &key, &value)) {
|
||||
getUnicodeString(key, keyName);
|
||||
dnn::DictValue dv;
|
||||
pyopencv_to(value, dv, info);
|
||||
lp.set(keyName, dv);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const std::vector<dnn::Target> &t)
|
||||
{
|
||||
|
@ -480,5 +480,21 @@ class dnn_test(NewOpenCVTests):
|
||||
params.scalefactor = 2.0
|
||||
self.assertEqual(params.scalefactor, (2.0, 0.0, 0.0, 0.0))
|
||||
|
||||
def test_net_builder(self):
|
||||
net = cv.dnn.Net()
|
||||
params = {
|
||||
"kernel_w": 3,
|
||||
"kernel_h": 3,
|
||||
"stride_w": 3,
|
||||
"stride_h": 3,
|
||||
"pool": "max",
|
||||
}
|
||||
net.addLayerToPrev("pool", "Pooling", cv.CV_32F, params)
|
||||
|
||||
inp = np.random.standard_normal([1, 2, 9, 12]).astype(np.float32)
|
||||
net.setInput(inp)
|
||||
out = net.forward()
|
||||
self.assertEqual(out.shape, (1, 2, 3, 4))
|
||||
|
||||
if __name__ == '__main__':
|
||||
NewOpenCVTests.bootstrap()
|
||||
|
@ -194,6 +194,13 @@ _PREDEFINED_TYPES = (
|
||||
export_name="ExtractMetaCallback"
|
||||
),
|
||||
AliasTypeNode.class_("LayerId", "DictValue"),
|
||||
AliasTypeNode.dict_("LayerParams",
|
||||
key_type=PrimitiveTypeNode.str_(),
|
||||
value_type=UnionTypeNode("DictValue", items=(
|
||||
PrimitiveTypeNode.int_(),
|
||||
PrimitiveTypeNode.float_(),
|
||||
PrimitiveTypeNode.str_())
|
||||
)),
|
||||
PrimitiveTypeNode.int_("cvflann_flann_distance_t"),
|
||||
PrimitiveTypeNode.int_("flann_flann_distance_t"),
|
||||
PrimitiveTypeNode.int_("cvflann_flann_algorithm_t"),
|
||||
|
Loading…
Reference in New Issue
Block a user