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

Method initialize

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

Source from the content-addressed store, hash-verified

962 self.pad_mode = pad_mode
963
964 def initialize(self, x):
965 # if same pad mode, re-compute the padding
966 if self.pad_mode in ("SAME_UPPER", "SAME_LOWER"):
967 self.padding, self.odd_padding = utils.get_padding_shape(
968 self.pad_mode, x.shape[2:], self.kernel_size, self.stride)
969
970 # if same pad mode, re-compute the padding
971 if self.pad_mode in ("SAME_UPPER", "SAME_LOWER"):
972 self.padding, self.odd_padding = utils.get_padding_shape(
973 self.pad_mode, x.shape[2:], self.kernel_size, self.stride)
974 self.padding = [self.padding[0], self.padding[2]]
975
976 _x = x
977 if self.odd_padding != (0, 0, 0, 0):
978 x_shape = list(x.data.shape())
979 x_shape[2] += (self.odd_padding[0] + self.odd_padding[1])
980 x_shape[3] += (self.odd_padding[2] + self.odd_padding[3])
981 _x = Tensor(shape=x_shape, device=x.device)
982 _x.set_value(0.0)
983
984 if _x.device.id() == -1:
985 self.handle = singa.PoolingHandle(
986 _x.data,
987 self.kernel_size,
988 self.stride,
989 self.padding,
990 self.is_max,
991 )
992 else:
993 self.handle = singa.CudnnPoolingHandle(
994 _x.data,
995 self.kernel_size,
996 self.stride,
997 self.padding,
998 self.is_max,
999 )
1000
1001 def forward(self, x):
1002 y = autograd.pooling_2d(self.handle, x, self.odd_padding)

Callers

nothing calls this directly

Calls 6

set_valueMethod · 0.95
shapeMethod · 0.80
PoolingHandleMethod · 0.80
CudnnPoolingHandleMethod · 0.80
TensorClass · 0.70
idMethod · 0.45

Tested by

no test coverage detected