Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

integrate SAM (segment anything) encoder with Unet#757

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Rusteam wants to merge26 commits intoqubvel-org:main
base:main
Choose a base branch
Loading
fromRusteam:sam

Conversation

Rusteam
Copy link

@RusteamRusteam commentedMay 3, 2023
edited
Loading

Closes#756

Added:

  • SAM to models
  • 3 SAM backbones (vit_h,vit_b andvit_l) to encoders
  • unittests and docs for SAM

Changed:

  • flake8 pre-commit repo to github (current) and version to latest

attashe, csaroff, TezRomacH, tabikhm, jaminryu, and adamjstewart reacted with thumbs up emoji
@RusteamRusteam changed the titleintegrate SAM (segment anything) model and encodersDraft: integrate SAM (segment anything) model and encodersMay 3, 2023
@RusteamRusteam changed the titleDraft: integrate SAM (segment anything) model and encodersintegrate SAM (segment anything) model and encodersMay 5, 2023
@Rusteam
Copy link
Author

hi@qubvel is there any update on this?
I've just trained a model using this branch and it worked.

wm-mask reacted with thumbs up emoji

@Rusteam
Copy link
Author

@Rusteam is the code merged into the main repo??i want to use this model to fine-tune my data?

It's not. Not sure if@qubvel has had a chance to look into this PR. You could use my fork in the meanwhile. And do let me know how your fine-Tuning goes because I haven't had much success so far.

@Rusteam
Copy link
Author

@Rusteam how to train a model ,can u give some outlines?as author is not responding pls help me to train a model.. I have sent u an mail pls give a look

make sure you install this package from my forkpip instal git+https://github.com/Rusteam/segmentation_models.pytorch.git@sam and then initialize your model as usualcreate_model("SAM", "sam-vit_b", encoder_weights=None, **kwargs) and run your training. You could passweights="sa-1b" in kwargs if you want to fine-tune from pre-trained weights.

So far I have been able to train the model, but I can't say it's learning. I'm still struggling there. Also I cannot fit more than 1 sample per batch on a 32gb gpu with a 512 input size.

@ccl-private
Copy link

@Rusteam
Copy link
Author

thanks for sharing, I'll try it if my current approach does not work. I've able to get some learning withthis transformers notebook

@qubvel
Copy link
Collaborator

Hi@Rusteam, thanks a lot for your contribution and sorry for the delay, I am going to review the request and will let you know

@Rusteam
Copy link
Author

Hey hey hey. While this solution worked I can't say the model was able to learn on my data. We might need to use the version before my ddp adjustments or make the model handle points and boxes as inputs, or use Sam image encoder with unet or other architectures.

from typing import Optional, Union, List, Tuple

import torch
from segment_anything.modeling import MaskDecoder, TwoWayTransformer, PromptEncoder
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is it a pip package? probably need to add to reqs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

just added it to reqs, or should we make it optional?

@qubvel
Copy link
Collaborator

Yes, I was actually thinking about just pre-trained encoder integration, did you test it?

@Rusteam
Copy link
Author

can we use this model to train on custom data??

@qubvel It didn't work with Unet yet, but I can make it work. Which models would be essential to integrate?

@Rusteam
Copy link
Author

Rusteam commentedMay 18, 2023
edited
Loading

@Rusteam@qubvel can we use this model to train on custom data??

that was my intention as well, but I was unable to make it learn without passing box/point prompts. However, when passing a prompt along with input image, it does learn. We might need to integrate multiple inputs toforward() call for it to work, or just use sam's image encoder with other arches like Unet

@siddpiku
Copy link

The following worked for me:
-git clone the sam branch,
-modify the sam.py file like below to get rid of the errors:
-change def forward(self, x: torch.Tensor) -> list[torch.Tensor]: to def forward(self, x: torch.Tensor):

  • import segmentation_models_pytorch as smp (python file in same folder as git clone branch)
  • smp.create_model("Unet", "sam-vit_b", encoder_weights="sa-1b", encoder_depth=4, decoder_channels=[256, 128, 64, 32])
  • Try training
    What did not work -
  • For me, I tried fine tuning with 2 RTX A6000 GPU with batch size of 2 on the ACDC data (https://www.creatis.insa-lyon.fr/Challenge/acdc/databases.html) but my Dice loss did not improve after 700 epochs. (Maybe some other setting works, but I did not have time to recreate it)

@Rusteam
Copy link
Author

@qubvel hey any updates?

iwaitu, RGring, frkangul, semaphore-egg, Rusab, agentdr1, murdav, csaroff, and WalidGharianiEAGLE reacted with thumbs up emoji

@Rusab
Copy link

Please add this, this library hasn't have new features for a long time

@github-actionsGitHub Actions
Copy link

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days.

@csaroff
Copy link

Is this PR ready?

@Rusteam
Copy link
Author

It's ready.

@17SIM
Copy link

The current PR seems to work with image with the size of 1024x1024 only.

@Rusteam
Copy link
Author

Yes, as the original Sam model

@github-actionsGitHub Actions
Copy link

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days.

@Stinosko
Copy link

Any progress on this?

@Rusab
Copy link

Why is the library dying? no new updates in a long time

@github-actionsGitHub Actions
Copy link

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days.

@Rusteam
Copy link
Author

@qubvel can you merge this? It did work

@isaaccorley
Copy link

@Rusteam Consider contributing this toTorchSeg

@qubvel-orgqubvel-org deleted a comment fromgithub-actionsbotJun 11, 2024
@qubvelqubvel removed the Stale labelJun 11, 2024
@adamjstewart
Copy link
Collaborator

@qubvel should we revive this PR?@giswqs may be interested in this.

@giswqs
Copy link

A relevant PR:huggingface/transformers#32317

@isaaccorley
Copy link

isaaccorley commentedJan 18, 2025
edited
Loading

I think you can already do this because timm supports the SAM ViT weights like:

Unet("tu-samvit_base_patch16.sa1b")

adamjstewart reacted with hooray emoji

@adamjstewart
Copy link
Collaborator

But I'm not sure how well SAM works with U-Net instead of their own custom decoder.

@isaaccorley
Copy link

Agreed, it's likely highly dependent on the prompt embeddings as well.

@ogencoglu
Copy link

I don't think SAM works out of the box like this.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@qubvelqubvelqubvel requested changes

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

SAM backbone integration
15 participants
@Rusteam@ccl-private@qubvel@chefkrym@lixiang007666@sushmanthreddy@siddpiku@Rusab@csaroff@17SIM@Stinosko@isaaccorley@adamjstewart@giswqs@ogencoglu

[8]ページ先頭

©2009-2025 Movatter.jp