def _deconv_matching_assert(self, model, output_layer, test_input):
     out = model(test_input)
     attrib = Deconvolution(model)
     neuron_attrib = NeuronDeconvolution(model, output_layer)
     for i in range(out.shape[1]):
         deconv_vals = attrib.attribute(test_input, target=i)
         neuron_deconv_vals = neuron_attrib.attribute(test_input, (i, ))
         assertTensorAlmostEqual(self,
                                 deconv_vals,
                                 neuron_deconv_vals,
                                 delta=0.01)
 def _deconv_test_assert(self,
                         model,
                         test_input,
                         expected,
                         additional_input=None):
     deconv = Deconvolution(model)
     attributions = deconv.attribute(
         test_input, target=0, additional_forward_args=additional_input)
     for i in range(len(test_input)):
         assertTensorAlmostEqual(self,
                                 attributions[i],
                                 expected[i],
                                 delta=0.01)
Beispiel #3
0
 def _deconv_test_assert(
     self,
     model: Module,
     test_input: TensorOrTupleOfTensorsGeneric,
     expected: Tuple[List[List[float]], ...],
     additional_input: Any = None,
 ) -> None:
     deconv = Deconvolution(model)
     attributions = deconv.attribute(
         test_input, target=0, additional_forward_args=additional_input
     )
     for i in range(len(test_input)):
         assertTensorAlmostEqual(self, attributions[i], expected[i], delta=0.01)
Beispiel #4
0
 def _deconv_matching_assert(
     self,
     model: Module,
     output_layer: Module,
     test_input: TensorOrTupleOfTensorsGeneric,
 ) -> None:
     out = model(test_input)
     attrib = Deconvolution(model)
     self.assertFalse(attrib.multiplies_by_inputs)
     neuron_attrib = NeuronDeconvolution(model, output_layer)
     for i in range(out.shape[1]):
         deconv_vals = attrib.attribute(test_input, target=i)
         neuron_deconv_vals = neuron_attrib.attribute(test_input, (i,))
         assertTensorAlmostEqual(self, deconv_vals, neuron_deconv_vals, delta=0.01)