Exemple #1
0
 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))
Exemple #2
0
 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
Exemple #3
0
 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
Exemple #4
0
 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))
Exemple #5
0
 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)
Exemple #7
0
 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)
Exemple #8
0
 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 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)
Exemple #10
0
 def array(self, shape):
     return ca.ones(shape)*self.c
Exemple #11
0
 def array(self, shape):
     return ca.ones(shape) * self.value
Exemple #12
0
 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)