updates UI
This commit is contained in:
@@ -10,6 +10,7 @@ _model = None
|
||||
_preprocess = None
|
||||
_device = None
|
||||
_lock = threading.Lock()
|
||||
_gpu_lock = threading.Lock()
|
||||
|
||||
def get_model():
|
||||
global _model, _preprocess, _device
|
||||
@@ -31,12 +32,13 @@ def get_model():
|
||||
def generate_embedding(image_path):
|
||||
model, preprocess, device = get_model()
|
||||
try:
|
||||
with Image.open(image_path) as img:
|
||||
image = preprocess(img.convert("RGB")).unsqueeze(0).to(device)
|
||||
with torch.no_grad():
|
||||
image_features = model.encode_image(image)
|
||||
image_features /= image_features.norm(dim=-1, keepdim=True)
|
||||
return image_features.cpu().numpy()[0].tolist()
|
||||
with _gpu_lock:
|
||||
with Image.open(image_path) as img:
|
||||
image = preprocess(img.convert("RGB")).unsqueeze(0).to(device)
|
||||
with torch.no_grad():
|
||||
image_features = model.encode_image(image)
|
||||
image_features /= image_features.norm(dim=-1, keepdim=True)
|
||||
return image_features.cpu().numpy()[0].tolist()
|
||||
except Exception as e:
|
||||
print(f"Error generating embedding for {image_path}: {e}")
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user