Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hpvm-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
llvm
hpvm-release
Commits
a5f68c94
Commit
a5f68c94
authored
5 years ago
by
Hashim Sharif
Browse files
Options
Downloads
Patches
Plain Diff
TensorRT frontend changes for DepthwiseConv2D
parent
9bc2ca73
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
llvm/projects/keras/frontend/approxhpvm_translator.py
+29
-12
29 additions, 12 deletions
llvm/projects/keras/frontend/approxhpvm_translator.py
llvm/projects/keras/frontend/utils.py
+19
-0
19 additions, 0 deletions
llvm/projects/keras/frontend/utils.py
with
48 additions
and
12 deletions
llvm/projects/keras/frontend/approxhpvm_translator.py
+
29
−
12
View file @
a5f68c94
...
...
@@ -4,6 +4,7 @@ import numpy as np
from
frontend.promise_translator
import
PromiseRtTranslator
from
frontend.hpvm_dfg_translator
import
HPVMTranslator
from
frontend.weight_utils
import
dumpLabels
,
dumpData
,
dumpConvWeights
,
dumpFcWeights
,
dumpFcBias
from
frontend.utils
import
*
import
keras
import
os
...
...
@@ -23,6 +24,7 @@ class DFG:
layer_name
=
layer
.
__class__
.
__name__
singleInLayers
=
{}
singleInLayers
[
"
DepthwiseConv2D
"
]
=
True
singleInLayers
[
"
Conv2D
"
]
=
True
singleInLayers
[
"
Dense
"
]
=
True
singleInLayers
[
"
MaxPooling2D
"
]
=
True
...
...
@@ -145,7 +147,7 @@ class DFGNode:
self
.
layer_name
=
layer
.
name
# unique layer identifier
print
(
self
.
layer_name
)
if
layer_type
==
"
Conv2D
"
or
layer_type
==
"
Dense
"
:
if
layer_type
==
"
Conv2D
"
or
layer_type
==
"
DepthwiseConv2D
"
or
layer_type
==
"
Dense
"
:
self
.
weights
=
layer
.
get_weights
()[
0
]
print
(
"
\t
"
,
self
.
weights
.
shape
)
self
.
use_bias
=
layer
.
use_bias
...
...
@@ -154,20 +156,23 @@ class DFGNode:
self
.
use_bias
=
layer
.
use_bias
self
.
bias_weights
=
layer
.
get_weights
()[
1
]
print
(
"
\t
"
,
self
.
bias_weights
.
shape
)
if
layer_type
==
"
Conv2D
"
:
if
layer_type
==
"
Conv2D
"
or
layer_type
==
"
DepthwiseConv2D
"
:
self
.
padding
=
layer
.
padding
self
.
strides
=
layer
.
strides
print
(
"
\t
"
,
self
.
strides
)
print
(
"
\t
Padding =
"
,
self
.
padding
)
if
layer_type
==
"
MaxPooling2D
"
or
layer_type
==
"
AveragePooling2D
"
:
self
.
pool_size
=
layer
.
pool_size
self
.
strides
=
layer
.
strides
print
(
"
\t
pool_size =
"
,
self
.
pool_size
)
print
(
"
\t
strides =
"
,
self
.
strides
)
if
layer_type
==
"
Conv2D
"
or
layer_type
==
"
Dense
"
or
layer_type
==
"
Activation
"
:
if
nodeHasActivation
(
self
):
self
.
activation_type
=
layer
.
activation
.
__name__
print
(
"
\t
Activation =
"
,
self
.
activation_type
)
...
...
@@ -317,7 +322,7 @@ class TensorRtTranslator:
def
hasBiasAdd
(
self
,
cur_node
):
if
cur_node
.
layer_type
==
"
Conv2D
"
or
cur_node
.
layer_type
==
"
Dense
"
:
if
nodeHasBias
(
cur_node
)
:
return
cur_node
.
use_bias
return
False
...
...
@@ -325,8 +330,8 @@ class TensorRtTranslator:
def
hasActivation
(
self
,
cur_node
):
if
cur_node
.
layer_type
==
"
Conv2D
"
or
cur_node
.
layer_type
==
"
Dense
"
:
return
cur_node
.
activation_type
!=
"
linear
"
if
nodeHasActivation
(
cur_node
)
:
return
cur_node
.
activation_type
!=
"
linear
"
return
False
...
...
@@ -355,7 +360,7 @@ class TensorRtTranslator:
out_var_name1
=
self
.
getVariableName
(
cur_node
)
layer_type
=
cur_node
.
layer_type
if
layer_type
==
"
Conv2D
"
:
if
layer_type
==
"
Conv2D
"
or
layer_type
==
"
DepthwiseConv2D
"
:
input_var_name
=
self
.
getSingleInputName
(
cur_node
)
weights
=
cur_node
.
weights
strides
=
cur_node
.
strides
...
...
@@ -379,7 +384,14 @@ class TensorRtTranslator:
inst_str
+=
str
(
padding
)
+
"
,
"
inst_str
+=
str
(
strides
[
0
])
+
"
,
"
inst_str
+=
str
(
strides
[
1
])
+
"
,
"
inst_str
+=
"
1, 0);
\n
"
inst_str
+=
"
1,
"
if
layer_type
==
"
DepthwiseConv2D
"
:
C
=
weights
.
shape
[
2
]
inst_str
+=
str
(
C
)
+
"
);
\n
"
else
:
inst_str
+=
"
1);
\n
"
self
.
program_str
+=
inst_str
...
...
@@ -501,7 +513,7 @@ class TensorRtTranslator:
layer_type
=
layer
.
__class__
.
__name__
layer_name
=
layer
.
name
if
layer_type
==
"
Conv2D
"
:
if
layer_type
==
"
Conv2D
"
or
layer_type
==
"
DepthwiseConv2D
"
:
weights
=
layer
.
get_weights
()[
0
]
w_name
=
layer_name
+
"
_w
"
...
...
@@ -522,6 +534,11 @@ class TensorRtTranslator:
file_path_str
+=
unique_file_name
+
"
\"
);
\n
"
self
.
weight_str
+=
file_path_str
# NOTE: Special handling for DepthwiseConv2D
if
layer_type
==
"
DepthwiseConv2D
"
:
N
=
C
C
=
1
# FIXME: Be flexible for datatypes (currently only FP32 weights)
# NOTE: '0' specified for floating point type
self
.
weight_str
+=
"
void*
"
+
w_name
+
"
=
"
+
"
readTrainedWeights(
"
...
...
This diff is collapsed.
Click to expand it.
llvm/projects/keras/frontend/utils.py
0 → 100644
+
19
−
0
View file @
a5f68c94
def
nodeHasBias
(
cur_node
):
if
cur_node
.
layer_type
==
"
Conv2D
"
or
cur_node
.
layer_type
==
"
DepthwiseConv2D
"
or
cur_node
.
layer_type
==
"
Dense
"
:
return
True
else
:
return
False
def
nodeHasActivation
(
cur_node
):
if
cur_node
.
layer_type
==
"
Conv2D
"
or
cur_node
.
layer_type
==
"
DepthwiseConv2D
"
\
or
cur_node
.
layer_type
==
"
Dense
"
or
cur_node
.
layer_type
==
"
Activation
"
:
return
True
else
:
return
False
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment