def _initialize_weight_default(shape=None, layer_type='conv', bias=False): if layer_type not in ('conv', 'bn', 'fc'): raise ValueError('The layer type is not known, the supported are conv, bn and fc') if bias and layer_type == 'bn': return Zero() if layer_type == 'conv': return One() if layer_type == 'bn': return One() return One()
def _initialize_weight_goog(shape=None, layer_type='conv', bias=False): if layer_type not in ('conv', 'bn', 'fc'): raise ValueError('The layer type is not known, the supported are conv, bn and fc') if bias: return Zero() if layer_type == 'conv': assert isinstance(shape, (tuple, list)) and len( shape) == 3, 'The shape must be 3 scalars, and are in_chs, ks, out_chs respectively' n = shape[1] * shape[1] * shape[2] return Normal(math.sqrt(2.0 / n)) if layer_type == 'bn': return One() assert isinstance(shape, (tuple, list)) and len( shape) == 2, 'The shape must be 2 scalars, and are in_chs, out_chs respectively' n = shape[1] init_range = 1.0 / math.sqrt(n) return Uniform(init_range)
def weight_variable(shape, factor=0.1): return One()
def test_zero_dimension_with_zero_shape(): with pytest.raises(ValueError) as ex: Tensor(shape=(1, 0, 3), dtype=mindspore.float32, init=One()) assert "Shape can not contain zero value." in str(ex.value)
def weight_variable(): return One()