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

Fix BPE vocabulary loading when using ImageBind as library #84

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include imagebind/bpe/*
5 changes: 4 additions & 1 deletion imagebind/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import logging
import math
import pkg_resources

import torch
import torch.nn as nn
Expand All @@ -22,6 +23,7 @@

DEFAULT_AUDIO_FRAME_SHIFT_MS = 10 # in milliseconds

BPE_PACKAGE = "imagebind"
BPE_PATH = "bpe/bpe_simple_vocab_16e6.txt.gz"


Expand Down Expand Up @@ -105,7 +107,8 @@ def load_and_transform_vision_data(image_paths, device):
def load_and_transform_text(text, device):
if text is None:
return None
tokenizer = SimpleTokenizer(bpe_path=BPE_PATH)
bpe_path = pkg_resources.resource_filename(BPE_PACKAGE, BPE_PATH)
tokenizer = SimpleTokenizer(bpe_path=bpe_path)
tokens = [tokenizer(t).unsqueeze(0).to(device) for t in text]
tokens = torch.cat(tokens, dim=0)
return tokens
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
name='imagebind',
version='0.1.0',
packages=find_packages(),
include_package_data=True,
description='A brief description of the package',
long_description=open('README.md').read(),
long_description_content_type="text/markdown",
Expand All @@ -17,4 +18,4 @@
],
install_requires=required,
dependency_links=['https://download.pytorch.org/whl/cu113'],
)
)