Skip to content

TypeError: 'module' object is not callable #133

@hessaAlawwad

Description

@hessaAlawwad

Hello,

I am trying to do the following:

from imagebind import data
from imagebind.models import imagebind_model
from imagebind.models.imagebind_model import ModalityType

def getEmbeddingVector(inputs):
     with torch.no_grad():
         embedding = imagebind_model(inputs)
     for key, value in embedding.items():
         vec = value.reshape(-1)
         return(vec)

def imageToEmbedding(path, device):
     inputs = { ModalityType.VISION: data.load_and_transform_vision_data(path, device)  }
     vec = getEmbeddingVector(inputs)
     return(vec)

def textToEmbedding(txt, device):
     text_list = [txt]
     inputs = {ModalityType.TEXT: data.load_and_transform_text(text_list, device)}
     vec = getEmbeddingVector(inputs)
     return(vec)

    
if __name__ == "__main__":
    device = "cuda:0" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
    imagebind = imagebind_model.imagebind_huge(pretrained=False)
    checkpoint_path = "~/.checkpoints/imagebind_huge.pth"
    imagebind.load_state_dict(torch.load(checkpoint_path, map_location=device, weights_only=True))
    imagebind.eval()
    imagebind.to(device)

    txt_list = ['This is a cat']
    textToEmbedding(txt_list, device)

but I am getting the following error:

Traceback (most recent call last):
  File "~/jtr_tqa.py", line 442, in <module>
    textToEmbedding(txt_list, device)
  File "~/jtr_tqa.py", line 69, in textToEmbedding
    vec = getEmbeddingVector(inputs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/jtr_tqa.py", line 54, in getEmbeddingVector
    embedding = imagebind_model(inputs)
                ^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'module' object is not callable

please help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions