Open mollie9523 opened 1 year ago
I have the same problem when playing with the exemplary code
`from transformers import AutoFeatureExtractor, AutoModelForImageClassification from transformers_interpret import ImageClassificationExplainer from PIL import Image import requests
model_name = "google/vit-base-patch16-224" model = AutoModelForImageClassification.from_pretrained(model_name) feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
image = Image.open(requests.get(image_link, stream=True).raw)
image_classification_explainer = ImageClassificationExplainer(model=model, feature_extractor=feature_extractor)
image_attributions = image_classification_explainer( image )
print(image_attributions.shape)
image_classification_explainer.visualize( method="heatmap", side_by_side=True, outlier_threshold=0.03
)`
Do you know the solution to this error?
Hi, I encountered the same error, it seems that transformers library doesn't work with PIL. Changing line 69 in _transformers_interpret/explainers/vision/imageclassification.py to this:
self.feature_extractor.resize(np.array(self._image), size=(attributions_t.shape[0], attributions_t.shape[1]))
worked in my case.
Hi,
I am trying to run the notebook that you provided but when it comes to visualizing, there is an attribute error.
How can I solve this?