Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
---
|
| 4 |
+
|
| 5 |
+
Rehosted from https://huggingface.co/saadlahrichi/WSTSPlus
|
| 6 |
+
|
| 7 |
+
Converted using the following code:
|
| 8 |
+
|
| 9 |
+
```python
|
| 10 |
+
import os
|
| 11 |
+
import segmentation_models_pytorch as smp
|
| 12 |
+
import torch
|
| 13 |
+
import hashlib
|
| 14 |
+
|
| 15 |
+
urls = {
|
| 16 |
+
"t1-all": "https://hf.co/saadlahrichi/WSTSPlus/resolve/main/trained_model_weights/Res18Unet_T1/All/fold6_testAP0.577.pth",
|
| 17 |
+
"t1-multi": "https://hf.co/saadlahrichi/WSTSPlus/resolve/main/trained_model_weights/Res18Unet_T1/Multi/fold6_testAP0.585.pth",
|
| 18 |
+
"t1-veg": "https://hf.co/saadlahrichi/WSTSPlus/resolve/main/trained_model_weights/Res18Unet_T1/Veg/fold2_testAP0.567.pth",
|
| 19 |
+
"t5-all": "https://hf.co/saadlahrichi/WSTSPlus/resolve/main/trained_model_weights/Res18Unet_T5/All/fold2_testAP0.594.pth",
|
| 20 |
+
"t5-multi": "https://hf.co/saadlahrichi/WSTSPlus/resolve/main/trained_model_weights/Res18Unet_T5/Multi/fold2_testAP0.597.pth",
|
| 21 |
+
"t5-veg": "https://hf.co/saadlahrichi/WSTSPlus/resolve/main/trained_model_weights/Res18Unet_T5/Veg/fold2_testAP0.590.pth",
|
| 22 |
+
}
|
| 23 |
+
for prefix, url in urls.items():
|
| 24 |
+
state_dict = torch.hub.load_state_dict_from_url(url, weights_only=True, map_location="cpu")
|
| 25 |
+
state_dict = {k.replace("model.", ""): v for k, v in state_dict.items()}
|
| 26 |
+
in_channels = state_dict["encoder.conv1.weight"].shape[1]
|
| 27 |
+
print(f"{prefix}: in_channels={in_channels}")
|
| 28 |
+
model = smp.Unet(encoder_name="resnet18", in_channels=in_channels, classes=1, encoder_weights=None)
|
| 29 |
+
model.load_state_dict(state_dict, strict=True)
|
| 30 |
+
filename = f"unet-resnet18-{prefix}.pth"
|
| 31 |
+
torch.save(model.state_dict(), filename)
|
| 32 |
+
md5 = hashlib.md5(open(filename, "rb").read()).hexdigest()[:8]
|
| 33 |
+
os.rename(filename, filename.replace(".pth", f"-{md5}.pth"))
|
| 34 |
+
```
|