Views
No views yet
1from transformers import VisionEncoderDecoderModel, ViTImageProcessor, GPT2Tokenizer
2import torch
3from PIL import Image
4model = VisionEncoderDecoderModel.from_pretrained("evlinzxxx/my_model_ViTB-16")
5feature_extractor = ViTImageProcessor.from_pretrained("evlinzxxx/my_model_ViTB-16")
6tokenizer = GPT2Tokenizer.from_pretrained("evlinzxxx/my_model_ViTB-16")
7device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
8model.to(device)
9def show_image_and_captions(url):
10 # get the image and display it
11 display(load_image(url))
12 # get the captions on various models
13 our_caption = get_caption(model, image_processor, tokenizer, url)
14 # print the captions
15 print(f"Our caption: {our_caption}")
16show_image_and_captions("/content/drive/MyDrive/try/test_400/gl_16.jpg") # ['navigate around the obstacle ahead adjusting your route to bypass the parked car.']