isaaccorley commited on
Commit
672bfb5
·
verified ·
1 Parent(s): d6e81e6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +28 -0
README.md CHANGED
@@ -2,3 +2,31 @@
2
  license: mit
3
  library_name: torchgeo
4
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  license: mit
3
  library_name: torchgeo
4
  ---
5
+
6
+
7
+ Model Weights extracted below:
8
+
9
+ ```python
10
+ import os
11
+ import hashlib
12
+
13
+ import torch
14
+ import segmentation_models_pytorch as smp
15
+
16
+
17
+ url = "https://github.com/microsoft/ai4g-flood/raw/refs/heads/main/models/ai4g_sar_model.ckpt"
18
+ state_dict = torch.hub.load_state_dict_from_url(url, weights_only=False, map_location="cpu")["state_dict"]
19
+ state_dict = {k.replace("model.model.", ""): v for k, v in state_dict.items() if "model.model." in k}
20
+ model = smp.Unet(
21
+ encoder_name="mobilenet_v2",
22
+ encoder_weights=None,
23
+ in_channels=2,
24
+ classes=2,
25
+ )
26
+ model.load_state_dict(state_dict, strict=True)
27
+
28
+ filename = "unet_mobilenetv2_sentinel1_ai4g_flood.pth"
29
+ torch.save(model.state_dict(), filename)
30
+ md5 = hashlib.md5(open(filename, "rb").read()).hexdigest()[:8]
31
+ os.rename(filename, filename.replace(".pth", f"-{md5}.pth"))
32
+ ```