salesforce / LAVIS

LAVIS - A One-stop Library for Language-Vision Intelligence
BSD 3-Clause "New" or "Revised" License
9.91k stars 972 forks source link

TypeError occurs when running instructBLIP demo #429

Closed greeksharifa closed 1 year ago

greeksharifa commented 1 year ago

I'm running this code snippet in instructBLIP readme:

import torch
from PIL import Image
# setup device to use
device = torch.device("cuda") if torch.cuda.is_available() else "cpu"
# load sample image
raw_image = Image.open("docs/_static/Confusing-Pictures.jpg").convert("RGB")

from lavis.models import load_model_and_preprocess
# loads InstructBLIP model
model, vis_processors, _ = load_model_and_preprocess(name="blip2_vicuna_instruct", model_type="vicuna7b", is_eval=True, device=device)
# prepare the image
image = vis_processors["eval"](raw_image).unsqueeze(0).to(device)
model.generate({"image": image, "prompt": "What is unusual about this image?"})

But I got the TypeError:

/opt/conda/lib/python3.8/site-packages/pandas/compat/_optional.py:161: UserWarning: Pandas requires version '2.7.1' or newer of 'numexpr' (version '2.7.0' currently installed).
  warnings.warn(msg, UserWarning)
/opt/conda/lib/python3.8/site-packages/apex/pyprof/__init__.py:5: FutureWarning: pyprof will be removed by the end of June, 2022
  warnings.warn("pyprof will be removed by the end of June, 2022", FutureWarning)
WARNING:root:Pytorch pre-release version 1.12.0a0+8a1a93a - assuming intent to test it
  warnings.warn(f'''
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    from lavis.models import load_model_and_preprocess
  File "/home/work/T5/ywjang/LBA_LAVIS/lavis/__init__.py", line 16, in <module>
    from lavis.models import *
  File "/home/work/T5/ywjang/LBA_LAVIS/lavis/models/__init__.py", line 49, in <module>
    from lavis.models.img2prompt_models.img2prompt_vqa import Img2PromptVQA
  File "/home/work/T5/ywjang/LBA_LAVIS/lavis/models/img2prompt_models/img2prompt_vqa.py", line 15, in <module>
    import spacy
  File "/opt/conda/lib/python3.8/site-packages/spacy/__init__.py", line 14, in <module>
    from . import pipeline  # noqa: F401
  File "/opt/conda/lib/python3.8/site-packages/spacy/pipeline/__init__.py", line 1, in <module>
    from .attributeruler import AttributeRuler
  File "/opt/conda/lib/python3.8/site-packages/spacy/pipeline/attributeruler.py", line 6, in <module>
    from .pipe import Pipe
  File "spacy/pipeline/pipe.pyx", line 8, in init spacy.pipeline.pipe
  File "/opt/conda/lib/python3.8/site-packages/spacy/training/__init__.py", line 11, in <module>
    from .callbacks import create_copy_from_base_model  # noqa: F401
  File "/opt/conda/lib/python3.8/site-packages/spacy/training/callbacks.py", line 3, in <module>
    from ..language import Language
  File "/opt/conda/lib/python3.8/site-packages/spacy/language.py", line 25, in <module>
    from .training.initialize import init_vocab, init_tok2vec
  File "/opt/conda/lib/python3.8/site-packages/spacy/training/initialize.py", line 14, in <module>
    from .pretrain import get_tok2vec_ref
  File "/opt/conda/lib/python3.8/site-packages/spacy/training/pretrain.py", line 16, in <module>
    from ..schemas import ConfigSchemaPretrain
  File "/opt/conda/lib/python3.8/site-packages/spacy/schemas.py", line 216, in <module>
    class TokenPattern(BaseModel):
  File "pydantic/main.py", line 299, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 411, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 342, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 451, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 545, in pydantic.fields.ModelField._type_analysis
  File "pydantic/fields.py", line 550, in pydantic.fields.ModelField._type_analysis
  File "/opt/conda/lib/python3.8/typing.py", line 774, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class

How can I resolve this issue?

Already, I tried to reinstall typing, typing-extensions, but I cannot solve this. or, could you tell me the exact version of typing, typing-extensions(and typing-inspect) ?

Thanks!

yuanze1024 commented 1 year ago

Hi, I've met the same problem. May I ask you how did you solve it?

yuanze1024 commented 1 year ago

Hi, I've met the same problem. May I ask you how did you solve it?

OK, I just pip install -U pydantic spacy which installed pydantic==1.10.12 & spacy==3.6.0, and problem solved. Record it here in case someone meets the same problem.

greeksharifa commented 1 year ago

I re-install the exact version of typing.