AI4LIFE-GROUP / OpenXAI

OpenXAI : Towards a Transparent Evaluation of Model Explanations
https://open-xai.github.io/
MIT License
232 stars 39 forks source link

AttributeError: module 'numpy' has no attribute 'float'. #24

Closed SachinLearns closed 1 year ago

SachinLearns commented 1 year ago

I am using numpy version 1.24.3 (>=1.19.5). But I am getting the below error. I did not see any mention of the python version, so I used python=3.10.

AttributeError Traceback (most recent call last) Cell In[4], line 16 13 from openxai.Explainer import Explainer 15 # Evaluation methods ---> 16 from openxai.evaluator import Evaluator 18 # Perturbation methods required for the computation of the relative stability metrics 19 from openxai.explainers.catalog.perturbation_methods import NormalPerturbation

File ~/OpenXAI/openxai/init.py:3 1 from .LoadModel import LoadModel 2 from .Explainer import Explainer ----> 3 from .evaluator import Evaluator

File ~/OpenXAI/openxai/evaluator.py:9 5 from scipy.special import comb 6 import pandas as pd ----> 9 class Evaluator(): 10 """ Metrics to evaluate an explanation method. 11 """ 13 def init(self, input_dict: dict, inputs, labels, model, explainer):

File ~/OpenXAI/openxai/evaluator.py:381, in Evaluator() 377 y_perturbed = self._arr(self.model(x_perturbed)) ### 379 return np.mean(np.abs(y - y_perturbed), axis=0)[0] ...

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 Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...

Then I tried removing the .float() from the entire code in the evaluator.py, but the error remained the same. I also tried float(<variable_to_be_converted)>, but the error did not change.
What else should I try?

SachinLearns commented 1 year ago

Got the error. Line 379 of evaluator.py, i.e.,

def _compute_Lp_norm_diff(self, vec1, vec2, normalize_to_relative_change: bool = True, eps: np.float = 0.001):

must be replaced with the following.

def _compute_Lp_norm_diff(self, vec1, vec2, normalize_to_relative_change: bool = True, eps: float = 0.001):