Add converted weights
Browse files- aerial_swinb_mi-326d69e1.pth +3 -0
- aerial_swinb_si-e4169eb1.pth +3 -0
- convert.py +69 -0
- landsat_swinb_mi-6b4a1cda.pth +3 -0
- landsat_swinb_si-4af978f6.pth +3 -0
- sentinel1_swinb_mi-f6c43d97.pth +3 -0
- sentinel1_swinb_si-3981c153.pth +3 -0
- sentinel2_resnet152_mi_ms-fd35b4bb.pth +3 -0
- sentinel2_resnet152_mi_rgb-67563ac5.pth +3 -0
- sentinel2_resnet152_si_ms-4500c6cb.pth +3 -0
- sentinel2_resnet152_si_rgb-f4d24c3c.pth +3 -0
- sentinel2_resnet50_mi_ms-da5413d2.pth +3 -0
- sentinel2_resnet50_mi_rgb-e79bb7fe.pth +3 -0
- sentinel2_resnet50_si_ms-1f454cc6.pth +3 -0
- sentinel2_resnet50_si_rgb-45fc6972.pth +3 -0
- sentinel2_swinb_mi_ms-39c86721.pth +3 -0
- sentinel2_swinb_mi_rgb-4efa210c.pth +3 -0
- sentinel2_swinb_si_ms-fe22a12c.pth +3 -0
- sentinel2_swinb_si_rgb-156a98d5.pth +3 -0
- sentinel2_swint_mi_ms-d8c659e3.pth +3 -0
- sentinel2_swint_mi_rgb-424d91f4.pth +3 -0
- sentinel2_swint_si_ms-bc68e396.pth +3 -0
- sentinel2_swint_si_rgb-0c1a96e0.pth +3 -0
aerial_swinb_mi-326d69e1.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:326d69e17c422559e394942239e4868346ab0c315f58c5809c49a25b7ed7bcbb
|
3 |
+
size 352714540
|
aerial_swinb_si-e4169eb1.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e4169eb166c9929f2b435075ee606446d238b8a03eef618cc8974d73f3bc12cb
|
3 |
+
size 352714540
|
convert.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
|
3 |
+
"""Convert Satlas-Pretrain model checkpoints to a format accepted by TorchGeo.
|
4 |
+
|
5 |
+
Reference implementation:
|
6 |
+
|
7 |
+
* https://github.com/allenai/satlaspretrain_models/blob/main/satlaspretrain_models/models/backbones.py
|
8 |
+
"""
|
9 |
+
|
10 |
+
import glob
|
11 |
+
import hashlib
|
12 |
+
import os
|
13 |
+
|
14 |
+
import timm
|
15 |
+
import torch
|
16 |
+
import torchvision
|
17 |
+
|
18 |
+
|
19 |
+
for checkpoint in glob.iglob('*swin*.pth'):
|
20 |
+
# Skip if already converted
|
21 |
+
if '-' in checkpoint:
|
22 |
+
continue
|
23 |
+
|
24 |
+
print(checkpoint)
|
25 |
+
|
26 |
+
# Map to CPU
|
27 |
+
state_dict = torch.load(checkpoint, map_location=torch.device('cpu'), weights_only=True)
|
28 |
+
|
29 |
+
# Extract backbone
|
30 |
+
if 'backbone.backbone.resnet.conv1.weight' in state_dict:
|
31 |
+
state_dict = {key.replace('backbone.backbone.resnet.', ''): value for key, value in state_dict.items() if key.startswith('backbone.backbone.resnet.')}
|
32 |
+
elif 'backbone.resnet.conv1.weight' in state_dict:
|
33 |
+
state_dict = {key.replace('backbone.resnet.', ''): value for key, value in state_dict.items() if key.startswith('backbone.resnet.')}
|
34 |
+
elif 'backbone.backbone.backbone.features.0.0.weight' in state_dict:
|
35 |
+
state_dict = {key.replace('backbone.backbone.backbone.', ''): value for key, value in state_dict.items() if key.startswith('backbone.backbone.backbone.')}
|
36 |
+
elif 'backbone.backbone.features.0.0.weight' in state_dict:
|
37 |
+
state_dict = {key.replace('backbone.backbone.', ''): value for key, value in state_dict.items() if key.startswith('backbone.backbone.')}
|
38 |
+
|
39 |
+
if 'resnet' in checkpoint:
|
40 |
+
# Extract # channels
|
41 |
+
in_chans = state_dict['conv1.weight'].shape[1]
|
42 |
+
|
43 |
+
# Create model
|
44 |
+
model_name = checkpoint.split('_')[1]
|
45 |
+
model = timm.create_model(model_name, in_chans=in_chans)
|
46 |
+
elif 'swin' in checkpoint:
|
47 |
+
# Extract # channels
|
48 |
+
out_channels, num_channels, kernel_size_0, kernel_size_1 = state_dict['features.0.0.weight'].shape
|
49 |
+
|
50 |
+
# Create model
|
51 |
+
if 'swint' in checkpoint:
|
52 |
+
model = torchvision.models.swin_v2_t()
|
53 |
+
elif 'swinb' in checkpoint:
|
54 |
+
model = torchvision.models.swin_v2_b()
|
55 |
+
|
56 |
+
model.features[0][0] = torch.nn.Conv2d(num_channels, out_channels, kernel_size=(kernel_size_0, kernel_size_1), stride=(4, 4))
|
57 |
+
|
58 |
+
# Load weights
|
59 |
+
model.load_state_dict(state_dict)
|
60 |
+
|
61 |
+
# Save model
|
62 |
+
torch.save(model.state_dict(), f'{checkpoint}.tmp')
|
63 |
+
|
64 |
+
# Compute the checksum
|
65 |
+
with open(f'{checkpoint}.tmp', 'rb') as f:
|
66 |
+
checksum = hashlib.file_digest(f, 'sha256').hexdigest()
|
67 |
+
|
68 |
+
# Rename
|
69 |
+
os.rename(f'{checkpoint}.tmp', f'{checkpoint[:-4]}-{checksum[:8]}.pth')
|
landsat_swinb_mi-6b4a1cda.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6b4a1cda734ea4e78309f31ec453fe8dcadc4565ebb2bcbe577e5263aa691d90
|
3 |
+
size 352780529
|
landsat_swinb_si-4af978f6.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4af978f6b6179fa958daacaaad0a7e50201bd863b894f3f60265e90208c4821f
|
3 |
+
size 352780529
|
sentinel1_swinb_mi-f6c43d97.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f6c43d9718e98ec3f96a46973aa3240cfddf1951a2806aa257a6aa648769f5a8
|
3 |
+
size 352707771
|
sentinel1_swinb_si-3981c153.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3981c153754822a0516637187931a2e4e5274c805d570b90baf3ae30ebcf1f5f
|
3 |
+
size 352707771
|
sentinel2_resnet152_mi_ms-fd35b4bb.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fd35b4bb6fb7796a4d2a1f099f5667a52c1a94b7d63d3ec628ae3dfddba3654a
|
3 |
+
size 241773722
|
sentinel2_resnet152_mi_rgb-67563ac5.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:67563ac51362374a8e4ed74bc82fc0724fdd97cc18682c03fb32d38d632b3c66
|
3 |
+
size 241699394
|
sentinel2_resnet152_si_ms-4500c6cb.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4500c6cbc871919e309b816d81ad092c7cc439591ec079fba491be81bc97933d
|
3 |
+
size 241773722
|
sentinel2_resnet152_si_rgb-f4d24c3c.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f4d24c3c4e6d99a53699badd472836d42495d8b316ea2f67f0f3c7513831ef45
|
3 |
+
size 241699394
|
sentinel2_resnet50_mi_ms-da5413d2.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:da5413d266438f3f848b6712a40037b8e360811b0f8b5be442b50ddb1b0137fc
|
3 |
+
size 102625862
|
sentinel2_resnet50_mi_rgb-e79bb7fe.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e79bb7fe84d3893b85a8f0ae6efbac3c7f8a72225db4c9a13e10e6c346896406
|
3 |
+
size 102550922
|
sentinel2_resnet50_si_ms-1f454cc6.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1f454cc627d95dad62646ac7697c2d25f802965b0ddcf07c98935096465bf12c
|
3 |
+
size 102625862
|
sentinel2_resnet50_si_rgb-45fc6972.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:45fc6972ee3e24d5f0a5afd33e44b9fcfc0fdcd2f75deb4b81bef24df3b70722
|
3 |
+
size 102550922
|
sentinel2_swinb_mi_ms-39c86721.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:39c86721744331ca21654869fb268f763e23df6a59bc0b79137868a01af4e448
|
3 |
+
size 352766474
|
sentinel2_swinb_mi_rgb-4efa210c.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4efa210c634b46dd721e16f1baa84ec06d60ed154db97ce299fda0a5b4419e95
|
3 |
+
size 352717775
|
sentinel2_swinb_si_ms-fe22a12c.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fe22a12c0237fa07b801691ac477ce0a263011aacb15305b172e1b76afede947
|
3 |
+
size 352766474
|
sentinel2_swinb_si_rgb-156a98d5.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:156a98d5c9b3340df191eea3315244372c4f31928d50e85033d966cbce0cc080
|
3 |
+
size 352717775
|
sentinel2_swint_mi_ms-d8c659e3.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d8c659e3900ed231382ffddbf4dd4d22d3818493aaf81cb80f0c71ea7541ca80
|
3 |
+
size 113943050
|
sentinel2_swint_mi_rgb-424d91f4.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:424d91f446ac44d3335167da76a1a137ced34c7d1b25c7177db0ccd4ca9c727e
|
3 |
+
size 113906423
|
sentinel2_swint_si_ms-bc68e396.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bc68e396aa183cfbde1afeb622304a0eb7d3af412200c7001babe5a6e69cdbfe
|
3 |
+
size 113943050
|
sentinel2_swint_si_rgb-0c1a96e0.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0c1a96e01ce9bdfef9c04e624de0b1e6672f995d0fba7ab74ebacb6b0393cd7e
|
3 |
+
size 113906423
|