Spaces:
Running
Running
Commit
·
1f223d8
1
Parent(s):
f49688f
app.py
CHANGED
@@ -47,7 +47,7 @@ def calculate_similarities(image, *texts):
|
|
47 |
if ttype=='hqclip':
|
48 |
tokenized_texts = tokenizer(text_inputs).to(device)
|
49 |
else:
|
50 |
-
tokenized_texts =
|
51 |
|
52 |
with torch.no_grad():
|
53 |
image_features = model.encode_image(img_tensor)
|
|
|
47 |
if ttype=='hqclip':
|
48 |
tokenized_texts = tokenizer(text_inputs).to(device)
|
49 |
else:
|
50 |
+
tokenized_texts = tokenizer(text_inputs,77).to(device)
|
51 |
|
52 |
with torch.no_grad():
|
53 |
image_features = model.encode_image(img_tensor)
|
debug.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import open_clip
|
3 |
+
import torch
|
4 |
+
import numpy as np
|
5 |
+
import pandas as pd
|
6 |
+
from PIL import Image
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
import io
|
9 |
+
|
10 |
+
# --- 1. Model Initialization (run only once) ---
|
11 |
+
print("Loading HQ-CLIP model...")
|
12 |
+
model_hq, _, preprocess_hq = open_clip.create_model_and_transforms('hf-hub:zhixiangwei/hqclip-openai-large-ft-vlm1b')
|
13 |
+
tokenizer_hq = open_clip.get_tokenizer('hf-hub:zhixiangwei/hqclip-openai-large-ft-vlm1b')
|
14 |
+
print("HQ-CLIP model loaded.")
|
15 |
+
|
16 |
+
print("Loading standard OpenAI CLIP model...")
|
17 |
+
model_openai, _, preprocess_openai = open_clip.create_model_and_transforms('ViT-L-14-quickgelu','openai')
|
18 |
+
tokenizer_openai = open_clip.get_tokenizer('ViT-L-14-quickgelu','openai')
|
19 |
+
print("OpenAI CLIP model loaded.")
|
20 |
+
|
21 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
22 |
+
device='cpu'
|
23 |
+
model_hq.to(device)
|
24 |
+
model_openai.to(device)
|
25 |
+
print(f"Models moved to {device}.")
|
26 |
+
|
27 |
+
tokenizer_openai(['cat','dog'],77)
|