Coder Social home page Coder Social logo

Comments (3)

chongzhou96 avatar chongzhou96 commented on May 20, 2024 2

Let's say the encoder of the original SAM on a 2080 Ti takes 235 ms and that of the EdgeSAM takes 5 ms and the decoder of both models takes 1 ms. The total execution times in everything mode are 235 + 1024 * 1 = 1259 ms and 5 + 1024 * 1 = 1029 ms for SAM and EdgeSAM respectively.

So, if VRAM is not your bottleneck, I would recommend using the original SAM instead.

from edgesam.

chongzhou96 avatar chongzhou96 commented on May 20, 2024

Since EdgeSAM follows the same encoder-decoder architecture as SAM, the everything mode will infer the decoder 32x32=1024 times, which is very inefficient. So I don't recommend doing that.

But if you really want to try it out, here is the script:

from segment_anything import sam_model_registry, SamAutomaticMaskGenerator

sam = sam_model_registry["edge_sam"](checkpoint="weights/edge_sam_3x.pth")
sam = sam.to(device=device)
sam.eval()

mask_generator = SamAutomaticMaskGenerator(sam)

# TODO: read an image and convert it to numpy.ndarray

masks = mask_generator.generate(image)

from edgesam.

CharlesPikachu avatar CharlesPikachu commented on May 20, 2024

I don't want to manually set points or boxes, I want to directly segment all the objects in the graph

Hello, sssegmentation also supported EdgeSAM now, you can write the following codes to achieve this goal after installing sssegmentation,

import cv2
import torch
import numpy as np
import matplotlib.pyplot as plt
from ssseg.modules.models.segmentors.sam.visualization import showanns
from ssseg.modules.models.segmentors.edgesam import EdgeSAMAutomaticMaskGenerator

# read image
image = cv2.imread('images/dog.jpg')
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# mask generator
mask_generator = EdgeSAMAutomaticMaskGenerator(use_default_edgesam=True, device='cuda')
# generate masks on an image
masks = mask_generator.generate(image)
# show all the masks overlayed on the image
plt.figure(figsize=(20, 20))
plt.imshow(image)
showanns(masks)
plt.axis('off')
plt.savefig('mask.png')

from edgesam.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.