Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
CNNArch2Gluon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
monticore
EmbeddedMontiArc
generators
CNNArch2Gluon
Commits
c3dc2a23
Commit
c3dc2a23
authored
Mar 07, 2020
by
Julian Treiber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added metric loss accuracy_ignore_label
parent
2990a673
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
src/main/resources/templates/gluon/CNNSupervisedTrainer.ftl
src/main/resources/templates/gluon/CNNSupervisedTrainer.ftl
+26
-2
src/main/resources/templates/gluon/CNNTrainer.ftl
src/main/resources/templates/gluon/CNNTrainer.ftl
+1
-1
No files found.
src/main/resources/templates/gluon/CNNSupervisedTrainer.ftl
View file @
c3dc2a23
...
@@ -87,15 +87,35 @@ class DiceLoss(gluon.loss.Loss):
...
@@ -87,15 +87,35 @@ class DiceLoss(gluon.loss.Loss):
diceloss = self.dice_loss(F, pred, label)
diceloss = self.dice_loss(F, pred, label)
return F.mean(loss, axis=self._batch_axis, exclude=True) + diceloss
return F.mean(loss, axis=self._batch_axis, exclude=True) + diceloss
class SoftmaxCrossEntropyLossIgnoreLabel(gluon.loss.Loss):
def __init__(self, axis=-1, from_logits=False, weight=None,
batch_axis=0, ignore_label=255, **kwargs):
super(SoftmaxCrossEntropyLossIgnoreLabel, self).__init__(weight, batch_axis, **kwargs)
self._axis = axis
self._from_logits = from_logits
self._ignore_label = ignore_label
def hybrid_forward(self, F, output, label, sample_weight=None):
if not self._from_logits:
output = F.log_softmax(output, axis=self._axis)
valid_label_map = (label != self._ignore_label)
loss = -(F.pick(output, label, axis=self._axis, keepdims=True) * valid_label_map )
loss = gluon.loss._apply_weighting(F, loss, self._weight, sample_weight)
return F.sum(loss) / F.sum(valid_label_map)
@mx.metric.register
@mx.metric.register
class ACCURACY_IGNORE_LABEL(mx.metric.EvalMetric):
class ACCURACY_IGNORE_LABEL(mx.metric.EvalMetric):
def __init__(self, axis=1, ignore_label=255, name='accuracy',
"""Ignores a label when computing accuracy.
"""
def __init__(self, axis=1, metric_ignore_label=255, name='accuracy',
output_names=None, label_names=None):
output_names=None, label_names=None):
super(ACCURACY_IGNORE_LABEL, self).__init__(
super(ACCURACY_IGNORE_LABEL, self).__init__(
name, axis=axis,
name, axis=axis,
output_names=output_names, label_names=label_names)
output_names=output_names, label_names=label_names)
self.axis = axis
self.axis = axis
self.ignore_label = ignore_label
self.ignore_label =
metric_
ignore_label
def update(self, labels, preds):
def update(self, labels, preds):
mx.metric.check_label_shapes(labels, preds)
mx.metric.check_label_shapes(labels, preds)
...
@@ -328,6 +348,10 @@ class ${tc.fileNameWithoutEnding}:
...
@@ -328,6 +348,10 @@ class ${tc.fileNameWithoutEnding}:
elif loss == 'dice_loss':
elif loss == 'dice_loss':
loss_weight = loss_params['loss_weight'] if 'loss_weight' in loss_params else None
loss_weight = loss_params['loss_weight'] if 'loss_weight' in loss_params else None
loss_function = DiceLoss(axis=loss_axis, weight=loss_weight, sparse_label=sparseLabel, batch_axis=batch_axis)
loss_function = DiceLoss(axis=loss_axis, weight=loss_weight, sparse_label=sparseLabel, batch_axis=batch_axis)
elif loss == 'softmax_cross_entropy_ignore_label':
loss_weight = loss_params['loss_weight'] if 'loss_weight' in loss_params else None
loss_ignore_label = loss_params['loss_ignore_label'] if 'loss_ignore_label' in loss_params else None
loss_function = SoftmaxCrossEntropyLossIgnoreLabel(axis=loss_axis, ignore_label=loss_ignore_label, weight=loss_weight, batch_axis=batch_axis)
elif loss == 'l2':
elif loss == 'l2':
loss_function = mx.gluon.loss.L2Loss()
loss_function = mx.gluon.loss.L2Loss()
elif loss == 'l1':
elif loss == 'l1':
...
...
src/main/resources/templates/gluon/CNNTrainer.ftl
View file @
c3dc2a23
...
@@ -71,7 +71,7 @@ if __name__ == "__main__":
...
@@ -71,7 +71,7 @@ if __name__ == "__main__":
'axis': ${config.evalMetric.axis},
'axis': ${config.evalMetric.axis},
</#if>
</#if>
<#if (config.evalMetric.exclude)??>
<#if (config.evalMetric.exclude)??>
'
ignore_label': ${config.evalMetric.
ignore_label},
'
metric_ignore_label': ${config.evalMetric.metric_
ignore_label},
</#if>
</#if>
},
},
</#if>
</#if>
...
...
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