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

IndexError: tuple index out of range while running python image_demo.py #11

Closed
3togo opened this issue Jul 14, 2023 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@3togo
Copy link

3togo commented Jul 14, 2023

How to fix it?

(jvenv2) eli@sf-5820:/work/gitee/similarities/examples$ python image_demo.py
Similarity: ClipSimilarity, matching_model: CLIPModel
text_outputs= BaseModelOutputWithPoolingAndCrossAttentions(last_hidden_state=tensor([[[-1.1101, -1.0938, 0.4898, ..., -0.0164, -0.6199, -0.0707],
[-0.6594, -0.4225, 0.2657, ..., 0.2450, -0.9777, 0.0150],
[-0.4969, -0.4251, 0.1939, ..., 0.1082, -1.2218, 0.1043],
...,
[-0.5155, -0.2084, 0.2472, ..., -0.1606, -1.1309, -0.5505],
[-0.6670, -0.3467, 0.3174, ..., -0.0138, -1.1362, -0.3339],
[-1.1101, -1.0938, 0.4898, ..., -0.0164, -0.6199, -0.0707]],

    [[-0.0918,  0.0306, -0.3715,  ...,  0.7056, -0.6969, -0.6218],
     [-0.2009,  0.4845, -0.7210,  ...,  0.7905, -1.1266, -0.3237],
     [ 0.0015,  0.5168, -0.7785,  ...,  0.5152, -1.0434, -0.4373],
     ...,
     [-0.0331,  0.6689, -0.8446,  ...,  0.7927, -1.1110, -0.2845],
     [-0.0289,  0.6874, -0.8168,  ...,  0.7872, -1.0861, -0.2702],
     [-0.0220,  0.6936, -0.8694,  ...,  0.8004, -1.0756, -0.2936]]],
   device='cuda:0'), pooler_output=None, hidden_states=None, past_key_values=None, attentions=None, cross_attentions=None)

Traceback (most recent call last):
File "/work/gitee/similarities/examples/image_demo.py", line 67, in
clip_demo()
File "/work/gitee/similarities/examples/image_demo.py", line 51, in clip_demo
sim_scores = m.similarity(imgs, texts)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/work/gitee/similarities/similarities/imagesim.py", line 129, in similarity
text_emb2 = self._get_vector(b)
^^^^^^^^^^^^^^^^^^^
File "/work/gitee/similarities/similarities/imagesim.py", line 82, in _get_vector
return self.clip_model.encode(text_or_img, batch_size=batch_size, show_progress_bar=show_progress_bar)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/work/gitee/similarities/similarities/clip_model.py", line 173, in encode
out_features = self.forward(features)
^^^^^^^^^^^^^^^^^^^^^^
File "/work/gitee/similarities/similarities/clip_model.py", line 62, in forward
text_embeds = self.model.text_projection(text_outputs[1])
~~~~~~~~~~~~^^^
File "/home/eli/jvenv2/lib/python3.11/site-packages/transformers/utils/generic.py", line 320, in getitem
return self.to_tuple()[k]
~~~~~~~~~~~~~~~^^^
IndexError: tuple index out of range

@3togo 3togo added the bug Something isn't working label Jul 14, 2023
@shibing624
Copy link
Owner

我本地没复现问题,你看下输入数据有问题不,可以把完整的示例数据发下,我复现下问题。1)加上用的哪个模型;2)加上执行的脚本是哪个,和代码版本。

shibing624 added a commit that referenced this issue Sep 19, 2023
@shibing624
Copy link
Owner

fixed, chinese clip model get pooled output is not to english clip model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants