Esempio n. 1
0
    def test_dump_tensor(self):
        model, dataloader = self.cv_session
        augment = ONNXRTAugment(ONNXModel(model),
                                dataloader, [],
                                self.augment_path,
                                iterations=[0, 1],
                                white_nodes=["conv"])
        map_dumped_tensors = augment.dump_tensor()
        assert "conv" in map_dumped_tensors["activation"][0]
        assert "C" in map_dumped_tensors["activation"][0]["conv"]
        assert "conv" in map_dumped_tensors["activation"][1]
        assert "C" in map_dumped_tensors["activation"][1]["conv"]

        model, dataloader = self.cv_session
        augment = ONNXRTAugment(ONNXModel(model),
                                dataloader, [],
                                self.augment_path,
                                iterations=[0],
                                white_nodes=["conv", "relu"])
        map_dumped_tensors = augment.dump_tensor(weight=True)
        assert "conv" in map_dumped_tensors["activation"][0]
        assert "relu" in map_dumped_tensors["activation"][0]
        assert "conv" in map_dumped_tensors["weight"]

        model, dataloader = self.nlp_session
        augment = ONNXRTAugment(ONNXModel(model),
                                dataloader, [],
                                self.augment_path,
                                iterations=[0],
                                white_nodes=["gather"])
        map_dumped_tensors = augment.dump_tensor()
        assert "gather" in map_dumped_tensors["activation"][0]
Esempio n. 2
0
    def test_dump_tensor(self):
        model, dataloader = self.cv_session
        augment = ONNXRTAugment(model,
                                dataloader, ["Conv", "Relu"],
                                self.augment_path,
                                iterations=[0])
        dumped_tensors = augment.dump_tensor()
        assert len(dumped_tensors) == 1
        assert "A" in dumped_tensors[0] and "B" in dumped_tensors[0]
        assert "C" in dumped_tensors[0] and "D" in dumped_tensors[0]

        model, dataloader = self.nlp_session
        augment = ONNXRTAugment(model,
                                dataloader, ["Gather"],
                                self.augment_path,
                                iterations=[0])
        dumped_tensors = augment.dump_tensor()
        assert len(dumped_tensors) == 1
        assert "A" in dumped_tensors[0] and "C" in dumped_tensors[0]
Esempio n. 3
0
 def inspect_tensor(self,
                    model,
                    data_loader,
                    op_list=[],
                    iteration_list=[],
                    inspect_type='activation',
                    save_to_disk=False):
     '''The function is used by tune strategy class for dumping tensor info.
     '''
     from lpot.adaptor.ox_utils.onnxrt_mid import ONNXRTAugment
     from lpot.model.onnx_model import ONNXModel
     if not isinstance(model, ONNXModel):
         model = ONNXModel(model)
     augment = ONNXRTAugment(model, data_loader, [], \
               os.path.join(self.work_space, 'augment_for_inspect.onnx'), \
               iterations=iteration_list,
               white_nodes=op_list)
     tensors = augment.dump_tensor(activation=(inspect_type != 'weight'),
                                   weight=(inspect_type != 'activation'))
     if save_to_disk:
         np.savez(tensors,
                  os.path.join(self.work_space, 'dumped_tensors.npz'))
     return tensors