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
3478240d
Commit
3478240d
authored
Jan 20, 2019
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13656 from dkurt:dnn_tf_atrous_faster_rcnn
parents
0395b2ea
67e6a607
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
tf_text_graph_faster_rcnn.py
samples/dnn/tf_text_graph_faster_rcnn.py
+52
-0
No files found.
samples/dnn/tf_text_graph_faster_rcnn.py
View file @
3478240d
...
...
@@ -48,10 +48,42 @@ def createFasterRCNNGraph(modelPath, configPath, outputPath):
removeIdentity
(
graph_def
)
nodesToKeep
=
[]
def
to_remove
(
name
,
op
):
if
name
in
nodesToKeep
:
return
False
return
op
==
'Const'
or
name
.
startswith
(
scopesToIgnore
)
or
not
name
.
startswith
(
scopesToKeep
)
or
\
(
name
.
startswith
(
'CropAndResize'
)
and
op
!=
'CropAndResize'
)
# Fuse atrous convolutions (with dilations).
nodesMap
=
{
node
.
name
:
node
for
node
in
graph_def
.
node
}
for
node
in
reversed
(
graph_def
.
node
):
if
node
.
op
==
'BatchToSpaceND'
:
del
node
.
input
[
2
]
conv
=
nodesMap
[
node
.
input
[
0
]]
spaceToBatchND
=
nodesMap
[
conv
.
input
[
0
]]
# Extract paddings
stridedSlice
=
nodesMap
[
spaceToBatchND
.
input
[
2
]]
assert
(
stridedSlice
.
op
==
'StridedSlice'
)
pack
=
nodesMap
[
stridedSlice
.
input
[
0
]]
assert
(
pack
.
op
==
'Pack'
)
padNodeH
=
nodesMap
[
nodesMap
[
pack
.
input
[
0
]]
.
input
[
0
]]
padNodeW
=
nodesMap
[
nodesMap
[
pack
.
input
[
1
]]
.
input
[
0
]]
padH
=
int
(
padNodeH
.
attr
[
'value'
][
'tensor'
][
0
][
'int_val'
][
0
])
padW
=
int
(
padNodeW
.
attr
[
'value'
][
'tensor'
][
0
][
'int_val'
][
0
])
paddingsNode
=
NodeDef
()
paddingsNode
.
name
=
conv
.
name
+
'/paddings'
paddingsNode
.
op
=
'Const'
paddingsNode
.
addAttr
(
'value'
,
[
padH
,
padH
,
padW
,
padW
])
graph_def
.
node
.
insert
(
graph_def
.
node
.
index
(
spaceToBatchND
),
paddingsNode
)
nodesToKeep
.
append
(
paddingsNode
.
name
)
spaceToBatchND
.
input
[
2
]
=
paddingsNode
.
name
removeUnusedNodesAndAttrs
(
to_remove
,
graph_def
)
...
...
@@ -225,6 +257,26 @@ def createFasterRCNNGraph(modelPath, configPath, outputPath):
detectionOut
.
addAttr
(
'variance_encoded_in_target'
,
True
)
graph_def
.
node
.
extend
([
detectionOut
])
def
getUnconnectedNodes
():
unconnected
=
[
node
.
name
for
node
in
graph_def
.
node
]
for
node
in
graph_def
.
node
:
for
inp
in
node
.
input
:
if
inp
in
unconnected
:
unconnected
.
remove
(
inp
)
return
unconnected
while
True
:
unconnectedNodes
=
getUnconnectedNodes
()
unconnectedNodes
.
remove
(
detectionOut
.
name
)
if
not
unconnectedNodes
:
break
for
name
in
unconnectedNodes
:
for
i
in
range
(
len
(
graph_def
.
node
)):
if
graph_def
.
node
[
i
]
.
name
==
name
:
del
graph_def
.
node
[
i
]
break
# Save as text.
graph_def
.
save
(
outputPath
)
...
...
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