Пример #1
0
 def get_output_shape(self, args):
     activations, weights = args
     act_shape = activations.get_shape()
     if len(act_shape) != 2:
         raise expr.ShapeError('Cannot matrix multiply non-matrix')
     weight_shape = weights.get_shape()
     if len(weight_shape) != 2:
         raise expr.ShapeError('Cannot matrix multiply non-matrix')
     if act_shape[1] != weight_shape[0]:
         raise expr.ShapeError('Incompatible matrices to multiply')
     return (act_shape[0], weight_shape[1])
Пример #2
0
 def get_output_shape(self, args):
     assert len(args) == 1
     values = args[0]
     input_shape = values.get_shape()
     if num_values(self.shape) != num_values(input_shape):
         raise expr.ShapeError(
             'Incompatible shapes for reshaping %s and %s' %
             (input_shape, shape))
     return self.shape
Пример #3
0
    def get_output_shape(self, args):
        assert len(args) == 1
        x = args[0]

        if self.shape is None:
            raise expr.ShapeError('Unknown shape')

        broadcasted_dims(x.get_shape(), self.shape)
        return self.shape
Пример #4
0
    def assert_output_shape(self, args, shape):
        assert len(args) == 1
        x = args[0]

        if self.shape is not None:
            if self.shape != shape:
                raise expr.ShapeError('mismatched shape %s and %s' % (self.shape, shape))

        broadcasted_dims(x.get_shape(), shape)
Пример #5
0
    def assert_output_shape(self, args, shape):
        activations, weights = args
        batch, output_size = shape

        try:
            act_shape = activations.get_shape()
        except expr.ShapeError:
            pass
        else:
            batch2, input_size = act_shape
            if batch != batch2:
                raise expr.ShapeError('Shape mismatch')
            weights.assert_shape((input_size, output_size))
            return None

        weight_shape = weights.get_shape()
        input_size, output_size2 = weight_shape
        if output_size2 != output_size:
            raise expr.ShapeError('Shape mismatch')
        activations.assert_shape((batch, input_size))