Skip to content

Commit

Permalink
[Darknet] softmax temperature in frontend (apache#1429)
Browse files Browse the repository at this point in the history
  • Loading branch information
siju-samuel authored and sergei-mironov committed Aug 8, 2018
1 parent b8a747a commit 91b0e5b
Show file tree
Hide file tree
Showing 2 changed files with 313 additions and 284 deletions.
5 changes: 5 additions & 0 deletions nnvm/python/nnvm/frontend/darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ def _darknet_reshape(inputs, attrs):

def _darknet_softmax_output(inputs, attrs):
"""Process the softmax operation."""
temperature = attrs.get('temperature', 1)
if temperature != 1:
inputs[0] = inputs[0] / float(temperature)
op_name, new_attrs = 'softmax', {}
if _darknet_parse_bool_str(attrs, 'multi_output'):
new_attrs['axis'] = 1
Expand Down Expand Up @@ -529,6 +532,8 @@ def _get_darknet_attrs(net, layer_num):
elif LAYERTYPE.SOFTMAX == layer.type:
attr.update({'axis' : 1})
attr.update({'use_flatten' : True})
if layer.temperature:
attr.update({'temperature' : str(layer.temperature)})

elif LAYERTYPE.SHORTCUT == layer.type:
add_layer = net.layers[layer.index]
Expand Down
Loading

0 comments on commit 91b0e5b

Please sign in to comment.