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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Image segmentation description #23261

Merged
merged 2 commits into from
May 10, 2023
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
11 changes: 5 additions & 6 deletions src/transformers/tools/image_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@

class ImageSegmentationTool(PipelineTool):
description = (
"This is a tool that creates a segmentation mask identifiying elements inside an image according to a prompt. "
"It takes two arguments named `image` which should be the original image, and `prompt` which should be a text "
"describing the elements what should be identified in the segmentation mask. The tool returns the mask as a "
"black-and-white image."
"This is a tool that creates a segmentation mask of an image according to a label. It cannot create an image."
"It takes two arguments named `image` which should be the original image, and `label` which should be a text "
"describing the elements what should be identified in the segmentation mask. The tool returns the mask."
)
default_checkpoint = "CIDAS/clipseg-rd64-refined"
name = "image_segmenter"
Expand All @@ -44,9 +43,9 @@ def __init__(self, *args, **kwargs):
requires_backends(self, ["vision"])
super().__init__(*args, **kwargs)

def encode(self, image: "Image", prompt: str):
def encode(self, image: "Image", label: str):
self.pre_processor.image_processor.size = {"width": image.size[0], "height": image.size[1]}
return self.pre_processor(text=[prompt], images=[image], padding=True, return_tensors="pt")
return self.pre_processor(text=[label], images=[image], padding=True, return_tensors="pt")

def forward(self, inputs):
with torch.no_grad():
Expand Down
Loading