Skip to content

Commit

Permalink
Merge pull request #119 from facebookresearch/bpefix
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisjanWust authored Jul 10, 2024
2 parents aedc5ab + 89c103c commit 3fcf5c9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
File renamed without changes.
15 changes: 9 additions & 6 deletions 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,7 +23,11 @@

DEFAULT_AUDIO_FRAME_SHIFT_MS = 10 # in milliseconds

BPE_PATH = "bpe/bpe_simple_vocab_16e6.txt.gz"

def return_bpe_path():
return pkg_resources.resource_filename(
"imagebind", "bpe/bpe_simple_vocab_16e6.txt.gz"
)


def waveform2melspec(waveform, sample_rate, num_mel_bins, target_length):
Expand Down Expand Up @@ -83,9 +88,7 @@ def load_and_transform_vision_data(image_paths, device):

data_transform = transforms.Compose(
[
transforms.Resize(
224, interpolation=transforms.InterpolationMode.BICUBIC
),
transforms.Resize(224, interpolation=transforms.InterpolationMode.BICUBIC),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(
Expand All @@ -94,7 +97,7 @@ def load_and_transform_vision_data(image_paths, device):
),
]
)

for image_path in image_paths:
with open(image_path, "rb") as fopen:
image = Image.open(fopen).convert("RGB")
Expand All @@ -107,7 +110,7 @@ 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)
tokenizer = SimpleTokenizer(bpe_path=return_bpe_path())
tokens = [tokenizer(t).unsqueeze(0).to(device) for t in text]
tokens = torch.cat(tokens, dim=0)
return tokens
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
name='imagebind',
version='0.1.0',
packages=find_packages(),
package_data={
'imagebind': ['bpe/bpe_simple_vocab_16e6.txt.gz'],
},
description='A brief description of the package',
long_description=open('README.md', encoding='utf-8').read(),
long_description_content_type="text/markdown",
Expand All @@ -17,4 +20,4 @@
],
install_requires=required,
dependency_links=['https://download.pytorch.org/whl/cu113'],
)
)

0 comments on commit 3fcf5c9

Please sign in to comment.