-
Notifications
You must be signed in to change notification settings - Fork 92
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
Comments
What is the error? We have included the checkpoint, can you please try the included pretrained model and the accompanied evaluation code? |
great thanks : ) I solved the problem. |
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
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()
The text was updated successfully, but these errors were encountered: