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

Method initialize

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

Source from the content-addressed store, hash-verified

396 self.bias_shape = bias_shape
397
398 def initialize(self, x):
399 if self.transA == 0:
400 self.in_features = x.shape[-1]
401 else:
402 self.in_features = x.shape[0]
403
404 if self.transB == 0:
405 w_shape = (self.in_features, self.nb_kernels)
406 else:
407 w_shape = (self.nb_kernels, self.in_features)
408
409 if self.bias_shape:
410 b_shape = self.bias_shape
411 else:
412 b_shape = (1, self.nb_kernels)
413
414 self.W = Tensor(shape=w_shape,
415 requires_grad=True,
416 stores_grad=True,
417 device=x.device)
418 std = math.sqrt(2.0 / (self.in_features + self.nb_kernels))
419 self.W.gaussian(0.0, std)
420
421 if self.bias:
422 self.b = Tensor(shape=b_shape,
423 requires_grad=True,
424 stores_grad=True,
425 device=x.device)
426 self.b.set_value(0.0)
427 else:
428 self.b = None
429
430 def forward(self, x):
431 if self.b:

Callers

nothing calls this directly

Calls 3

TensorClass · 0.70
gaussianMethod · 0.45
set_valueMethod · 0.45

Tested by

no test coverage detected