WZH0120 / SAM2-UNet

SAM2-UNet: Segment Anything 2 Makes Strong Encoder for Natural and Medical Image Segmentation
Apache License 2.0
117 stars 15 forks source link

Can this model resume from former checkpoint? #20

Open scpoppin1207 opened 1 week ago

scpoppin1207 commented 1 week ago

I don't see any function or parameters to load from existed checkpoint.

xiongxyowo commented 1 week ago

Hi, you can add/modify the following code to the appropriate place to resume training:

# save meta-data
checkpoint = {'model': model.state_dict(), 'optim': optim.state_dict(), \
              'epoch': epoch, 'lr': scheduler.state_dict(),}
torch.save(checkpoint, path)

# load meta-data
checkpoint = torch.load(path)
model.load_state_dict(checkpoint['model'])
optim.load_state_dict(checkpoint['optim'])
epoch = checkpoint(['epoch'])
scheduler = CosineAnnealingLR(optim, args.epoch, eta_min=1.0e-7, last_epoch=epoch)

You may also refer to the pytorch tutorial.

scpoppin1207 commented 1 week ago

Thxs 👍