def setup_from_shape(self, in_shape): batch_size = in_shape[0] self.shape = (batch_size,) self.array = ca.zeros(self.shape) self.grad_array = ca.ones(self.shape) self.axis = tuple(range(1, len(in_shape))) self.bcast_shape = tuple([batch_size, ] + [1, ]*len(self.axis))
def fun_grad(x): ca.random.seed(seed) src.array = ca.array(x) graph.fprop() sink.grad_array = ca.ones(sink.shape, dtype=ca.float_) graph.bprop() x_grad = np.array(src.grad_array) return x_grad
def setup_from_shape(self, in_shape): batch_size = in_shape[0] self.shape = (batch_size, ) self.array = ca.zeros(self.shape) self.grad_array = ca.ones(self.shape) self.axis = tuple(range(1, len(in_shape))) self.bcast_shape = tuple([ batch_size, ] + [ 1, ] * len(self.axis))
def setup(self): super(BatchNormalization, self).setup() if len(self.out_shape) != 2: raise ValueError('Only 1D data supported') reduced_shape = 1, self.out_shape[1] self.running_mean = ca.zeros(reduced_shape) self.running_std = ca.ones(reduced_shape) self._tmp_batch_centered = ca.zeros(self.out_shape) self._tmp_batch_inv_std = ca.zeros(reduced_shape) if self.affine: self.gamma.setup(reduced_shape) self.beta.setup(reduced_shape)
def setup(self): super(BatchNormalization, self).setup() reduced_shape = (1,) + self.out_shape[1:] if self.running_mean is None: self.running_mean = ca.zeros(reduced_shape) self.running_std = ca.ones(reduced_shape) if self.affine: self.gamma.setup(reduced_shape) self.beta.setup(reduced_shape) else: if self.running_mean.shape != reduced_shape: raise ValueError('New input shape is not compatible') self._tmp_batch_inv_std = ca.zeros(reduced_shape) self._tmp_batch_centered = ca.zeros(self.out_shape)
def setup(self): super(BatchNormalization, self).setup() reduced_shape = (1, ) + self.out_shape[1:] if self.running_mean is None: self.running_mean = ca.zeros(reduced_shape) self.running_std = ca.ones(reduced_shape) if self.affine: self.gamma.setup(reduced_shape) self.beta.setup(reduced_shape) else: if self.running_mean.shape != reduced_shape: raise ValueError('New input shape is not compatible') self._tmp_batch_inv_std = ca.zeros(reduced_shape) self._tmp_batch_centered = ca.zeros(self.out_shape)
def setup(self): super(SpatialBatchNormalization, self).setup() if len(self.out_shape) != 4: raise ValueError('Only 4D data supported') reduced_shape = 1, self.out_shape[1], 1, 1 if self.running_mean is None: self.running_mean = ca.zeros(reduced_shape) self.running_std = ca.ones(reduced_shape) if self.affine: self.gamma.setup(reduced_shape) self.beta.setup(reduced_shape) else: if self.running_mean.shape != reduced_shape: raise ValueError('New input shape is not compatible') self._tmp_batch_inv_std = ca.zeros(reduced_shape) self._tmp_batch_centered = ca.zeros(self.out_shape)
def array(self, shape): return ca.ones(shape)*self.c
def array(self, shape): return ca.ones(shape) * self.value
def setup(self): self.out_shape = (self.pred.out_shape[0], 1) self.out = ca.empty(self.out_shape) self.out_grad = ca.ones(self.out_shape)
def setup(self): self.out_shape = (len(self.mu.out), 1) self.out = ca.empty(self.out_shape) self.out_grad = ca.ones(self.out_shape)