MCPcopy Create free account
hub / github.com/apache/singa / initialize

Method initialize

python/singa/layer.py:822–850  ·  view source on GitHub ↗
(self, x)

Source from the content-addressed store, hash-verified

820 assert 0 <= momentum <= 1.0, ("Illegal momentum")
821
822 def initialize(self, x):
823 self.channels = x.shape[1]
824 param_shape = (self.channels,)
825
826 self.scale = Tensor(shape=param_shape,
827 requires_grad=True,
828 stores_grad=True)
829 self.scale.set_value(1.0)
830
831 self.bias = Tensor(shape=param_shape,
832 requires_grad=True,
833 stores_grad=True)
834 self.bias.set_value(0.0)
835
836 self.running_mean = Tensor(shape=param_shape,
837 requires_grad=False,
838 stores_grad=False)
839 self.running_mean.set_value(0.0)
840
841 self.running_var = Tensor(shape=param_shape,
842 requires_grad=False,
843 stores_grad=False)
844 self.running_var.set_value(1.0)
845
846 if not hasattr(self, "handle"):
847 if x.device.id() == -1:
848 self.handle = singa.BatchNormHandle(self.momentum, x.data)
849 else:
850 self.handle = singa.CudnnBatchNormHandle(self.momentum, x.data)
851
852 def forward(self, x):
853 assert x.shape[1] == self.channels, (

Callers

nothing calls this directly

Calls 5

BatchNormHandleMethod · 0.80
CudnnBatchNormHandleMethod · 0.80
TensorClass · 0.70
set_valueMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected