FastSAM
FastSAM copied to clipboard
Masks without the background image
How to obtain as a result the masks without the background image?
Some lines in prompt.py/plot_to_result should be modified
I was also looking for a way to get the masks without the background image, similar to the format that the original SAM provides. The FastSAM code is not very clear about this.
I also have this problem+
import sys import os from matplotlib import pyplot as plt import numpy as np import cv2 from PIL import Image
file_path = os.path.abspath(file) work_path = os.path.dirname(os.path.dirname(file_path)) sys.path.append(work_path) from fastsam import FastSAM, FastSAMPrompt
model = FastSAM(work_path+'/weights/FastSAM_X.pt') IMAGE_PATH = work_path+'/examples/home.jpg' DEVICE = 'cuda' #'cpu' everything_results = model(IMAGE_PATH, device=DEVICE, retina_masks=False, conf=0.4, iou=0.9,) conf=0.4, iou=0.9,imgsz=1024, prompt_process = FastSAMPrompt(IMAGE_PATH, everything_results, device=DEVICE)
ann = prompt_process.everything_prompt()
mask=everything_results[0].masks.data mask=(mask.cpu()*np.array(list(range(1,mask.size()[0]+1)))[:,np.newaxis,np.newaxis]).sum(axis=0)
image = Image.fromarray(mask.numpy().astype('uint8')) image.save(work_path+'/output/home.png')
plt.figure(figsize=(10, 10)) # 255 is the fill color in grayscale (white) plt.imshow(mask, cmap='gray') # Display the image in grayscale plt.axis('off') # Turn off axis numbers and ticks plt.show()
How to obtain as a result the masks without the background image?
do you have any way to relize it?