Commit 01c16d6c authored by Christian Fuß's avatar Christian Fuß
Browse files

added functionality for ArgMax layer

parent f337232c
Pipeline #181546 failed with stages
in 2 minutes
...@@ -185,13 +185,19 @@ class ${tc.fileNameWithoutEnding}: ...@@ -185,13 +185,19 @@ class ${tc.fileNameWithoutEnding}:
if True: <#-- Fix indentation --> if True: <#-- Fix indentation -->
<#include "pythonExecute.ftl"> <#include "pythonExecute.ftl">
predictions = [ out_names=[]
<#list tc.architectureOutputs as output_name> <#list tc.architectureOutputs as output_name>
mx.nd.argmax(${output_name}, axis=1)<#sep>, out_names.append(${output_name})
</#list> </#list>
] predictions = []
for output_name in out_names:
if mx.nd.shape_array(output_name).size > 1:
predictions.append(mx.nd.argmax(output_name, axis=1))
#ArgMax already applied
else:
predictions.append(output_name)
<#include "elements/BeamSearchStart.ftl"> <#include "elements/BeamSearch.ftl">
metric.update(preds=predictions, labels=labels) metric.update(preds=predictions, labels=labels)
train_metric_score = metric.get()[1] train_metric_score = metric.get()[1]
...@@ -213,12 +219,17 @@ class ${tc.fileNameWithoutEnding}: ...@@ -213,12 +219,17 @@ class ${tc.fileNameWithoutEnding}:
if True: <#-- Fix indentation --> if True: <#-- Fix indentation -->
<#include "pythonExecute.ftl"> <#include "pythonExecute.ftl">
predictions = [ out_names=[]
<#list tc.architectureOutputs as output_name> <#list tc.architectureOutputs as output_name>
mx.nd.argmax(${output_name}, axis=1)<#sep>, out_names.append(${output_name})
</#list> </#list>
predictions = []
] for output_name in out_names:
if mx.nd.shape_array(output_name).size > 1:
predictions.append(mx.nd.argmax(output_name, axis=1))
#ArgMax already applied
else:
predictions.append(output_name)
metric.update(preds=predictions, labels=labels) metric.update(preds=predictions, labels=labels)
test_metric_score = metric.get()[1] test_metric_score = metric.get()[1]
......
<#assign input = element.inputs[0]> <#assign input = element.inputs[0]>
<#if mode == "FORWARD_FUNCTION"> <#if mode == "FORWARD_FUNCTION">
${element.name} = F.ndarray.argmax(${input}, keepdims=True) <#-- only passtrough method, argmax logic is applied in pythonExecute.ftl and CNNSupervisedTrainer.ftl -->
${element.name} = ${input}
</#if> </#if>
\ No newline at end of file
...@@ -9,10 +9,20 @@ ...@@ -9,10 +9,20 @@
<#if networkInstruction.isUnroll()> <#if networkInstruction.isUnroll()>
<#list networkInstruction.toUnrollInstruction().resolvedBodies as resolvedBody> <#list networkInstruction.toUnrollInstruction().resolvedBodies as resolvedBody>
${tc.join(tc.getStreamOutputNames(networkInstruction.body, resolvedBody), ", ")} = self._networks[${networkInstruction?index}](${tc.join(tc.getStreamInputNames(networkInstruction.body, resolvedBody), ", ")}) ${tc.join(tc.getStreamOutputNames(networkInstruction.body, resolvedBody), ", ")} = self._networks[${networkInstruction?index}](${tc.join(tc.getStreamInputNames(networkInstruction.body, resolvedBody), ", ")})
<#list resolvedBody.elements as element>
<#if element.name == "ArgMax">
${tc.join(tc.getStreamOutputNames(networkInstruction.body, resolvedBody), ", ")} = mx.nd.argmax(${tc.join(tc.getStreamOutputNames(networkInstruction.body, resolvedBody), ", ")}, axis=1)
</#if>
</#list>
</#list> </#list>
<#else> <#else>
<#if networkInstruction.body.isTrainable()> <#if networkInstruction.body.isTrainable()>
${tc.join(tc.getStreamOutputNames(networkInstruction.body), ", ")} = self._networks[${networkInstruction?index}](${tc.join(tc.getStreamInputNames(networkInstruction.body), ", ")}) ${tc.join(tc.getStreamOutputNames(networkInstruction.body), ", ")} = self._networks[${networkInstruction?index}](${tc.join(tc.getStreamInputNames(networkInstruction.body), ", ")})
<#list networkInstruction.body.elements as element>
<#if element.name == "ArgMax">
${tc.join(tc.getStreamOutputNames(networkInstruction.body), ", ")} = mx.nd.argmax(${tc.join(tc.getStreamOutputNames(networkInstruction.body), ", ")}, axis=1)
</#if>
</#list>
<#else> <#else>
${tc.include(networkInstruction.body, "PYTHON_INLINE")} ${tc.include(networkInstruction.body, "PYTHON_INLINE")}
</#if> </#if>
......
...@@ -140,7 +140,6 @@ class CNNSupervisedTrainer_Alexnet: ...@@ -140,7 +140,6 @@ class CNNSupervisedTrainer_Alexnet:
predictions_ = self._networks[0](data_) predictions_ = self._networks[0](data_)
loss = \ loss = \
loss_function(predictions_, predictions_label) loss_function(predictions_, predictions_label)
...@@ -178,9 +177,15 @@ class CNNSupervisedTrainer_Alexnet: ...@@ -178,9 +177,15 @@ class CNNSupervisedTrainer_Alexnet:
predictions_ = self._networks[0](data_) predictions_ = self._networks[0](data_)
out_names=[]
predictions = [ out_names.append(predictions_)
mx.nd.argmax(predictions_, axis=1)] predictions = []
for output_name in out_names:
if mx.nd.shape_array(output_name).size > 1:
predictions.append(mx.nd.argmax(output_name, axis=1))
#ArgMax already applied
else:
predictions.append(output_name)
metric.update(preds=predictions, labels=labels) metric.update(preds=predictions, labels=labels)
...@@ -200,10 +205,15 @@ class CNNSupervisedTrainer_Alexnet: ...@@ -200,10 +205,15 @@ class CNNSupervisedTrainer_Alexnet:
predictions_ = self._networks[0](data_) predictions_ = self._networks[0](data_)
out_names=[]
predictions = [ out_names.append(predictions_)
mx.nd.argmax(predictions_, axis=1) predictions = []
] for output_name in out_names:
if mx.nd.shape_array(output_name).size > 1:
predictions.append(mx.nd.argmax(output_name, axis=1))
#ArgMax already applied
else:
predictions.append(output_name)
metric.update(preds=predictions, labels=labels) metric.update(preds=predictions, labels=labels)
test_metric_score = metric.get()[1] test_metric_score = metric.get()[1]
......
...@@ -140,7 +140,6 @@ class CNNSupervisedTrainer_CifarClassifierNetwork: ...@@ -140,7 +140,6 @@ class CNNSupervisedTrainer_CifarClassifierNetwork:
softmax_ = self._networks[0](data_) softmax_ = self._networks[0](data_)
loss = \ loss = \
loss_function(softmax_, softmax_label) loss_function(softmax_, softmax_label)
...@@ -178,9 +177,15 @@ class CNNSupervisedTrainer_CifarClassifierNetwork: ...@@ -178,9 +177,15 @@ class CNNSupervisedTrainer_CifarClassifierNetwork:
softmax_ = self._networks[0](data_) softmax_ = self._networks[0](data_)
out_names=[]
predictions = [ out_names.append(softmax_)
mx.nd.argmax(softmax_, axis=1)] predictions = []
for output_name in out_names:
if mx.nd.shape_array(output_name).size > 1:
predictions.append(mx.nd.argmax(output_name, axis=1))
#ArgMax already applied
else:
predictions.append(output_name)
metric.update(preds=predictions, labels=labels) metric.update(preds=predictions, labels=labels)
...@@ -200,10 +205,15 @@ class CNNSupervisedTrainer_CifarClassifierNetwork: ...@@ -200,10 +205,15 @@ class CNNSupervisedTrainer_CifarClassifierNetwork:
softmax_ = self._networks[0](data_) softmax_ = self._networks[0](data_)
out_names=[]
predictions = [ out_names.append(softmax_)
mx.nd.argmax(softmax_, axis=1) predictions = []
] for output_name in out_names:
if mx.nd.shape_array(output_name).size > 1:
predictions.append(mx.nd.argmax(output_name, axis=1))
#ArgMax already applied
else:
predictions.append(output_name)
metric.update(preds=predictions, labels=labels) metric.update(preds=predictions, labels=labels)
test_metric_score = metric.get()[1] test_metric_score = metric.get()[1]
......
...@@ -140,7 +140,6 @@ class CNNSupervisedTrainer_VGG16: ...@@ -140,7 +140,6 @@ class CNNSupervisedTrainer_VGG16:
predictions_ = self._networks[0](data_) predictions_ = self._networks[0](data_)
loss = \ loss = \
loss_function(predictions_, predictions_label) loss_function(predictions_, predictions_label)
...@@ -178,9 +177,15 @@ class CNNSupervisedTrainer_VGG16: ...@@ -178,9 +177,15 @@ class CNNSupervisedTrainer_VGG16:
predictions_ = self._networks[0](data_) predictions_ = self._networks[0](data_)
out_names=[]
predictions = [ out_names.append(predictions_)
mx.nd.argmax(predictions_, axis=1)] predictions = []
for output_name in out_names:
if mx.nd.shape_array(output_name).size > 1:
predictions.append(mx.nd.argmax(output_name, axis=1))
#ArgMax already applied
else:
predictions.append(output_name)
metric.update(preds=predictions, labels=labels) metric.update(preds=predictions, labels=labels)
...@@ -200,10 +205,15 @@ class CNNSupervisedTrainer_VGG16: ...@@ -200,10 +205,15 @@ class CNNSupervisedTrainer_VGG16:
predictions_ = self._networks[0](data_) predictions_ = self._networks[0](data_)
out_names=[]
predictions = [ out_names.append(predictions_)
mx.nd.argmax(predictions_, axis=1) predictions = []
] for output_name in out_names:
if mx.nd.shape_array(output_name).size > 1:
predictions.append(mx.nd.argmax(output_name, axis=1))
#ArgMax already applied
else:
predictions.append(output_name)
metric.update(preds=predictions, labels=labels) metric.update(preds=predictions, labels=labels)
test_metric_score = metric.get()[1] test_metric_score = metric.get()[1]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment