def __init__(self, loc=None, scale=None, seed=None, dtype=mstype.float32, name="Logistic"): """ Constructor of Logistic. """ param = dict(locals()) param['param_dict'] = {'loc': loc, 'scale': scale} valid_dtype = mstype.float_type Validator.check_type_name("dtype", dtype, valid_dtype, type(self).__name__) super(Logistic, self).__init__(seed, dtype, name, param) self._loc = self._add_parameter(loc, 'loc') self._scale = self._add_parameter(scale, 'scale') if self._scale is not None: check_greater_zero(self._scale, "scale") # ops needed for the class self.cast = P.Cast() self.const = P.ScalarToArray() self.consttensor = P.ScalarToTensor() self.dtypeop = P.DType() self.exp = exp_generic self.expm1 = P.Expm1() self.fill = P.Fill() self.less = P.Less() self.log = log_generic self.log1p = P.Log1p() self.logicalor = P.LogicalOr() self.erf = P.Erf() self.greater = P.Greater() self.sigmoid = P.Sigmoid() self.squeeze = P.Squeeze(0) self.select = P.Select() self.shape = P.Shape() self.softplus = self._softplus self.sqrt = P.Sqrt() self.uniform = C.uniform self.threshold = np.log(np.finfo(np.float32).eps) + 1. self.tiny = np.finfo(np.float).tiny self.sd_const = np.pi / np.sqrt(3)
def __init__(self): super(LBeta, self).__init__() # const numbers self.log_2pi = np.log(2 * np.pi) self.minimax_coeff = [ -0.165322962780713e-02, 0.837308034031215e-03, -0.595202931351870e-03, 0.793650666825390e-03, -0.277777777760991e-02, 0.833333333333333e-01 ] # operations self.log = P.Log() self.log1p = P.Log1p() self.less = P.Less() self.select = P.Select() self.shape = P.Shape() self.dtype = P.DType() self.lgamma = LGamma() self.const = P.ScalarToTensor()
def __init__(self, args, conv=default_conv): super(IPT, self).__init__() self.dytpe = mstype.float16 self.scale_idx = 0 self.args = args self.con_loss = args.con_loss n_feats = args.n_feats kernel_size = 3 act = nn.ReLU() self.head = nn.CellList([ nn.SequentialCell(conv(args.n_colors, n_feats, kernel_size).to_float(self.dytpe), ResBlock(conv, n_feats, 5, act=act).to_float(self.dytpe), ResBlock(conv, n_feats, 5, act=act).to_float(self.dytpe)) for _ in range(6)]) self.body = VisionTransformer(img_dim=args.patch_size, patch_dim=args.patch_dim, num_channels=n_feats, embedding_dim=n_feats * args.patch_dim * args.patch_dim, num_heads=args.num_heads, num_layers=args.num_layers, hidden_dim=n_feats * args.patch_dim * args.patch_dim * 4, num_queries=args.num_queries, dropout_rate=args.dropout_rate, mlp=args.no_mlp, pos_every=args.pos_every, no_pos=args.no_pos, con_loss=args.con_loss).to_float(self.dytpe) self.tail = nn.CellList([ nn.SequentialCell(Upsampler(conv, s, n_feats).to_float(self.dytpe), conv(n_feats, args.n_colors, kernel_size).to_float(self.dytpe)) \ for s in [2, 3, 4, 1, 1, 1]]) self.reshape = P.Reshape() self.tile = P.Tile() self.transpose = P.Transpose() self.s2t = P.ScalarToTensor() self.cast = P.Cast()