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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use after training #37

Closed
moliniao opened this issue Jun 27, 2023 · 5 comments
Closed

How to use after training #37

moliniao opened this issue Jun 27, 2023 · 5 comments

Comments

@moliniao
Copy link

Hello, how to use it after training? My code is as follows, the mask obtained after running is the same no matter what the picture is
code:
modelWeight = "/Users/xxx/Desktop/sement/segment-adapter/SAM-Adapter-PyTorch/pretrained/model_epoch_last.pth"
imageTransform = transforms.Compose([
transforms.Resize((1024, 1024)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
])
configPath = "/Users/xxx/Desktop/sement/segment-adapter/SAM-Adapter-PyTorch/configs/cod-sam-vit-b.yaml"
file1 = "/Users/xxx/Desktop/sement/segment-adapter/SAM-Adapter-PyTorch/camourflage_00103.jpg"
file2 = "/Users/xxx/Desktop/sement/segment-adapter/SAM-Adapter-PyTorch/camourflage_00001.jpg"
img1 = transforms.Resize((1024, 1024))(Image.open(file1).convert('RGB'))
img2 = transforms.Resize((1024, 1024))(Image.open(file2).convert('RGB'))
img1 = imageTransform(img1)
img2 = imageTransform(img2)
bs = torch.stack([img1,img2],dim=0)
with open(configPath, 'r') as f:
config = yaml.load(f, Loader=yaml.FullLoader)
model = models.make(config['model'])
sam_checkpoint = torch.load(modelWeight,map_location=torch.device('cpu'))
model.load_state_dict(sam_checkpoint, strict=True)
model.eval()
masks = model.infer(bs)
sig = torch.sigmoid(masks)
single = torch.squeeze(masks, dim=0)
to_pil = transforms.ToPILImage()
mask_img = to_pil(single[1])
mask_img.show()

@tianrun-chen
Copy link
Owner

What is the error? We have included the checkpoint, can you please try the included pretrained model and the accompanied evaluation code?

@YunyaGaoTree
Copy link

What is the error? We have included the checkpoint, can you please try the included pretrained model and the accompanied evaluation code?

Hello Tianrun,

Could you tell us how to visualize the predicted mask from the fine-tuned models?
If this part of codes were already included in the GitHub, could you tell us where to find them?
If not, it's also OK. I will do it myself.
(I checked most codes but perhaps still missed them)

Like the figures shown in your paper and GitHub.
image

Thanks so much in advance!
Kind regards.

@tianrun-chen
Copy link
Owner

tianrun-chen commented Jun 29, 2023

e068282593a635d6ee14cee0dfbf1b6

You can try this at test.py

@YunyaGaoTree
Copy link

great thanks : ) I solved the problem.

@AnnemSony
Copy link

Thank you ! For multi-class segmentation do we need to make any changes .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants