Skip to content

Multi-thread usage of open_clip #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
devparty1996 opened this issue Mar 9, 2024 · 0 comments
Closed

Multi-thread usage of open_clip #430

devparty1996 opened this issue Mar 9, 2024 · 0 comments

Comments

@devparty1996
Copy link

hi I am using open_clip with a pretrained model in my project to compare images similarity but i only can run it in one thread i did not find any solution to use it as a multithread task is there any solution for it ?

i think the preprocess variable that create with the below code produce the problem :

preprocess_val = image_transform_v2(
        pp_cfg,
        is_train=False,
    )

the whole code :

device = "cuda" if torch.cuda.is_available() else "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 = numpy.array(image1)
    data_img = numpy.array(image2)
    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

score = generateScore(pil_image1, pil_image2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant