Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
7eba3a7c
Commit
7eba3a7c
authored
Jan 09, 2020
by
Liubov Batanina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add pack description
parent
752653c7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
39 deletions
+43
-39
all_layers.hpp
modules/dnn/include/opencv2/dnn/all_layers.hpp
+1
-1
layers_common.cpp
modules/dnn/src/layers/layers_common.cpp
+16
-4
layers_common.hpp
modules/dnn/src/layers/layers_common.hpp
+1
-1
pooling_layer.cpp
modules/dnn/src/layers/pooling_layer.cpp
+16
-26
tf_importer.cpp
modules/dnn/src/tensorflow/tf_importer.cpp
+9
-7
No files found.
modules/dnn/include/opencv2/dnn/all_layers.hpp
View file @
7eba3a7c
...
...
@@ -250,7 +250,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
std
::
vector
<
size_t
>
pads_begin
,
pads_end
;
CV_DEPRECATED_EXTERNAL
Size
kernel
,
stride
,
pad
;
CV_DEPRECATED_EXTERNAL
int
pad_l
,
pad_t
,
pad_r
,
pad_b
;
bool
globalPooling
;
CV_DEPRECATED_EXTERNAL
bool
globalPooling
;
std
::
vector
<
bool
>
isGlobalPooling
;
bool
computeMaxIdx
;
String
padMode
;
...
...
modules/dnn/src/layers/layers_common.cpp
View file @
7eba3a7c
...
...
@@ -144,14 +144,26 @@ void getStrideAndPadding(const LayerParams ¶ms, std::vector<size_t>& pads_be
}
}
void
getPoolingKernelParams
(
const
LayerParams
&
params
,
std
::
vector
<
size_t
>&
kernel
,
bool
&
globalPooling
,
void
getPoolingKernelParams
(
const
LayerParams
&
params
,
std
::
vector
<
size_t
>&
kernel
,
std
::
vector
<
bool
>&
globalPooling
,
std
::
vector
<
size_t
>&
pads_begin
,
std
::
vector
<
size_t
>&
pads_end
,
std
::
vector
<
size_t
>&
strides
,
cv
::
String
&
padMode
)
{
globalPooling
=
params
.
has
(
"global_pooling"
)
&&
params
.
get
<
bool
>
(
"global_pooling"
);
bool
is_global
=
params
.
get
<
bool
>
(
"global_pooling"
,
false
);
globalPooling
=
std
::
vector
<
bool
>
(
3
,
is_global
);
if
(
params
.
has
(
"global_d"
))
{
globalPooling
[
0
]
=
params
.
get
<
bool
>
(
"global_d"
);
}
else
if
(
params
.
has
(
"global_h"
))
{
globalPooling
[
1
]
=
params
.
get
<
bool
>
(
"global_h"
);
}
else
if
(
params
.
has
(
"global_w"
))
{
globalPooling
[
2
]
=
params
.
get
<
bool
>
(
"global_w"
);
}
if
(
globalPooling
)
if
(
is_global
)
{
util
::
getStrideAndPadding
(
params
,
pads_begin
,
pads_end
,
strides
,
padMode
);
if
(
params
.
has
(
"kernel_h"
)
||
params
.
has
(
"kernel_w"
)
||
params
.
has
(
"kernel_size"
))
...
...
modules/dnn/src/layers/layers_common.hpp
View file @
7eba3a7c
...
...
@@ -63,7 +63,7 @@ void getConvolutionKernelParams(const LayerParams ¶ms, std::vector<size_t>&
std
::
vector
<
size_t
>&
pads_end
,
std
::
vector
<
size_t
>&
strides
,
std
::
vector
<
size_t
>&
dilations
,
cv
::
String
&
padMode
,
std
::
vector
<
size_t
>&
adjust_pads
);
void
getPoolingKernelParams
(
const
LayerParams
&
params
,
std
::
vector
<
size_t
>&
kernel
,
bool
&
globalPooling
,
void
getPoolingKernelParams
(
const
LayerParams
&
params
,
std
::
vector
<
size_t
>&
kernel
,
std
::
vector
<
bool
>&
globalPooling
,
std
::
vector
<
size_t
>&
pads_begin
,
std
::
vector
<
size_t
>&
pads_end
,
std
::
vector
<
size_t
>&
strides
,
cv
::
String
&
padMode
);
void
getConvPoolOutParams
(
const
std
::
vector
<
int
>&
inp
,
const
std
::
vector
<
size_t
>&
kernel
,
...
...
modules/dnn/src/layers/pooling_layer.cpp
View file @
7eba3a7c
...
...
@@ -79,6 +79,7 @@ public:
{
computeMaxIdx
=
true
;
globalPooling
=
false
;
isGlobalPooling
=
std
::
vector
<
bool
>
(
3
,
false
);
stride
=
Size
(
1
,
1
);
pad_t
=
pad_l
=
pad_b
=
pad_r
=
0
;
...
...
@@ -95,7 +96,8 @@ public:
else
CV_Error
(
Error
::
StsBadArg
,
"Unknown pooling type
\"
"
+
pool
+
"
\"
"
);
getPoolingKernelParams
(
params
,
kernel_size
,
globalPooling
,
pads_begin
,
pads_end
,
strides
,
padMode
);
getPoolingKernelParams
(
params
,
kernel_size
,
isGlobalPooling
,
pads_begin
,
pads_end
,
strides
,
padMode
);
globalPooling
=
std
::
accumulate
(
isGlobalPooling
.
begin
(),
isGlobalPooling
.
end
(),
0
)
==
3
;
if
(
kernel_size
.
size
()
==
2
)
{
kernel
=
Size
(
kernel_size
[
1
],
kernel_size
[
0
]);
stride
=
Size
(
strides
[
1
],
strides
[
0
]);
...
...
@@ -125,14 +127,7 @@ public:
setParamsFrom
(
params
);
ceilMode
=
params
.
get
<
bool
>
(
"ceil_mode"
,
true
);
if
(
params
.
has
(
"is_global_pooling"
))
{
const
DictValue
&
global_axis
=
params
.
get
(
"is_global_pooling"
);
int
size
=
global_axis
.
size
();
isGlobalPooling
.
resize
(
size
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
isGlobalPooling
[
i
]
=
global_axis
.
get
<
bool
>
(
i
);
}
spatialScale
=
params
.
get
<
float
>
(
"spatial_scale"
,
1
);
avePoolPaddedArea
=
params
.
get
<
bool
>
(
"ave_pool_padded_area"
,
true
);
}
...
...
@@ -155,17 +150,14 @@ public:
inp
.
push_back
(
inputs
[
0
].
size
[
i
]);
out
.
push_back
(
outputs
[
0
].
size
[
i
]);
}
if
(
globalPooling
)
{
kernel
=
Size
(
inp
[
1
],
inp
[
0
]);
kernel_size
=
std
::
vector
<
size_t
>
(
inp
.
begin
(),
inp
.
end
());
}
else
if
(
!
isGlobalPooling
.
empty
())
{
for
(
int
i
=
0
;
i
<
isGlobalPooling
.
size
();
i
++
)
{
if
(
isGlobalPooling
[
i
])
kernel_size
[
i
]
=
inp
[
i
];
}
kernel
=
Size
(
kernel_size
[
1
],
kernel_size
[
0
]);
kernel_size
.
resize
(
out
.
size
());
int
diff_size
=
isGlobalPooling
.
size
()
-
kernel_size
.
size
();
for
(
int
i
=
0
;
i
<
kernel_size
.
size
();
i
++
)
{
if
(
isGlobalPooling
[
i
+
diff_size
])
kernel_size
[
i
]
=
inp
[
i
];
}
kernel
=
Size
(
kernel_size
[
1
],
kernel_size
[
0
]);
getConvPoolPaddings
(
inp
,
kernel_size
,
strides
,
padMode
,
pads_begin
,
pads_end
);
if
(
pads_begin
.
size
()
==
2
)
{
...
...
@@ -1053,14 +1045,12 @@ virtual Ptr<BackendNode> initNgraph(const std::vector<Ptr<BackendWrapper> >& inp
outShape
[
0
]
=
inputs
[
1
][
0
];
// Number of proposals;
outShape
[
1
]
=
psRoiOutChannels
;
}
else
if
(
!
isGlobalPooling
.
empty
())
int
diff_size
=
isGlobalPooling
.
size
()
-
(
outShape
.
size
()
-
2
);
for
(
int
i
=
2
;
i
<
outShape
.
size
();
i
++
)
{
CV_Assert
(
isGlobalPooling
.
size
()
==
inpShape
.
size
());
for
(
int
i
=
0
;
i
<
isGlobalPooling
.
size
();
i
++
)
{
if
(
isGlobalPooling
[
i
])
outShape
[
2
+
i
]
=
1
;
}
if
(
isGlobalPooling
[
i
-
2
+
diff_size
])
outShape
[
i
]
=
1
;
}
int
numOutputs
=
requiredOutputs
?
requiredOutputs
:
(
type
==
MAX
?
2
:
1
);
...
...
modules/dnn/src/tensorflow/tf_importer.cpp
View file @
7eba3a7c
...
...
@@ -1961,8 +1961,7 @@ void TFImporter::populateNet(Net dstNet)
CV_Assert
(
layer_id
.
find
(
avgName
)
==
layer_id
.
end
());
avgLp
.
set
(
"pool"
,
"ave"
);
// pooling kernel H x 1
bool
isGlobalPooling
[]
=
{
true
,
false
};
avgLp
.
set
(
"is_global_pooling"
,
DictValue
::
arrayInt
(
&
isGlobalPooling
[
0
],
2
));
avgLp
.
set
(
"global_h"
,
true
);
avgLp
.
set
(
"kernel_size"
,
1
);
int
avgId
=
dstNet
.
addLayer
(
avgName
,
"Pooling"
,
avgLp
);
layer_id
[
avgName
]
=
avgId
;
...
...
@@ -2025,6 +2024,12 @@ void TFImporter::populateNet(Net dstNet)
}
else
if
(
type
==
"Pack"
)
{
// op: tf.stack(list of tensors, axis=0)
// Join a list of inputs along a new axis.
// The "axis" specifies the index of the new axis in the dimensions of the output.
// Example: given a list with "N" tensors of shape (C, H, W):
// if axis == 0 then the output tensor will have the shape (N, C, H, W),
// if axis == 1 then the output tensor will have the shape (C, N, H, W).
CV_Assert
(
hasLayerAttr
(
layer
,
"axis"
));
int
dim
=
(
int
)
getLayerAttr
(
layer
,
"axis"
).
i
();
if
(
dim
!=
0
)
...
...
@@ -2054,11 +2059,8 @@ void TFImporter::populateNet(Net dstNet)
int
id
=
dstNet
.
addLayer
(
name
,
"Concat"
,
layerParams
);
layer_id
[
name
]
=
id
;
for
(
int
li
=
0
;
li
<
num
;
li
++
)
{
Pin
inp
=
parsePin
(
reshape_names
[
li
]);
connect
(
layer_id
,
dstNet
,
inp
,
id
,
li
);
}
for
(
int
li
=
0
;
li
<
num
;
li
++
)
connect
(
layer_id
,
dstNet
,
Pin
(
reshape_names
[
li
]),
id
,
li
);
}
else
if
(
type
==
"ClipByValue"
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment