Skip to content

Commit 7968e36

Browse files
PariksheetPinjari909tqchen
authored andcommitted
Fixed issue #483, removing enum dependancy (#485)
1 parent 3865410 commit 7968e36

File tree

2 files changed

+32
-42
lines changed

2 files changed

+32
-42
lines changed

nnvm/python/nnvm/frontend/darknet.py

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
"""
44

55
from __future__ import absolute_import as _abs
6-
from enum import IntEnum
76
import numpy as np
87
import tvm
98
from .. import symbol as _sym
109

11-
class LAYERTYPE(IntEnum):
10+
class LAYERTYPE(object):
1211
"""Darknet LAYERTYPE Class constant."""
1312
CONVOLUTIONAL = 0
1413
DECONVOLUTIONAL = 1
@@ -36,7 +35,7 @@ class LAYERTYPE(IntEnum):
3635
REORG = 23
3736
BLANK = 24
3837

39-
class ACTIVATION(IntEnum):
38+
class ACTIVATION(object):
4039
"""Darknet ACTIVATION Class constant."""
4140
LOGISTIC = 0
4241
RELU = 1
@@ -323,33 +322,31 @@ def _darknet_op_not_support(inputs, attrs):
323322
raise NotImplementedError(err)
324323

325324
_DARKNET_CONVERT_MAP = {
326-
'CONVOLUTIONAL' : _darknet_conv2d,
327-
'DECONVOLUTIONAL' : _darknet_conv2d_transpose,
328-
'CONNECTED' : _darknet_dense,
329-
'MAXPOOL' : _darknet_maxpooling,
330-
'SOFTMAX' : _darknet_softmax_output,
331-
'DROPOUT' : _darknet_dropout,
332-
'AVGPOOL' : _darknet_avgpooling,
333-
'BATCHNORM' : _darknet_batch_norm,
334-
'RESHAPE' : _darknet_reshape,
335-
'ROUTE' : _darknet_route,
336-
'REORG' : _darknet_reorg,
337-
'REGION' : _darknet_region,
338-
'ACTIVATION' : _darknet_activations,
339-
'SHORTCUT' : _darknet_shortcut,
340-
'DETECTION' : _darknet_op_not_support,
341-
'CROP' : _darknet_op_not_support,
342-
'COST' : _darknet_op_not_support,
343-
'NORMALIZATION' : _darknet_op_not_support,
344-
'LOCAL' : _darknet_op_not_support,
345-
'ACTIVE' : _darknet_op_not_support,
346-
'RNN' : _darknet_op_not_support,
347-
'GRU' : _darknet_op_not_support,
348-
'LSTM' : _darknet_op_not_support,
349-
'CRNN' : _darknet_op_not_support,
350-
'NETWORK' : _darknet_op_not_support,
351-
'XNOR' : _darknet_op_not_support,
352-
'BLANK' : _darknet_op_not_support,
325+
LAYERTYPE.CONVOLUTIONAL : _darknet_conv2d,
326+
LAYERTYPE.DECONVOLUTIONAL : _darknet_conv2d_transpose,
327+
LAYERTYPE.CONNECTED : _darknet_dense,
328+
LAYERTYPE.MAXPOOL : _darknet_maxpooling,
329+
LAYERTYPE.SOFTMAX : _darknet_softmax_output,
330+
LAYERTYPE.DROPOUT : _darknet_dropout,
331+
LAYERTYPE.AVGPOOL : _darknet_avgpooling,
332+
LAYERTYPE.BATCHNORM : _darknet_batch_norm,
333+
LAYERTYPE.ROUTE : _darknet_route,
334+
LAYERTYPE.REORG : _darknet_reorg,
335+
LAYERTYPE.REGION : _darknet_region,
336+
LAYERTYPE.SHORTCUT : _darknet_shortcut,
337+
LAYERTYPE.DETECTION : _darknet_op_not_support,
338+
LAYERTYPE.CROP : _darknet_op_not_support,
339+
LAYERTYPE.COST : _darknet_op_not_support,
340+
LAYERTYPE.NORMALIZATION : _darknet_op_not_support,
341+
LAYERTYPE.LOCAL : _darknet_op_not_support,
342+
LAYERTYPE.ACTIVE : _darknet_op_not_support,
343+
LAYERTYPE.RNN : _darknet_op_not_support,
344+
LAYERTYPE.GRU : _darknet_op_not_support,
345+
LAYERTYPE.LSTM : _darknet_op_not_support,
346+
LAYERTYPE.CRNN : _darknet_op_not_support,
347+
LAYERTYPE.NETWORK : _darknet_op_not_support,
348+
LAYERTYPE.XNOR : _darknet_op_not_support,
349+
LAYERTYPE.BLANK : _darknet_op_not_support,
353350
}
354351

355352
def _darknet_convert_symbol(op_name, inputs, attrs):
@@ -376,7 +373,7 @@ def _darknet_convert_symbol(op_name, inputs, attrs):
376373
if op_name in _DARKNET_CONVERT_MAP:
377374
sym, out_name = _DARKNET_CONVERT_MAP[op_name](inputs, attrs)
378375
else:
379-
_darknet_raise_not_supported('Operator: ' + op_name)
376+
_darknet_raise_not_supported('Operator type ' + str(op_name))
380377
if out_name is None:
381378
out_name = sym.list_output_names()[0].replace('_output', '')
382379
return out_name, sym
@@ -397,10 +394,6 @@ def _read_memory_buffer(shape, data, dtype):
397394
data_np[i] = data[i]
398395
return data_np.reshape(shape)
399396

400-
def _get_darknet_layername(layer_type):
401-
"""Get the layer name from the darknet enums."""
402-
return str((LAYERTYPE(layer_type))).replace('LAYERTYPE.', '')
403-
404397
def _get_convolution_weights(layer, opname, params, dtype):
405398
"""Get the convolution layer weights and biases."""
406399
if layer.nweights == 0:
@@ -460,8 +453,6 @@ def _get_darknet_attrs(net, layer_num):
460453
attr = {}
461454
use_flatten = True
462455
layer = net.layers[layer_num]
463-
op_name = _get_darknet_layername(layer.type)
464-
465456
if LAYERTYPE.CONVOLUTIONAL == layer.type:
466457
attr.update({'layout' : 'NCHW'})
467458
attr.update({'pad' : str(layer.pad)})
@@ -551,10 +542,10 @@ def _get_darknet_attrs(net, layer_num):
551542
attr.update({'background' : layer.background})
552543
attr.update({'softmax' : layer.softmax})
553544
else:
554-
err = "Darknet layer {} is not supported in nnvm.".format(op_name)
545+
err = "Darknet layer type {} is not supported in nnvm.".format(layer.type)
555546
raise NotImplementedError(err)
556547

557-
return op_name, attr
548+
return layer.type, attr
558549

559550
def _get_tvm_params_name(opname, arg_name):
560551
"""Makes the params name for the k,v pair."""

nnvm/python/nnvm/testing/darknet.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"""
99
from __future__ import division
1010
import math
11-
from enum import IntEnum
1211
import numpy as np
1312
import cv2
1413
from cffi import FFI
@@ -91,7 +90,7 @@ def load_image(image, resize_width, resize_height):
9190
img = load_image_color(image)
9291
return _letterbox_image(img, resize_width, resize_height)
9392

94-
class LAYERTYPE(IntEnum):
93+
class LAYERTYPE(object):
9594
"""Darknet LAYERTYPE Class constant."""
9695
CONVOLUTIONAL = 0
9796
DECONVOLUTIONAL = 1
@@ -119,7 +118,7 @@ class LAYERTYPE(IntEnum):
119118
REORG = 23
120119
BLANK = 24
121120

122-
class ACTIVATION(IntEnum):
121+
class ACTIVATION(object):
123122
"""Darknet ACTIVATION Class constant."""
124123
LOGISTIC = 0
125124
RELU = 1

0 commit comments

Comments
 (0)