def test_register_metric_postprocess(self):
        import PIL.Image
        image = np.array(PIL.Image.open(self.image_path))
        resize_image = np.resize(image, (224, 224, 3))
        mean = [123.68, 116.78, 103.94]
        resize_image = resize_image - mean
        images = np.expand_dims(resize_image, axis=0)
        labels = [768]
        from lpot import Benchmark, Quantization
        from lpot.experimental.data.transforms.imagenet_transform import LabelShift
        from lpot.experimental.metric.metric import TensorflowTopK

        evaluator = Benchmark('fake_yaml.yaml')

        evaluator.postprocess('label_benchmark', LabelShift, label_shift=1)
        evaluator.metric('topk_benchmark', TensorflowTopK)
        dataloader = evaluator.dataloader(dataset=list(zip(images, labels)))
        result = evaluator(self.pb_path, b_dataloader=dataloader)
        acc, batch_size, result_list = result['accuracy']
        self.assertEqual(acc, 0.0)

        quantizer = Quantization('fake_yaml.yaml')
        quantizer.postprocess('label_quantize', LabelShift, label_shift=1)
        quantizer.metric('topk_quantize', TensorflowTopK)

        evaluator = Benchmark('fake_yaml.yaml')
        evaluator.metric('topk_second', TensorflowTopK)

        dataloader = evaluator.dataloader(dataset=list(zip(images, labels)))
        result = evaluator(self.pb_path, b_dataloader=dataloader)
        acc, batch_size, result_list = result['accuracy']
        self.assertEqual(acc, 0.0)
Example #2
0
    def test_register_metric_postprocess(self):
        import PIL.Image
        image = np.array(PIL.Image.open(self.image_path))
        resize_image = np.resize(image, (224, 224, 3))
        mean = [123.68, 116.78, 103.94]
        resize_image = resize_image - mean
        images = np.expand_dims(resize_image, axis=0)
        labels = [768]
        from lpot import Benchmark, Quantization
        from lpot.experimental.data.transforms.imagenet_transform import LabelShift
        from lpot.experimental.metric.metric import TensorflowTopK

        evaluator = Benchmark('fake_yaml.yaml')

        evaluator.postprocess('label_benchmark', LabelShift, label_shift=1)
        evaluator.metric('topk_benchmark', TensorflowTopK)
        # as we supported multi instance, the result will print out instead of return
        dataloader = evaluator.dataloader(dataset=list(zip(images, labels)))
        evaluator(self.pb_path, b_dataloader=dataloader)

        quantizer = Quantization('fake_yaml.yaml')
        quantizer.postprocess('label_quantize', LabelShift, label_shift=1)
        quantizer.metric('topk_quantize', TensorflowTopK)

        evaluator = Benchmark('fake_yaml.yaml')
        evaluator.metric('topk_second', TensorflowTopK)

        dataloader = evaluator.dataloader(dataset=list(zip(images, labels)))
        result = evaluator(self.pb_path, b_dataloader=dataloader)