System Info
transformers version: 4.35.0.dev0
- Platform: Linux-5.4.15-1.el7.elrepo.x86_64-x86_64-with-glibc2.27
- Python version: 3.11.4
- Huggingface_hub version: 0.17.3
- Safetensors version: 0.4.0
- Accelerate version: 0.23.0
- Accelerate config: not found
- PyTorch version (GPU?): 2.1.0+cu121 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: yes
- Using distributed or parallel set-up in script?: yes (but I grabbed 1 GPU only to my workspace bash terminal)
Who can help?
@amyeroberts @Narsil
Information
Tasks
Reproduction
Following the example notebook of automatic mask generation using SAM model, I used the following code snippet to do image segmentation:
import numpy as np
import matplotlib.pyplot as plt
import gc
from transformers import pipeline
from PIL import Image
import requests
def show_mask(mask, ax, random_color=False):
if random_color:
color = np.concatenate([np.random.random(3), np.array([0.6])], axis=0)
else:
color = np.array([30 / 255, 144 / 255, 255 / 255, 0.6])
h, w = mask.shape[-2:]
mask_image = mask.reshape(h, w, 1) * color.reshape(1, 1, -1)
ax.imshow(mask_image)
del mask
gc.collect()
def show_masks_on_image(raw_image, masks):
plt.imshow(np.array(raw_image))
ax = plt.gca()
ax.set_autoscale_on(False)
for mask in masks:
show_mask(mask, ax=ax, random_color=True)
plt.axis("off")
plt.show()
del mask
gc.collect()
generator = pipeline("mask-generation", model="facebook/sam-vit-base", device=0)
raw_image = Image.open("test.png")
outputs = generator(raw_image, points_per_batch=64)
masks = outputs["masks"]
show_masks_on_image(raw_image, masks)
The original code is provided in the form of a notebook, which I arrange as a script that can be run in the terminal.
Expected behavior
The output is empty, and no mask is shown on the image. When I insert print(outputs) into the code snippet, the output in the terminal is {'masks': [], 'scores': tensor([])}.
System Info
transformersversion: 4.35.0.dev0Who can help?
@amyeroberts @Narsil
Information
Tasks
examplesfolder (such as GLUE/SQuAD, ...)Reproduction
Following the example notebook of automatic mask generation using SAM model, I used the following code snippet to do image segmentation:
The original code is provided in the form of a notebook, which I arrange as a script that can be run in the terminal.
Expected behavior
The output is empty, and no mask is shown on the image. When I insert
print(outputs)into the code snippet, the output in the terminal is{'masks': [], 'scores': tensor([])}.