Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
9f6e0c59
Commit
9f6e0c59
authored
May 16, 2018
by
Pariksheet Pinjari
Committed by
Tianqi Chen
May 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed issue #483, removing enum dependancy (#485)
parent
a349f5ec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
42 deletions
+32
-42
nnvm/python/nnvm/frontend/darknet.py
+30
-39
nnvm/python/nnvm/testing/darknet.py
+2
-3
No files found.
nnvm/python/nnvm/frontend/darknet.py
View file @
9f6e0c59
...
...
@@ -3,12 +3,11 @@ DarkNet symbol frontend.
"""
from
__future__
import
absolute_import
as
_abs
from
enum
import
IntEnum
import
numpy
as
np
import
tvm
from
..
import
symbol
as
_sym
class
LAYERTYPE
(
IntEnum
):
class
LAYERTYPE
(
object
):
"""Darknet LAYERTYPE Class constant."""
CONVOLUTIONAL
=
0
DECONVOLUTIONAL
=
1
...
...
@@ -36,7 +35,7 @@ class LAYERTYPE(IntEnum):
REORG
=
23
BLANK
=
24
class
ACTIVATION
(
IntEnum
):
class
ACTIVATION
(
object
):
"""Darknet ACTIVATION Class constant."""
LOGISTIC
=
0
RELU
=
1
...
...
@@ -323,33 +322,31 @@ def _darknet_op_not_support(inputs, attrs):
raise
NotImplementedError
(
err
)
_DARKNET_CONVERT_MAP
=
{
'CONVOLUTIONAL'
:
_darknet_conv2d
,
'DECONVOLUTIONAL'
:
_darknet_conv2d_transpose
,
'CONNECTED'
:
_darknet_dense
,
'MAXPOOL'
:
_darknet_maxpooling
,
'SOFTMAX'
:
_darknet_softmax_output
,
'DROPOUT'
:
_darknet_dropout
,
'AVGPOOL'
:
_darknet_avgpooling
,
'BATCHNORM'
:
_darknet_batch_norm
,
'RESHAPE'
:
_darknet_reshape
,
'ROUTE'
:
_darknet_route
,
'REORG'
:
_darknet_reorg
,
'REGION'
:
_darknet_region
,
'ACTIVATION'
:
_darknet_activations
,
'SHORTCUT'
:
_darknet_shortcut
,
'DETECTION'
:
_darknet_op_not_support
,
'CROP'
:
_darknet_op_not_support
,
'COST'
:
_darknet_op_not_support
,
'NORMALIZATION'
:
_darknet_op_not_support
,
'LOCAL'
:
_darknet_op_not_support
,
'ACTIVE'
:
_darknet_op_not_support
,
'RNN'
:
_darknet_op_not_support
,
'GRU'
:
_darknet_op_not_support
,
'LSTM'
:
_darknet_op_not_support
,
'CRNN'
:
_darknet_op_not_support
,
'NETWORK'
:
_darknet_op_not_support
,
'XNOR'
:
_darknet_op_not_support
,
'BLANK'
:
_darknet_op_not_support
,
LAYERTYPE
.
CONVOLUTIONAL
:
_darknet_conv2d
,
LAYERTYPE
.
DECONVOLUTIONAL
:
_darknet_conv2d_transpose
,
LAYERTYPE
.
CONNECTED
:
_darknet_dense
,
LAYERTYPE
.
MAXPOOL
:
_darknet_maxpooling
,
LAYERTYPE
.
SOFTMAX
:
_darknet_softmax_output
,
LAYERTYPE
.
DROPOUT
:
_darknet_dropout
,
LAYERTYPE
.
AVGPOOL
:
_darknet_avgpooling
,
LAYERTYPE
.
BATCHNORM
:
_darknet_batch_norm
,
LAYERTYPE
.
ROUTE
:
_darknet_route
,
LAYERTYPE
.
REORG
:
_darknet_reorg
,
LAYERTYPE
.
REGION
:
_darknet_region
,
LAYERTYPE
.
SHORTCUT
:
_darknet_shortcut
,
LAYERTYPE
.
DETECTION
:
_darknet_op_not_support
,
LAYERTYPE
.
CROP
:
_darknet_op_not_support
,
LAYERTYPE
.
COST
:
_darknet_op_not_support
,
LAYERTYPE
.
NORMALIZATION
:
_darknet_op_not_support
,
LAYERTYPE
.
LOCAL
:
_darknet_op_not_support
,
LAYERTYPE
.
ACTIVE
:
_darknet_op_not_support
,
LAYERTYPE
.
RNN
:
_darknet_op_not_support
,
LAYERTYPE
.
GRU
:
_darknet_op_not_support
,
LAYERTYPE
.
LSTM
:
_darknet_op_not_support
,
LAYERTYPE
.
CRNN
:
_darknet_op_not_support
,
LAYERTYPE
.
NETWORK
:
_darknet_op_not_support
,
LAYERTYPE
.
XNOR
:
_darknet_op_not_support
,
LAYERTYPE
.
BLANK
:
_darknet_op_not_support
,
}
def
_darknet_convert_symbol
(
op_name
,
inputs
,
attrs
):
...
...
@@ -376,7 +373,7 @@ def _darknet_convert_symbol(op_name, inputs, attrs):
if
op_name
in
_DARKNET_CONVERT_MAP
:
sym
,
out_name
=
_DARKNET_CONVERT_MAP
[
op_name
](
inputs
,
attrs
)
else
:
_darknet_raise_not_supported
(
'Operator
: '
+
op_name
)
_darknet_raise_not_supported
(
'Operator
type '
+
str
(
op_name
)
)
if
out_name
is
None
:
out_name
=
sym
.
list_output_names
()[
0
]
.
replace
(
'_output'
,
''
)
return
out_name
,
sym
...
...
@@ -397,10 +394,6 @@ def _read_memory_buffer(shape, data, dtype):
data_np
[
i
]
=
data
[
i
]
return
data_np
.
reshape
(
shape
)
def
_get_darknet_layername
(
layer_type
):
"""Get the layer name from the darknet enums."""
return
str
((
LAYERTYPE
(
layer_type
)))
.
replace
(
'LAYERTYPE.'
,
''
)
def
_get_convolution_weights
(
layer
,
opname
,
params
,
dtype
):
"""Get the convolution layer weights and biases."""
if
layer
.
nweights
==
0
:
...
...
@@ -460,8 +453,6 @@ def _get_darknet_attrs(net, layer_num):
attr
=
{}
use_flatten
=
True
layer
=
net
.
layers
[
layer_num
]
op_name
=
_get_darknet_layername
(
layer
.
type
)
if
LAYERTYPE
.
CONVOLUTIONAL
==
layer
.
type
:
attr
.
update
({
'layout'
:
'NCHW'
})
attr
.
update
({
'pad'
:
str
(
layer
.
pad
)})
...
...
@@ -551,10 +542,10 @@ def _get_darknet_attrs(net, layer_num):
attr
.
update
({
'background'
:
layer
.
background
})
attr
.
update
({
'softmax'
:
layer
.
softmax
})
else
:
err
=
"Darknet layer
{} is not supported in nnvm."
.
format
(
op_nam
e
)
err
=
"Darknet layer
type {} is not supported in nnvm."
.
format
(
layer
.
typ
e
)
raise
NotImplementedError
(
err
)
return
op_nam
e
,
attr
return
layer
.
typ
e
,
attr
def
_get_tvm_params_name
(
opname
,
arg_name
):
"""Makes the params name for the k,v pair."""
...
...
nnvm/python/nnvm/testing/darknet.py
View file @
9f6e0c59
...
...
@@ -8,7 +8,6 @@ These are utility functions used for testing and tutorial file.
"""
from
__future__
import
division
import
math
from
enum
import
IntEnum
import
numpy
as
np
import
cv2
from
cffi
import
FFI
...
...
@@ -91,7 +90,7 @@ def load_image(image, resize_width, resize_height):
img
=
load_image_color
(
image
)
return
_letterbox_image
(
img
,
resize_width
,
resize_height
)
class
LAYERTYPE
(
IntEnum
):
class
LAYERTYPE
(
object
):
"""Darknet LAYERTYPE Class constant."""
CONVOLUTIONAL
=
0
DECONVOLUTIONAL
=
1
...
...
@@ -119,7 +118,7 @@ class LAYERTYPE(IntEnum):
REORG
=
23
BLANK
=
24
class
ACTIVATION
(
IntEnum
):
class
ACTIVATION
(
object
):
"""Darknet ACTIVATION Class constant."""
LOGISTIC
=
0
RELU
=
1
...
...
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