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
if name == "main":
device = "cuda" if torch.cuda.is_available() else "cpu"
model, processor = clip.load("ViT-B/32", device=device)
tokenizer = clip.tokenize
images_list =[]
text_list = []
for i in range(500):
images_list.append("med_1.png")
text_list.append("This is a medical laboratory report This is a medical laboratory report This is a medical laboratory report This is a medical laboratory report This is a medical laboratory report This is a medical laboratory report This is a medical laboratory report This is a medical laboratory report This is a medical laboratory report This is a medical laboratory report This is a medical laboratory report")
start_time = time.time()
image_inputs=[]
for img_name in images_list:
img = Image.open(img_name)
image_input = processor(img).unsqueeze(0).to(device)
image_inputs.append(image_input)
temp = torch.stack(image_inputs)
temp = temp.squeeze().to(device)
print("temp", temp.shape)
print("temp", temp.device)
with torch.no_grad():
all_image_features = model.encode_image(temp)
text = tokenizer(text_list).to(device)
text_features = model.encode_text(text)
end_time = time.time()
print(f"耗时: {end_time - start_time}秒")
print(all_image_features.shape)
print(text_features.shape)
print((all_image_features+text_features).shape)
The text was updated successfully, but these errors were encountered:
import torch
import clip
from PIL import Image
from torchvision import transforms
class ClipEmbeding:
device = "cuda" if torch.cuda.is_available() else "cpu"
import time
if name == "main":
device = "cuda" if torch.cuda.is_available() else "cpu"
model, processor = clip.load("ViT-B/32", device=device)
tokenizer = clip.tokenize
The text was updated successfully, but these errors were encountered: