def __init__(self, bins=10, momentum=0.0): super(GHMCLoss, self).__init__() self.bins = bins self.momentum = momentum edges_left = np.array([float(x) / bins for x in range(bins)], dtype=np.float32) self.edges_left = Tensor(edges_left.reshape((bins, 1, 1, 1, 1))) edges_right = np.array([float(x) / bins for x in range(1, bins + 1)], dtype=np.float32) edges_right[-1] += 1e-4 self.edges_right = Tensor(edges_right.reshape((bins, 1, 1, 1, 1))) if momentum >= 0: self.acc_sum = Parameter(initializer(0, [bins], mstype.float32)) self.abs = ops.Abs() self.log = ops.Log() self.cast = ops.Cast() self.select = ops.Select() self.reshape = ops.Reshape() self.reduce_sum = ops.ReduceSum() self.max = ops.Maximum() self.less = ops.Less() self.equal = ops.Equal() self.greater = ops.Greater() self.logical_and = ops.LogicalAnd() self.greater_equal = ops.GreaterEqual() self.zeros_like = ops.ZerosLike() self.expand_dims = ops.ExpandDims()
def __init__(self): super(log_sum_exp, self).__init__() self.maxi = P.ReduceMax() self.maxi_dim = P.ReduceMax(keep_dims=True) self.log = P.Log() self.sums = P.ReduceSum() self.exp = P.Exp()
def __init__(self): super(log_softmax, self).__init__() self.maxi = P.ReduceMax() self.log = P.Log() self.sums = P.ReduceSum() self.exp = P.Exp() self.axis = -1 self.concat = P.Concat(-1) self.expanddims = P.ExpandDims()
def __init__(self, alpha=2, beta=4): super(FocalLoss, self).__init__() self.alpha = alpha self.beta = beta self.pow = ops.Pow() self.log = ops.Log() self.select = ops.Select() self.equal = ops.Equal() self.less = ops.Less() self.cast = ops.Cast() self.fill = ops.Fill() self.dtype = ops.DType() self.shape = ops.Shape() self.reduce_sum = ops.ReduceSum()
def __init__(self, model, config, is_training, dropout_prob=0.0, use_one_hot_embeddings=False): super(BertPoetry, self).__init__(auto_prefix=False) self.num_tokens = 3191 self.poetry = model self.onehot = ops.OneHot() self.on_value = Tensor(1.0, mstype.float32) self.off_value = Tensor(0.0, mstype.float32) self.reduce_sum = ops.ReduceSum() self.reduce_mean = ops.ReduceMean() self.reshape = ops.Reshape() self.neg = ops.Neg() self.cast = ops.Cast() self.last_idx = (-1,) self.log = ops.Log() self.max = ops.ArgMaxWithValue(axis=-1)
def __init__(self, sparse=False): super(SoftmaxCrossEntropyExpand, self).__init__() self.exp = ops.Exp() self.sum = ops.ReduceSum(keep_dims=True) self.onehot = ops.OneHot() self.on_value = Tensor(1.0, mstype.float32) self.off_value = Tensor(0.0, mstype.float32) self.div = ops.RealDiv() self.log = ops.Log() self.sum_cross_entropy = ops.ReduceSum(keep_dims=False) self.mul = ops.Mul() self.mul2 = ops.Mul() self.mean = ops.ReduceMean(keep_dims=False) self.sparse = sparse self.max = ops.ReduceMax(keep_dims=True) self.sub = ops.Sub()
def __init__(self, log_scale_min=-7.0, reduce=True): super(mix_gaussian_loss, self).__init__() self.log_scale_min = log_scale_min self.reduce = reduce self.transpose_op = P.Transpose() self.maximum = P.Maximum() self.tile = P.Tile() self.exp = P.Exp() self.logsoftmax = P.LogSoftmax(-1) self.expand_dims = P.ExpandDims() self.sums = P.ReduceSum() self.lse = log_sum_exp() self.sq = P.Square() self.sqrt = P.Sqrt() self.const = P.ScalarToArray() self.log = P.Log()
def __init__(self, num_classes=256, log_scale_min=-7.0, reduce=True): super(discretized_mix_logistic_loss, self).__init__() self.num_classes = num_classes self.log_scale_min = log_scale_min self.reduce = reduce self.transpose_op = P.Transpose() self.exp = P.Exp() self.sigmoid = P.Sigmoid() self.softplus = Stable_softplus() self.log = P.Log() self.cast = P.Cast() self.logsoftmax = P.LogSoftmax(-1) self.expand_dims = P.ExpandDims() self.tile = P.Tile() self.maximum = P.Maximum() self.sums = P.ReduceSum() self.lse = log_sum_exp() self.reshape = P.Reshape() self.factor = self.log(Tensor((self.num_classes - 1) / 2, ms.float32))
def __init__(self, log_scale_min=-7.0, reduce=True): super(mix_gaussian_loss, self).__init__() self.log_scale_min = log_scale_min self.reduce = reduce self.transpose_op = P.Transpose() self.maximum = P.Maximum() self.tile = P.Tile() self.exp = P.Exp() self.expand_dims = P.ExpandDims() self.sums = P.ReduceSum() self.lse = log_sum_exp() self.sq = P.Square() self.sqrt = P.Sqrt() self.const = P.ScalarToArray() self.log = P.Log() self.tensor_one = Tensor(1., ms.float32) if context.get_context("device_target") == "CPU": self.logsoftmax = log_softmax() else: self.logsoftmax = P.LogSoftmax(-1)
def __init__(self): super(Stable_softplus, self).__init__() self.log_op = P.Log() self.abs_op = P.Abs() self.relu_op = P.ReLU() self.exp_op = P.Exp()