Views
No views yet
super-image library.super-image.sub_mean and add_mean normalization layers have been removed1from super_image import RcanModel, RcanConfig
2from huggingface_hub import hf_hub_download
3import torch
4
5# load model
6path = hf_hub_download(repo_id="lschmidt/rcan-dsc", filename="rcan_model.py")
7exec(open(path).read())
8model = load_rcan()
9
10# load config
11config, _ = RcanConfig.from_pretrained("lschmidt/rcan-dsc")
12
13# load pretrained weights
14state_dict_path = hf_hub_download(repo_id="lschmidt/rcan-dsc", filename="pytorch_model_4x.pt")
15state_dict = torch.load(state_dict_path, map_location="cpu")
16model.load_state_dict(state_dict, strict=False)
17
18# generate sample data (B, C, W, H)
19inputs = torch.randn(1, 2, 10, 10)
20
21# or use test data
22data_path = hf_hub_download(
23 repo_id="lschmidt/rcan-dsc",
24 filename="test_wind_velocities.nc",
25 subfolder="test_data"
26)
27ds = xr.open_dataset(data_path)
28u = ds["u100"].values[0]
29v = ds["v100"].values[0]
30inputs = torch.from_numpy(np.stack([u, v], axis=0)).unsqueeze(0).float()
31
32# prediction
33output = model(inputs)