Skip to content

Commit

Permalink
Fix pyre errors in GuidedGradCAM (#1396)
Browse files Browse the repository at this point in the history
Summary:

Initial work on fixing Pyre errors in Guided GradCAM

Reviewed By: craymichael

Differential Revision: D64677347
  • Loading branch information
Vivek Miglani authored and facebook-github-bot committed Oct 22, 2024
1 parent a1e15dc commit 6e4fa22
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions captum/attr/_core/guided_grad_cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def attribute(
self,
inputs: TensorOrTupleOfTensorsGeneric,
target: TargetType = None,
# pyre-fixme[2]: Parameter annotation cannot be `Any`.
additional_forward_args: Any = None,
additional_forward_args: object = None,
interpolate_mode: str = "nearest",
attribute_to_layer_input: bool = False,
) -> TensorOrTupleOfTensorsGeneric:
Expand Down Expand Up @@ -181,15 +180,11 @@ def attribute(
>>> # attribution size matches input size, Nx3x32x32
>>> attribution = guided_gc.attribute(input, 3)
"""
# pyre-fixme[6]: For 1st argument expected `Tensor` but got
# `TensorOrTupleOfTensorsGeneric`.
is_inputs_tuple = _is_tuple(inputs)
# pyre-fixme[9]: inputs has type `TensorOrTupleOfTensorsGeneric`; used as
# `Tuple[Tensor, ...]`.
inputs = _format_tensor_into_tuples(inputs)
inputs_tuple = _format_tensor_into_tuples(inputs)
grad_cam_attr = self.grad_cam.attribute.__wrapped__(
self.grad_cam, # self
inputs=inputs,
inputs=inputs_tuple,
target=target,
additional_forward_args=additional_forward_args,
attribute_to_layer_input=attribute_to_layer_input,
Expand All @@ -204,20 +199,18 @@ def attribute(

guided_backprop_attr = self.guided_backprop.attribute.__wrapped__(
self.guided_backprop, # self
inputs=inputs,
inputs=inputs_tuple,
target=target,
additional_forward_args=additional_forward_args,
)
output_attr: List[Tensor] = []
for i in range(len(inputs)):
for i in range(len(inputs_tuple)):
try:
output_attr.append(
guided_backprop_attr[i]
* LayerAttribution.interpolate(
grad_cam_attr,
# pyre-fixme[6]: For 2nd argument expected `Union[int,
# typing.Tuple[int, ...]]` but got `Size`.
inputs[i].shape[2:],
tuple(inputs_tuple[i].shape[2:]),
interpolate_mode=interpolate_mode,
)
)
Expand Down

0 comments on commit 6e4fa22

Please sign in to comment.