Views
No views yet
1import torch
2import segmentation_models_pytorch as smp
3from safetensors.torch import load_file
4
5# Load the model
6model = smp.Unet(
7 encoder_name="resnet50",
8 classes=1,
9 activation=None,
10 decoder_channels=(256, 128, 64, 32, 16)
11)
12
13# Load weights from safetensors
14state_dict = load_file("model.safetensors")
15model.load_state_dict(state_dict)
16model.eval()
17
18# Use for inference
19with torch.no_grad():
20 prediction = model(input_image) # Input: (B, 3, 768, 768)
21 mask = torch.sigmoid(prediction) > 0.5 # Binary mask