Exemplo n.º 1
0
 def test_raise(self):
     with pytest.raises(ValueError) as excinfo:
         quant_pooling_object = quant_pooling.QuantAvgPool2d(
             kernel_size=3,
             stride=1,
             quant_desc_input=tensor_quant.QuantDescriptor(
                 fake_quant=False))
     assert "Only fake quantization is supported" in str(excinfo.value)
Exemplo n.º 2
0
    def test_input_fake_quant_disable(self):
        quant_pooling_object = quant_pooling.QuantAvgPool2d(kernel_size=3,
                                                            stride=1)

        test_input = torch.randn(1, 5, 5, 5, dtype=torch.double)

        quant_pooling_object.input_quantizer.disable()

        out1 = F.avg_pool2d(test_input, 3, 1, 0, False, True, None)
        out2 = quant_pooling_object(test_input)
        np.testing.assert_array_equal(out1.detach().cpu().numpy(),
                                      out2.detach().cpu().numpy())
Exemplo n.º 3
0
    def test_input_variable_bits(self):
        # Repeat checking the output for variable number of bits to QuantDescriptor
        for bits in [2, 4, 6]:
            quant_desc_input = tensor_quant.QuantDescriptor(num_bits=bits)

            quant_pooling.QuantAvgPool2d.set_default_quant_desc_input(
                quant_desc_input)
            quant_pooling_object = quant_pooling.QuantAvgPool2d(kernel_size=3,
                                                                stride=1)

            test_input = torch.randn(1, 5, 5, 5, dtype=torch.double)

            quant_input = tensor_quant.fake_tensor_quant(
                test_input, torch.max(torch.abs(test_input)), bits)

            out1 = F.avg_pool2d(quant_input, 3, 1, 0, False, True, None)
            out2 = quant_pooling_object(test_input)
            np.testing.assert_array_equal(out1.detach().cpu().numpy(),
                                          out2.detach().cpu().numpy())