def __init__(self, mul_weight, strategy1=None, strategy2=None):
     super().__init__()
     self.mul = P.Mul().shard(strategy1)
     self.dropout_do_mask = P.DropoutDoMask().shard(strategy2)
     self.dropout_gen_mask = P.DropoutGenMask()
     self.get_shape = P.Shape()
     self.cast = P.Cast()
     self.mul_weight = Parameter(mul_weight, "w1")
     self.keep_prob = Tensor(0.9)
Esempio n. 2
0
def test_dropout():
    dropOutGenMask = P.DropoutGenMask()
    dropoutDoMask = P.DropoutDoMask()
    shape = P.Shape()

    def get_dropout(x, prob):
        mask = dropOutGenMask(shape(x), prob)
        y = dropoutDoMask(x, mask, prob)
        return y

    return get_dropout
Esempio n. 3
0
 def __init__(self, keep_prob=0.5, seed0=0, seed1=0, dtype=mstype.float32):
     super(Dropout, self).__init__()
     if keep_prob <= 0 or keep_prob > 1:
         raise ValueError("dropout probability should be a number in range (0, 1], but got {}".format(keep_prob))
     validator.check_subclass("dtype", dtype, mstype.number_type, self.cls_name)
     self.keep_prob = Tensor(keep_prob)
     self.seed0 = seed0
     self.seed1 = seed1
     self.dtype = dtype
     self.get_shape = P.Shape()
     self.dropout_gen_mask = P.DropoutGenMask(Seed0=seed0, Seed1=seed1)
     self.dropout_do_mask = P.DropoutDoMask()
     self.cast = P.Cast()
Esempio n. 4
0
 def __init__(self, keep_prob=0.5, dtype=mstype.float32):
     super(Dropout, self).__init__()
     if keep_prob <= 0 or keep_prob > 1:
         raise ValueError("dropout probability should be a number in range (0, 1], but got {}".format(keep_prob))
     Validator.check_subclass("dtype", dtype, mstype.number_type, self.cls_name)
     Validator.check_value_type('keep_prob', keep_prob, [float], self.cls_name)
     self.keep_prob = keep_prob
     seed0, seed1 = _get_graph_seed(0, "dropout")
     self.seed0 = seed0
     self.seed1 = seed1
     self.dtype = dtype
     self.get_shape = P.Shape()
     self.dropout_gen_mask = P.DropoutGenMask(Seed0=self.seed0, Seed1=self.seed1)
     self.dropout_do_mask = P.DropoutDoMask()
     self.cast = P.Cast()
     self.is_gpu = context.get_context('device_target') in ["GPU"]
     self.dropout = P.Dropout(keep_prob)
Esempio n. 5
0
     'desc_bprop': [[8192,1024]],
     'skip': ['backward']}),
 ('UnsortedSegmentSum_1', {
     'block': P.UnsortedSegmentSum(),
     'desc_const': [4],
     'desc_inputs': [[3, 2, 1, 3], Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
     'desc_bprop': [[4, 1, 3]],
     'skip': ['backward']}),
 ('DropoutGenMask', {
     'block': P.DropoutGenMask(),
     'desc_const': [(2, 2), Tensor(0.5, mstype.float32)],
     'desc_inputs': [],
     'desc_bprop': [Tensor(np.ones(1).astype(np.int8))],
     'skip': ['backward']}),
 ('DropoutDoMask', {
     'block': P.DropoutDoMask(),
     'desc_const': [Tensor(0.5)],
     'desc_inputs': [[64, 12, 128, 128], Tensor(np.ones(1572864).astype(np.uint8))],
     'desc_bprop': [[64, 12, 128, 128]]}),
 ('Dropout', {
     'block': nn.Dropout(0.5),
     'desc_inputs': [[64, 12, 128, 128]],
     'desc_bprop': [[64, 12, 128, 128]]}),
 ('ReduceMean0', {
     'block': P.ReduceMean(),
     'desc_const': [(2,)],
     'desc_inputs': [[3, 2, 2]],
     'desc_bprop': [[3, 2]]}),
 ('ReduceMean1', {
     'block': P.ReduceMean(),
     'desc_const': [2],
 def __init__(self):
     super(Net, self).__init__()
     self.dropoutdomask = P.DropoutDoMask()
Esempio n. 7
0
     'desc_inputs':
     [[3, 2, 1, 3],
      Tensor(np.array([[0, 1], [0, 1], [0, 1]]).astype(np.int32))],
     'desc_bprop': [[4, 1, 3]],
     'skip': ['backward']
 }),
 ('DropoutGenMask', {
     'block': P.DropoutGenMask(),
     'desc_const': [(2, 2), Tensor(0.5, mstype.float32)],
     'desc_inputs': [],
     'desc_bprop': [Tensor(np.ones(1).astype(np.int8))],
     'skip': ['backward']
 }),
 ('DropoutDoMask', {
     'block':
     P.DropoutDoMask(),
     'desc_const': [Tensor(0.5)],
     'desc_inputs': [[64, 12, 128, 128],
                     Tensor(np.ones(1572864).astype(np.uint8))],
     'desc_bprop': [[64, 12, 128, 128]]
 }),
 ('Dropout', {
     'block': nn.Dropout(0.5),
     'desc_inputs': [[64, 12, 128, 128]],
     'desc_bprop': [[64, 12, 128, 128]]
 }),
 ('ReduceMean0', {
     'block': P.ReduceMean(),
     'desc_const': [(2, )],
     'desc_inputs': [[3, 2, 2]],
     'desc_bprop': [[3, 2]]