Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NNVM][FRONTEND]C-RNN layer support is added for darknet #1492

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions nnvm/python/nnvm/frontend/darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,31 @@ def _handle_darknet_rnn_layers(self, layer_num, sym):
self._sym_array[layer_num] = sym
processed = True

elif LAYERTYPE.CRNN == layer.type:
attr.update({'n' : layer.n})
attr.update({'batch' : layer.batch})
attr.update({'num_hidden' : str(layer.outputs)})

state = self._get_rnn_state_buffer(layer)

for _ in range(layer.steps):
input_layer = layer.input_layer
sym = self._get_darknet_rnn_attrs(input_layer, sym)

self_layer = layer.self_layer
state = self._get_darknet_rnn_attrs(self_layer, state)

op_name, new_attrs = 'elemwise_add', {}
new_inputs = _as_list([sym, state])
state = _darknet_get_nnvm_op(op_name)(*new_inputs, **new_attrs)
self._outs.append(state)

output_layer = layer.output_layer
sym = self._get_darknet_rnn_attrs(output_layer, state)

self._sym_array[layer_num] = sym
processed = True

return processed, sym

def from_darknet(self):
Expand Down
26 changes: 26 additions & 0 deletions nnvm/tests/python/frontend/darknet/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,31 @@ def test_forward_rnn():
test_rnn_forward(net)
LIB.free_network(net)

def test_forward_crnn():
'''test softmax layer'''
net = LIB.make_network(1)
batch = 1
c = 3
h = 224
w = 224
hidden_filters = c
output_filters = c
steps = 1
activation = 0
batch_normalize = 0
inputs = 256
outputs = 256
layer_1 = LIB.make_crnn_layer(batch, h, w, c, hidden_filters, output_filters,
steps, activation, batch_normalize)
net.layers[0] = layer_1
net.inputs = inputs
net.outputs = output_filters * h * w
net.w = w
net.h = h
LIB.resize_network(net, net.w, net.h)
test_forward(net)
LIB.free_network(net)

def test_forward_activation_logistic():
'''test logistic activation layer'''
net = LIB.make_network(1)
Expand Down Expand Up @@ -369,4 +394,5 @@ def test_forward_activation_logistic():
test_forward_region()
test_forward_elu()
test_forward_rnn()
test_forward_crnn()
test_forward_activation_logistic()