How to build single executable file with open clip used #774
Jayapraveen516
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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