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
image1 = path to image 1
image2 = path to image 2
print(Path(image1).stem)
print(Path(image2).stem)
print(f"similarity Score: ", round(generateScore(image1, image2), 2))
The above is the code I tried, As a beginner in python I built standalone exe using pyinstaller. But for this script I can't able to built standalone exe file. Guidance for building exe file can be helpfull
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
import torch
import open_clip
import cv2, os
from sentence_transformers import util
from PIL import Image
from pathlib import Path
device = "cpu"
model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-16-plus-240', pretrained="laion400m_e32")
model.to(device)
def imageEncoder(img):
img1 = Image.fromarray(img).convert('RGB')
img1 = preprocess(img1).unsqueeze(0).to(device)
img1 = model.encode_image(img1)
return img1
def generateScore(image1, image2):
test_img = cv2.imread(image1, cv2.IMREAD_UNCHANGED)
data_img = cv2.imread(image2, cv2.IMREAD_UNCHANGED)
img1 = imageEncoder(test_img)
img2 = imageEncoder(data_img)
cos_scores = util.pytorch_cos_sim(img1, img2)
score = round(float(cos_scores[0][0])*100, 2)
return score
image1 = path to image 1
image2 = path to image 2
print(Path(image1).stem)
print(Path(image2).stem)
print(f"similarity Score: ", round(generateScore(image1, image2), 2))
The above is the code I tried, As a beginner in python I built standalone exe using pyinstaller. But for this script I can't able to built standalone exe file. Guidance for building exe file can be helpfull
Beta Was this translation helpful? Give feedback.
All reactions