pyspark/bigdl/nn/layer.py
def quantize(self):
        '''
        Clone self and quantize it, at last return a new quantized model.
        :return: A new quantized model.

        >>> fc = Linear(4, 2)
        creating: createLinear
        >>> fc.set_weights([np.ones((2, 4)), np.ones((2,))])
        >>> input = np.ones((2, 4))
        >>> output = fc.forward(input)
        >>> expected_output = np.array([[5., 5.], [5., 5.]])
        >>> np.testing.assert_allclose(output, expected_output)
        >>> quantized_fc = fc.quantize()
        >>> quantized_output = quantized_fc.forward(input)
        >>> expected_quantized_output = np.array([[5., 5.], [5., 5.]])
        >>> np.testing.assert_allclose(quantized_output, expected_quantized_output)

        >>> assert("quantized.Linear" in quantized_fc.__str__())
        >>> conv = SpatialConvolution(1, 2, 3, 3)
        creating: createSpatialConvolution
        >>> conv.set_weights([np.ones((2, 1, 3, 3)), np.zeros((2,))])
        >>> input = np.ones((2, 1, 4, 4))
        >>> output = conv.forward(input)
        >>> expected_output = np.array([[[[9., 9.], [9., 9.]], [[9., 9.], [9., 9.]]], [[[9., 9.], [9., 9.]], [[9., 9.], [9., 9.]]]])
        >>> np.testing.assert_allclose(output, expected_output)
        >>> quantized_conv = conv.quantize()
        >>> quantized_output = quantized_conv.forward(input)
        >>> expected_quantized_output = np.array([[[[9., 9.], [9., 9.]], [[9., 9.], [9., 9.]]], [[[9., 9.], [9., 9.]], [[9., 9.], [9., 9.]]]])
        >>> np.testing.assert_allclose(quantized_output, expected_quantized_output)
        >>> assert("quantized.SpatialConvolution" in quantized_conv.__str__())
        >>> seq = Sequential()
        creating: createSequential
        >>> seq = seq.add(conv)
        >>> seq = seq.add(Reshape([8, 4], False))
        creating: createReshape
        >>> seq = seq.add(fc)
        >>> input = np.ones([1, 1, 6, 6])
        >>> output = seq.forward(input)
        >>> expected_output = np.array([[37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.]])
        >>> np.testing.assert_allclose(output, expected_output)
        >>> quantized_seq = seq.quantize()
        >>> quantized_output = quantized_seq.forward(input)
        >>> expected_quantized_output = np.array([[37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.]])
        >>> np.testing.assert_allclose(quantized_output, expected_quantized_output)
        >>> assert("quantized.Linear" in quantized_seq.__str__())
        >>> assert("quantized.SpatialConvolution" in quantized_seq.__str__())
        '''
        quantized_model = callBigDlFunc(self.bigdl_type, "quantize", self.value)
        return Layer.of(quantized_model)
def quantize(self):
        '''
        Clone self and quantize it, at last return a new quantized model.
        :return: A new quantized model.

        >>> fc = Linear(4, 2)
        creating: createLinear
        >>> fc.set_weights([np.ones((2, 4)), np.ones((2,))])
        >>> input = np.ones((2, 4))
        >>> output = fc.forward(input)
        >>> expected_output = np.array([[5., 5.], [5., 5.]])
        >>> np.testing.assert_allclose(output, expected_output)
        >>> quantized_fc = fc.quantize()
        >>> quantized_output = quantized_fc.forward(input)
        >>> expected_quantized_output = np.array([[5., 5.], [5., 5.]])
        >>> np.testing.assert_allclose(quantized_output, expected_quantized_output)

        >>> assert("quantized.Linear" in quantized_fc.__str__())
        >>> conv = SpatialConvolution(1, 2, 3, 3)
        creating: createSpatialConvolution
        >>> conv.set_weights([np.ones((2, 1, 3, 3)), np.zeros((2,))])
        >>> input = np.ones((2, 1, 4, 4))
        >>> output = conv.forward(input)
        >>> expected_output = np.array([[[[9., 9.], [9., 9.]], [[9., 9.], [9., 9.]]], [[[9., 9.], [9., 9.]], [[9., 9.], [9., 9.]]]])
        >>> np.testing.assert_allclose(output, expected_output)
        >>> quantized_conv = conv.quantize()
        >>> quantized_output = quantized_conv.forward(input)
        >>> expected_quantized_output = np.array([[[[9., 9.], [9., 9.]], [[9., 9.], [9., 9.]]], [[[9., 9.], [9., 9.]], [[9., 9.], [9., 9.]]]])
        >>> np.testing.assert_allclose(quantized_output, expected_quantized_output)
        >>> assert("quantized.SpatialConvolution" in quantized_conv.__str__())
        >>> seq = Sequential()
        creating: createSequential
        >>> seq = seq.add(conv)
        >>> seq = seq.add(Reshape([8, 4], False))
        creating: createReshape
        >>> seq = seq.add(fc)
        >>> input = np.ones([1, 1, 6, 6])
        >>> output = seq.forward(input)
        >>> expected_output = np.array([[37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.]])
        >>> np.testing.assert_allclose(output, expected_output)
        >>> quantized_seq = seq.quantize()
        >>> quantized_output = quantized_seq.forward(input)
        >>> expected_quantized_output = np.array([[37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.]])
        >>> np.testing.assert_allclose(quantized_output, expected_quantized_output)
        >>> assert("quantized.Linear" in quantized_seq.__str__())
        >>> assert("quantized.SpatialConvolution" in quantized_seq.__str__())
        '''
        quantized_model = callBigDlFunc(self.bigdl_type, "quantize", self.value)
        return Layer.of(quantized_model)
Clone self and quantize it, at last return a new quantized model.
        :return: A new quantized model.

        >>> fc = Linear(4, 2)
        creating: createLinear
        >>> fc.set_weights([np.ones((2, 4)), np.ones((2,))])
        >>> input = np.ones((2, 4))
        >>> output = fc.forward(input)
        >>> expected_output = np.array([[5., 5.], [5., 5.]])
        >>> np.testing.assert_allclose(output, expected_output)
        >>> quantized_fc = fc.quantize()
        >>> quantized_output = quantized_fc.forward(input)
        >>> expected_quantized_output = np.array([[5., 5.], [5., 5.]])
        >>> np.testing.assert_allclose(quantized_output, expected_quantized_output)

        >>> assert("quantized.Linear" in quantized_fc.__str__())
        >>> conv = SpatialConvolution(1, 2, 3, 3)
        creating: createSpatialConvolution
        >>> conv.set_weights([np.ones((2, 1, 3, 3)), np.zeros((2,))])
        >>> input = np.ones((2, 1, 4, 4))
        >>> output = conv.forward(input)
        >>> expected_output = np.array([[[[9., 9.], [9., 9.]], [[9., 9.], [9., 9.]]], [[[9., 9.], [9., 9.]], [[9., 9.], [9., 9.]]]])
        >>> np.testing.assert_allclose(output, expected_output)
        >>> quantized_conv = conv.quantize()
        >>> quantized_output = quantized_conv.forward(input)
        >>> expected_quantized_output = np.array([[[[9., 9.], [9., 9.]], [[9., 9.], [9., 9.]]], [[[9., 9.], [9., 9.]], [[9., 9.], [9., 9.]]]])
        >>> np.testing.assert_allclose(quantized_output, expected_quantized_output)
        >>> assert("quantized.SpatialConvolution" in quantized_conv.__str__())
        >>> seq = Sequential()
        creating: createSequential
        >>> seq = seq.add(conv)
        >>> seq = seq.add(Reshape([8, 4], False))
        creating: createReshape
        >>> seq = seq.add(fc)
        >>> input = np.ones([1, 1, 6, 6])
        >>> output = seq.forward(input)
        >>> expected_output = np.array([[37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.]])
        >>> np.testing.assert_allclose(output, expected_output)
        >>> quantized_seq = seq.quantize()
        >>> quantized_output = quantized_seq.forward(input)
        >>> expected_quantized_output = np.array([[37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.], [37., 37.]])
        >>> np.testing.assert_allclose(quantized_output, expected_quantized_output)
        >>> assert("quantized.Linear" in quantized_seq.__str__())
        >>> assert("quantized.SpatialConvolution" in quantized_seq.__str__())