[GH-ISSUE #508] I have slight differences between obtaining features on the server and on the local machine. #428

Open
opened 2026-10-31 21:14:53 +00:00 by bsakaguchi · 2 comments
Owner

Originally created by @bbhxwl on GitHub (Jul 3, 2025).
Original GitHub issue: https://github.com/openai/CLIP/issues/508

I have slight differences between obtaining features on the server and on the local machine.
0.0037348971236497164
0.0037349374033510685

model, preprocess = clip.load("ViT-B/32")

def extract_features(image_path):
    # 如果是URL链接,下载图片
    if isinstance(image_path, Image.Image):
        img = image_path.convert('RGB')
    elif image_path.startswith('http://') or image_path.startswith('https://'):
        response = requests.get(image_path)
        img = Image.open(BytesIO(response.content)).convert('RGB')
    elif os.path.exists(image_path):  
        img = Image.open(image_path).convert('RGB')

    else:
        raise ValueError("Invalid image path or URL.")
    img_tensor = preprocess(img).unsqueeze(0)
    with torch.no_grad():
        emb = model.encode_image(img_tensor)
        emb = emb / emb.norm(dim=-1, keepdim=True)
        features = emb[0].tolist()

    return features
Originally created by @bbhxwl on GitHub (Jul 3, 2025). Original GitHub issue: https://github.com/openai/CLIP/issues/508 I have slight differences between obtaining features on the server and on the local machine. 0.0037348971236497164 0.0037349374033510685 ``` model, preprocess = clip.load("ViT-B/32") def extract_features(image_path): # 如果是URL链接,下载图片 if isinstance(image_path, Image.Image): img = image_path.convert('RGB') elif image_path.startswith('http://') or image_path.startswith('https://'): response = requests.get(image_path) img = Image.open(BytesIO(response.content)).convert('RGB') elif os.path.exists(image_path): img = Image.open(image_path).convert('RGB') else: raise ValueError("Invalid image path or URL.") img_tensor = preprocess(img).unsqueeze(0) with torch.no_grad(): emb = model.encode_image(img_tensor) emb = emb / emb.norm(dim=-1, keepdim=True) features = emb[0].tolist() return features ```
Author
Owner

@bbhxwl commented on GitHub (Jul 3, 2025):

Is there a different version of ViT-B/32 that is automatically downloaded? Is my server different from the local version?

<!-- gh-comment-id:3031083089 --> @bbhxwl commented on GitHub (Jul 3, 2025): Is there a different version of ViT-B/32 that is automatically downloaded? Is my server different from the local version?
Author
Owner

@AloscariS commented on GitHub (Sep 5, 2025):

It can be perfectly normal since the code will run on different hardware (remote and local) or even different versions of PyTorch/cuDNN. This will result in slightly different treatments of the floating-point operations.

These small deviations are harmless and don’t indicate a bug.

<!-- gh-comment-id:3258059568 --> @AloscariS commented on GitHub (Sep 5, 2025): It can be perfectly normal since the code will run on different hardware (remote and local) or even different versions of PyTorch/cuDNN. This will result in slightly different treatments of the floating-point operations. These small deviations are harmless and don’t indicate a bug.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openai/CLIP#428
No description provided.