1import os
2import hashlib
3
4import torch
5from model import EarthLoc
6
7# Download the model checkpoint using the following command:
8# rsync -rhz rsync://vandaldata.polito.it/sf_xl/EarthLoc/data/best_trained_model.pt .
9path = "best_trained_model.pt"
10model = EarthLoc(image_size=320, desc_dim=4096)
11state_dict = torch.load(path, weights_only=True, map_location="cpu")
12state_dict = {k.replace("backbone.model.", "backbone."): v for k, v in state_dict.items()}
13model.load_state_dict(state_dict, strict=True)
14
15filename = "earthloc.pth"
16torch.save(model.state_dict(), filename)
17md5 = hashlib.md5(open(filename, "rb").read()).hexdigest()[:8]
18os.rename(filename, filename.replace(".pth", f"-{md5}.pth"))