Views
No views yet
| Metric | Score |
|---|---|
| Dice Score | 0.612 |
| mIoU | 0.716 |
1import torch
2from huggingface_hub import hf_hub_download
3from transformers import AutoProcessor, CLIPSegForImageSegmentation
4from PIL import Image
5
6processor = AutoProcessor.from_pretrained("CIDAS/clipseg-rd64-refined")
7model = CLIPSegForImageSegmentation.from_pretrained("CIDAS/clipseg-rd64-refined")
8
9path = hf_hub_download(repo_id="primus29/crackseg", filename="best_model.pth")
10checkpoint = torch.load(path, map_location="cpu", weights_only=False)
11model.load_state_dict(checkpoint['model_state_dict'])
12model.eval()
13
14image = Image.open("your_image.jpg")
15inputs = processor(text="segment crack", images=image, return_tensors="pt", padding=True)
16
17with torch.no_grad():
18 outputs = model(**inputs)
19
20mask = torch.sigmoid(outputs.logits).squeeze()
21mask = (mask > 0.5).float()