mirror of
https://github.com/openai/CLIP.git
synced 2026-11-05 01:37:26 +00:00
[GH-ISSUE #114] Embedding is not deterministic #103
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openai/CLIP#103
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ArrowLuo on GitHub (Jun 9, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/114
Thanks for this amazing model.
I encountered a reproduce issue when extracting features. The results are different randomly with a small probability. Is there something wrong with my running?
A toy example is shown as the last block in colab.
The results are like,
Thanks.
@vinson2233 commented on GitHub (Jun 9, 2021):
Have you read about this ? https://pytorch.org/docs/stable/notes/randomness.html
Btw I seen your code and a bit confused. So you breaking a single image to multiple different patches, and then compare the embedding between the different patches to the first patches ?
in this part
np.array_equal(test_tensor, itm):,itmis every part ofsequence_output_cpuwhiletest_tensoris only the first part ofsequence_output_cpu@ArrowLuo commented on GitHub (Jun 9, 2021):
Thanks for your quick reply.
Yes, I have read the link you provide.
The code runs 10 turns, each turn has the same images with different batch sizes.
test_tensoris the feature from the first image of the first turn, which is used to compare with the images of the rest turns.Because the images in each turn are the same, we naturally hope the CLIP returns the same features. But the results are not deterministic, which occurs without a pattern.
Are there some methods to make the generated feature deterministic from pretrained CLIP?
@vinson2233 commented on GitHub (Jun 9, 2021):
Unless I'm wrongly interpreted it, I think the code you use for testing is at fault here.
let's say for this turn batch_size is 2,
then the image is split into 2 (I don't know how maybe the first part is the top half of the image and the second part is the bottom half).
So the image itself is not same in each turn. I think what you want is to set the batch_size to 1 in this case, since the batch_size is relevant on multiple images, not single image
@ArrowLuo commented on GitHub (Jun 9, 2021):
I print the image size at each turn, the size reflects the images are not split operation. The colab has been updated.
Also, when replace
sequence_output_cpu = image_features.detach().cpu().numpy()withsequence_output_cpu = image .detach().cpu().numpy(), the print shows the images are the same. So, the difference is the output of themodel.encode_image(image).@vinson2233 commented on GitHub (Jun 10, 2021):
I see, I mistook the expand method with the reshape method/
Hmmm, that's weird, the issue doesn't happen in my environment. I'm using this code :
This print nothing
@ArrowLuo commented on GitHub (Jun 10, 2021):
The outputs are the same in the same batch, but not at different turns even for the same image.
So, the testing should save the first tensor from the image, and use it to compare with the rest of the outputs.
The difference occurs randomly, so rerun several times if nothing prints.
@jongwook commented on GitHub (Jun 30, 2021):
Related: #13. It can be frustrating, but there are unfortunately many factors in GPU we can't fully control. We empirically find that those differences do not make a significant impact on downstream tasks.