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

Added cache_dir argument for downloading model to a specific directory #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions models/imagebind_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def forward(self, inputs):
return outputs


def imagebind_huge(pretrained=False):
def imagebind_huge(pretrained=False, cache_dir=None):
model = ImageBindModel(
vision_embed_dim=1280,
vision_num_blocks=32,
Expand All @@ -501,17 +501,20 @@ def imagebind_huge(pretrained=False):
)

if pretrained:
if not os.path.exists(".checkpoints/imagebind_huge.pth"):
cache_dir = cache_dir if cache_dir is not None else ".checkpoints"
ckpt_path = "{}/imagebind_huge.pth".format(cache_dir)

if not os.path.exists(ckpt_path):
print(
"Downloading imagebind weights to .checkpoints/imagebind_huge.pth ..."
"Downloading imagebind weights to {} ...".format(ckpt_path)
)
os.makedirs(".checkpoints", exist_ok=True)
os.makedirs(cache_dir, exist_ok=True)
torch.hub.download_url_to_file(
"https://dl.fbaipublicfiles.com/imagebind/imagebind_huge.pth",
".checkpoints/imagebind_huge.pth",
ckpt_path,
progress=True,
)

model.load_state_dict(torch.load(".checkpoints/imagebind_huge.pth"))
model.load_state_dict(torch.load(ckpt_path))

return model