Exemple #1
0
 def __init__(self, sparse=False, reduction='none'):
     super(SoftmaxCrossEntropyWithLogits, self).__init__(reduction)
     self.sparse = validator.check_bool(sparse, "sparse")
     self.reduction = reduction
     self.softmax_cross_entropy = _selected_ops.SoftmaxCrossEntropyWithLogits(
     )
     self.one_hot = P.OneHot()
     self.on_value = Tensor(1.0, mstype.float32)
     self.off_value = Tensor(0., mstype.float32)
     self.is_cpugpu = context.get_context('device_target') in ["CPU", "GPU"]
     self.sparse_softmax_cross_entropy = P.SparseSoftmaxCrossEntropyWithLogits(
     )
Exemple #2
0
    def __init__(self,
                 is_grad=True,
                 sparse=False,
                 reduction=None,
                 smooth_factor=0,
                 num_classes=2):
        super(SoftmaxCrossEntropyWithLogits, self).__init__(reduction)
        self.is_grad = is_grad
        self.sparse = sparse
        validator.check_number_range("smooth_factor", smooth_factor, 0, 1,
                                     Rel.INC_BOTH, self.cls_name)
        self.smooth_factor = smooth_factor
        self.num_classes = num_classes
        self.softmax_cross_entropy = _selected_ops.SoftmaxCrossEntropyWithLogits(
        )
        self.one_hot = P.OneHot()
        self.on_value = Tensor(1.0 - self.smooth_factor, mstype.float32)
        self.off_value = Tensor(
            1.0 * self.smooth_factor / (self.num_classes - 1), mstype.float32)
        self.is_cpugpu = context.get_context('device_target') in ["CPU", "GPU"]

        if self.is_cpugpu:
            self.sparse_softmax_cross_entropy = P.SparseSoftmaxCrossEntropyWithLogits(
                is_grad=self.is_grad)