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
ccd2370b
Commit
ccd2370b
authored
6 years ago
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11890 from dkurt:keras_resize_nearest
parents
c0d0cf5e
36288eeb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
0 deletions
+46
-0
tf_graph_simplifier.cpp
modules/dnn/src/tensorflow/tf_graph_simplifier.cpp
+45
-0
test_tf_importer.cpp
modules/dnn/test/test_tf_importer.cpp
+1
-0
No files found.
modules/dnn/src/tensorflow/tf_graph_simplifier.cpp
View file @
ccd2370b
...
...
@@ -571,6 +571,50 @@ public:
}
};
// In case of resizing by factor.
class
UpsamplingKerasSubgraph
:
public
Subgraph
{
public
:
UpsamplingKerasSubgraph
()
{
int
input
=
addNodeToMatch
(
""
);
int
shape
=
addNodeToMatch
(
"Shape"
,
input
);
int
stack
=
addNodeToMatch
(
"Const"
);
int
stack_1
=
addNodeToMatch
(
"Const"
);
int
stack_2
=
addNodeToMatch
(
"Const"
);
int
strided_slice
=
addNodeToMatch
(
"StridedSlice"
,
shape
,
stack
,
stack_1
,
stack_2
);
int
factors
=
addNodeToMatch
(
"Const"
);
int
mul
=
addNodeToMatch
(
"Mul"
,
strided_slice
,
factors
);
addNodeToMatch
(
"ResizeNearestNeighbor"
,
input
,
mul
);
setFusedNode
(
"ResizeNearestNeighbor"
,
input
,
factors
);
}
virtual
void
finalize
(
tensorflow
::
GraphDef
&
net
,
tensorflow
::
NodeDef
*
fusedNode
,
std
::
vector
<
tensorflow
::
NodeDef
*>&
inputNodes
)
CV_OVERRIDE
{
Mat
factorsMat
=
getTensorContent
(
inputNodes
[
1
]
->
attr
().
at
(
"value"
).
tensor
());
CV_Assert
(
factorsMat
.
total
()
==
2
,
factorsMat
.
type
()
==
CV_32SC1
);
// Height scale factor
tensorflow
::
TensorProto
*
factorY
=
inputNodes
[
1
]
->
mutable_attr
()
->
at
(
"value"
).
mutable_tensor
();
factorY
->
clear_int_val
();
factorY
->
clear_tensor_content
();
factorY
->
add_int_val
(
factorsMat
.
at
<
int
>
(
0
,
0
));
// Width scale factor.
tensorflow
::
NodeDef
*
factorXNode
=
net
.
add_node
();
factorXNode
->
set_op
(
"Const"
);
factorXNode
->
set_name
(
fusedNode
->
name
()
+
"/factor_y"
);
tensorflow
::
AttrValue
factorX
;
factorX
.
mutable_tensor
()
->
set_dtype
(
tensorflow
::
DT_INT32
);
factorX
.
mutable_tensor
()
->
add_int_val
(
factorsMat
.
at
<
int
>
(
0
,
1
));
factorXNode
->
mutable_attr
()
->
insert
(
MapPair
<
std
::
string
,
tensorflow
::
AttrValue
>
(
"value"
,
factorX
));
fusedNode
->
add_input
(
factorXNode
->
name
());
}
};
void
simplifySubgraphs
(
tensorflow
::
GraphDef
&
net
)
{
std
::
vector
<
Ptr
<
Subgraph
>
>
subgraphs
;
...
...
@@ -585,6 +629,7 @@ void simplifySubgraphs(tensorflow::GraphDef& net)
subgraphs
.
push_back
(
Ptr
<
Subgraph
>
(
new
DeconvolutionValidKerasSubgraph
()));
subgraphs
.
push_back
(
Ptr
<
Subgraph
>
(
new
DeconvolutionSameKerasSubgraph
()));
subgraphs
.
push_back
(
Ptr
<
Subgraph
>
(
new
ResizeBilinearSubgraph
()));
subgraphs
.
push_back
(
Ptr
<
Subgraph
>
(
new
UpsamplingKerasSubgraph
()));
int
numNodes
=
net
.
node_size
();
std
::
vector
<
int
>
matchedNodesIds
;
...
...
This diff is collapsed.
Click to expand it.
modules/dnn/test/test_tf_importer.cpp
View file @
ccd2370b
...
...
@@ -403,6 +403,7 @@ TEST(Test_TensorFlow, split)
TEST
(
Test_TensorFlow
,
resize_nearest_neighbor
)
{
runTensorFlowNet
(
"resize_nearest_neighbor"
);
runTensorFlowNet
(
"keras_upsampling2d"
);
}
TEST
(
Test_TensorFlow
,
slice
)
...
...
This diff is collapsed.
Click to expand it.
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