You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
File c:\Users\SDS\anaconda3\envs\GradCAM_Pytorch\lib\site-packages\torch\nn\modules\module.py:1527, in Module._call_impl(self, *args, **kwargs)
1522 # If we don't have any hooks, we want to skip the rest of the logic in
1523 # this function, and just call forward.
1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1525 or _global_backward_pre_hooks or _global_backward_hooks
1526 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527 return forward_call(*args, **kwargs)
1529 try:
1530 result = None
File c:\Users\SDS\anaconda3\envs\GradCAM_Pytorch\lib\site-packages\medcam\medcam_inject.py:211, in forward(self, batch, label, mask, raw_input)
209 self.medcam_dict['current_attention_map'] = attention_map[list(attention_map.keys())[0]]
210 self.medcam_dict['current_layer'] = list(attention_map.keys())[0]
--> 211 scores = self._process_attention_maps(attention_map, mask, batch_size, channels, raw_input)
212 output = self._replace_or_return(output, attention_map, batch.shape[2:])
213 else: # If no attention maps could be extracted
File c:\Users\SDS\anaconda3\envs\GradCAM_Pytorch\lib\site-packages\medcam\medcam_inject.py:287, in _process_attention_maps(self, attention_map, mask, batch_size, channels, raw_input)
285 if raw_input is not None:
286 raw_input_single = raw_input[j]
--> 287 self._save_attention_map(attention_map_single, layer_output_dir, j, k, raw_input_single)
288 if self.medcam_dict['evaluate']:
289 if mask is None:
File c:\Users\SDS\anaconda3\envs\GradCAM_Pytorch\lib\site-packages\numpy_init_.py:324, in getattr(attr)
319 warnings.warn(
320 f"In the future np.{attr} will be defined as the "
321 "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
323 if attr in former_attrs:
--> 324 raise AttributeError(former_attrs[attr])
326 if attr == 'testing':
327 import numpy.testing as testing
AttributeError: module 'numpy' has no attribute 'float'. np.float was a deprecated alias for the builtin float. To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations`
The text was updated successfully, but these errors were encountered:
I no longer have access to this repo, so this would be something @MECLabTUDA would need to do. As an alternative, you could fork the repo and fix the issue yourself which is relatively simple as only np.float needs to be replaced with np.float32 in a couple of places.
This is my code:
`model = model.to("cuda")
def load_image(image_path = "Normal-3000.png"):
raw_image = cv2.imread(image_path)
raw_image = cv2.resize(raw_image, (224,) * 2)
image = transforms.Compose(
[
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
]
)(raw_image[..., ::-1].copy())
image = image.to("cuda").unsqueeze(0)
return image
model = medcam.inject(model, output_dir="practice code running", backend='ggcam', layer='layer4', label='best', save_maps=True)
model.eval()
model(load_image())
`
When I run this code I get this ERROR:
`AttributeError Traceback (most recent call last)
c:\Users\SDS\Desktop\SDS PC Files PHD\PhD Work\Lab work\practice code running\medcam_resnet50.ipynb Cell 6 line 2
1 model.eval()
----> 2 model(load_image())
File c:\Users\SDS\anaconda3\envs\GradCAM_Pytorch\lib\site-packages\torch\nn\modules\module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)
1516 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1517 else:
-> 1518 return self._call_impl(*args, **kwargs)
File c:\Users\SDS\anaconda3\envs\GradCAM_Pytorch\lib\site-packages\torch\nn\modules\module.py:1527, in Module._call_impl(self, *args, **kwargs)
1522 # If we don't have any hooks, we want to skip the rest of the logic in
1523 # this function, and just call forward.
1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1525 or _global_backward_pre_hooks or _global_backward_hooks
1526 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527 return forward_call(*args, **kwargs)
1529 try:
1530 result = None
File c:\Users\SDS\anaconda3\envs\GradCAM_Pytorch\lib\site-packages\medcam\medcam_inject.py:211, in forward(self, batch, label, mask, raw_input)
209 self.medcam_dict['current_attention_map'] = attention_map[list(attention_map.keys())[0]]
210 self.medcam_dict['current_layer'] = list(attention_map.keys())[0]
--> 211 scores = self._process_attention_maps(attention_map, mask, batch_size, channels, raw_input)
212 output = self._replace_or_return(output, attention_map, batch.shape[2:])
213 else: # If no attention maps could be extracted
File c:\Users\SDS\anaconda3\envs\GradCAM_Pytorch\lib\site-packages\medcam\medcam_inject.py:287, in _process_attention_maps(self, attention_map, mask, batch_size, channels, raw_input)
285 if raw_input is not None:
286 raw_input_single = raw_input[j]
--> 287 self._save_attention_map(attention_map_single, layer_output_dir, j, k, raw_input_single)
288 if self.medcam_dict['evaluate']:
289 if mask is None:
File c:\Users\SDS\anaconda3\envs\GradCAM_Pytorch\lib\site-packages\medcam\medcam_inject.py:300, in save_attention_map(self, attention_map, layer_output_dir, j, k, raw_input)
298 self.medcam_dict['pickle_maps'].append(attention_map)
299 if self.medcam_dict['save_maps']:
--> 300 medcam_utils.save_attention_map(filename=layer_output_dir + "/attention_map" + str(self.medcam_dict['counter']) + "" + str(j) + "" + str(k), attention_map=attention_map, heatmap=self.medcam_dict['heatmap'], raw_input=raw_input)
File c:\Users\SDS\anaconda3\envs\GradCAM_Pytorch\lib\site-packages\medcam\medcam_utils.py:29, in save_attention_map(filename, attention_map, heatmap, raw_input)
27 raw_input = raw_input.transpose(1, 2, 0)
28 dim = len(attention_map.shape)
---> 29 attention_map = normalize(attention_map.astype(np.float))
30 attention_map = generate_attention_map(attention_map, heatmap, dim, raw_input)
31 _save_file(filename, attention_map, dim)
File c:\Users\SDS\anaconda3\envs\GradCAM_Pytorch\lib\site-packages\numpy_init_.py:324, in getattr(attr)
319 warnings.warn(
320 f"In the future
np.{attr}
will be defined as the "321 "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
323 if attr in former_attrs:
--> 324 raise AttributeError(former_attrs[attr])
326 if attr == 'testing':
327 import numpy.testing as testing
AttributeError: module 'numpy' has no attribute 'float'.
np.float
was a deprecated alias for the builtinfloat
. To avoid this error in existing code, usefloat
by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, usenp.float64
here.The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations`
The text was updated successfully, but these errors were encountered: