Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will bertviz work for vision transformer? #118

Open
nahidalam opened this issue May 24, 2023 · 0 comments
Open

Will bertviz work for vision transformer? #118

nahidalam opened this issue May 24, 2023 · 0 comments

Comments

@nahidalam
Copy link

Since both the model_view and head_view methods require tokens, I wonder if this will work for vision transformers. Here is a sample code I tried that fails because ValueError: 'tokens' is required

from transformers import AutoTokenizer, AutoModel, utils
from bertviz import model_view
utils.logging.set_verbosity_error()  # Suppress standard warnings

from transformers import MobileViTFeatureExtractor, MobileViTForImageClassification
from PIL import Image
import requests

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)

feature_extractor = MobileViTFeatureExtractor.from_pretrained("apple/mobilevit-small")
model = MobileViTForImageClassification.from_pretrained("apple/mobilevit-small")

inputs = feature_extractor(images=image, return_tensors="pt")

outputs = model(**inputs)
attention = outputs[-1]  # Retrieve attention from model outputs
#tokens = tokenizer.convert_ids_to_tokens(inputs[0])  # Convert input ids to token strings
#model_view(attention, tokens)  # Display model view
model_view(attention)
@nahidalam nahidalam changed the title Will bertvis work for vision transformer? Will bertviz work for vision transformer? May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant