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

[clip] Prevent warning with padding when tokenizing for CLIP #2599

Merged
merged 1 commit into from
Apr 17, 2024
Merged
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
18 changes: 10 additions & 8 deletions sentence_transformers/models/CLIPModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@ def tokenize(self, texts, padding: Union[str, bool] = True):
texts_values.append(data)
image_text_info.append(1)

if len(texts_values) == 0:
texts_values = None
if len(images) == 0:
images = None

inputs = self.processor(text=texts_values, images=images, return_tensors="pt", padding=padding)
inputs["image_text_info"] = image_text_info
return inputs
encoding = {}
if len(texts_values):
encoding = self.processor.tokenizer(texts_values, return_tensors="pt", padding=padding)

if len(images):
image_features = self.processor.image_processor(images, return_tensors="pt")
encoding["pixel_values"] = image_features.pixel_values

encoding["image_text_info"] = image_text_info
return encoding

def save(self, output_path: str):
self.model.save_pretrained(output_path)
Expand Down
Loading