Skip to content
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

CLIP result seems wrong #2387

Closed
awsaf49 opened this issue Mar 13, 2024 · 5 comments
Closed

CLIP result seems wrong #2387

awsaf49 opened this issue Mar 13, 2024 · 5 comments
Assignees
Labels

Comments

@awsaf49
Copy link

awsaf49 commented Mar 13, 2024

Current Behavior:

I tried out recently added pre-trained CLIP for zero-shot classification and the result seems wrong. You can verify that in this kaggle notebook. Instead of classifying the image as cat it is giving all candid labels equal probability of 0.33. I tried with multiple samples and the result is same for all, {'man': 0.33333847, 'dog': 0.33333862, 'cat': 0.33332297}.

Steps To Reproduce:

notebook: https://www.kaggle.com/code/awsaf49/kerascv-clip

Version:

  • HEAD

Reference:

@awsaf49
Copy link
Author

awsaf49 commented Mar 13, 2024

cc: @divyashreepathihalli

@awsaf49
Copy link
Author

awsaf49 commented Mar 13, 2024

I tried this code for zero-shot classification

processed_image = processor.process_images(["cat1.jpg"])
candid_labels = ["man", "dog", "cat"]
processed_text, attention_mask = processor.process_texts(
  [f"Picture of a {x}." for x in candid_labels]
  )
image_logits, text_logits = model(
        {
            "image": processed_image,
            "text": processed_text,
            "attention_mask": attention_mask,
        }
    )
preds = keras.ops.softmax(image_logits).numpy().squeeze()
result = dict(zip(candid_labels, preds))
print(result)

@awsaf49
Copy link
Author

awsaf49 commented Mar 13, 2024

In the same kaggle notebook, I've compared results with open-ai CLIP . And open-AI's CLIP works nicely in contrast to KerasCV's CLIP.

@divyashreepathihalli
Copy link
Collaborator

That doesn't seem right. I'll take a look.

@divyashreepathihalli
Copy link
Collaborator

Looks like the model is working fine with the weights file but from_preset() doesn't seem to be working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants