Skip to content

Weight Converter & Pretrained Loaders API

Auto-generated from source — see Weight Porting and Pretrained Weights for narrative guides.

Converter

keras_climate.weights.converter.WeightConverter

WeightConverter(keras_model, torch_state_dict, name_map, param_kind_map=None, skip_patterns=None)
Source code in keras_climate/weights/converter.py
67
68
69
70
71
72
73
74
75
76
77
78
79
def __init__(
    self,
    keras_model,
    torch_state_dict,
    name_map,
    param_kind_map=None,
    skip_patterns=None,
):
    self.model = keras_model
    self.state_dict = torch_state_dict
    self.name_map = name_map if callable(name_map) else build_regex_mapper(name_map)
    self.param_kind_map = param_kind_map or {}
    self.skip_patterns = [re.compile(p) for p in (skip_patterns or [])]

keras_climate.weights.converter.infer_transpose

infer_transpose(torch_shape, keras_shape, param_kind=None)
Source code in keras_climate/weights/converter.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def infer_transpose(torch_shape, keras_shape, param_kind=None):
    if param_kind == "dense_kernel":
        return (1, 0)

    if tuple(torch_shape) == tuple(keras_shape):
        return None

    if len(torch_shape) == 2 and torch_shape[::-1] == tuple(keras_shape):
        return (1, 0)

    if param_kind == "conv2d_kernel" or len(torch_shape) == 4:
        candidate = (torch_shape[2], torch_shape[3], torch_shape[1], torch_shape[0])
        if candidate == tuple(keras_shape):
            return (2, 3, 1, 0)

    if param_kind == "conv3d_kernel" or len(torch_shape) == 5:
        candidate = (
            torch_shape[2],
            torch_shape[3],
            torch_shape[4],
            torch_shape[1],
            torch_shape[0],
        )
        if candidate == tuple(keras_shape):
            return (2, 3, 4, 1, 0)

    if param_kind == "conv1d_kernel" or len(torch_shape) == 3:
        candidate = (torch_shape[2], torch_shape[1], torch_shape[0])
        if candidate == tuple(keras_shape):
            return (2, 1, 0)

    if param_kind == "depthwise_kernel" and len(torch_shape) == 4:
        return "depthwise"

    return None

keras_climate.weights.converter.apply_transpose

apply_transpose(array, perm)
Source code in keras_climate/weights/converter.py
42
43
44
45
46
47
48
49
50
def apply_transpose(array, perm):
    if perm is None:
        return array
    if perm == "depthwise":
        out_ch, _, kh, kw = array.shape
        arr = array.reshape(out_ch, 1, kh, kw)
        arr = np.transpose(arr, (2, 3, 0, 1))
        return arr
    return np.transpose(array, perm)

keras_climate.weights.converter.build_regex_mapper

build_regex_mapper(rules)
Source code in keras_climate/weights/converter.py
53
54
55
56
57
58
59
60
61
62
63
def build_regex_mapper(rules):

    compiled = [(re.compile(p), r) for p, r in rules]

    def mapper(torch_key):
        for pattern, replacement in compiled:
            if pattern.search(torch_key):
                return pattern.sub(replacement, torch_key)
        return None

    return mapper

keras_climate.weights.converter.load_torch_state_dict_as_numpy

load_torch_state_dict_as_numpy(checkpoint_path, key_prefix_strip=None)
Source code in keras_climate/weights/converter.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
def load_torch_state_dict_as_numpy(checkpoint_path, key_prefix_strip=None):
    import torch

    state_dict = torch.load(checkpoint_path, map_location="cpu")
    if "state_dict" in state_dict:
        state_dict = state_dict["state_dict"]
    if "model" in state_dict and all(
        isinstance(v, dict) for v in [state_dict.get("model", {})]
    ):
        state_dict = state_dict.get("model", state_dict)

    out = {}
    for k, v in state_dict.items():
        if key_prefix_strip and k.startswith(key_prefix_strip):
            k = k[len(key_prefix_strip) :]
        out[k] = v.detach().cpu().numpy() if hasattr(v, "detach") else np.asarray(v)
    return out

keras_climate.weights.converter.load_safetensors_as_numpy

load_safetensors_as_numpy(checkpoint_path)
Source code in keras_climate/weights/converter.py
200
201
202
203
204
205
206
207
def load_safetensors_as_numpy(checkpoint_path):
    from safetensors import safe_open

    out = {}
    with safe_open(checkpoint_path, framework="numpy") as f:
        for key in f.keys():
            out[key] = f.get_tensor(key)
    return out

Pretrained loaders

keras_climate.weights.pretrained.unet_carvana

unet_carvana(input_shape=(256, 256, 3), cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def unet_carvana(input_shape=(256, 256, 3), cache_dir=None, strict=True):
    path = _download(
        "https://github.com/milesial/Pytorch-UNet/releases/download/v3.0/"
        "unet_carvana_scale1.0_epoch2.pth",
        "unet_carvana_scale1.0_epoch2.pth",
        cache_dir,
    )
    model = UNet(input_shape=input_shape, num_classes=2, base_filters=64, depth=4)
    model(np.zeros((1,) + input_shape, dtype="float32"))

    state_dict = load_torch_state_dict_as_numpy(path)
    report = WeightConverter(
        model,
        state_dict,
        build_unet_mapper(depth=4),
        skip_patterns=[r"num_batches_tracked$"],
    ).convert(strict=strict, verbose=True)
    return model, report

keras_climate.weights.pretrained.deeplabv3plus_resnet50_imagenet_backbone

deeplabv3plus_resnet50_imagenet_backbone(input_shape=(512, 512, 3), num_classes=21, cache_dir=None)
Source code in keras_climate/weights/pretrained.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def deeplabv3plus_resnet50_imagenet_backbone(
    input_shape=(512, 512, 3), num_classes=21, cache_dir=None
):
    path = _download(
        "https://download.pytorch.org/models/resnet50-11ad3fa6.pth",
        "resnet50-11ad3fa6.pth",
        cache_dir,
    )
    model = DeepLabV3Plus(
        input_shape=input_shape,
        num_classes=num_classes,
        backbone_layers=(3, 4, 6, 3),
        output_stride=16,
    )
    model(np.zeros((1,) + input_shape, dtype="float32"))

    state_dict = load_torch_state_dict_as_numpy(path)
    mapper = build_resnet_backbone_mapper(layer_counts=(3, 4, 6, 3))
    report = WeightConverter(
        model,
        state_dict,
        mapper,
        skip_patterns=[r"num_batches_tracked$", r"^fc\."],
    ).convert(strict=False, verbose=True)
    return model, report

keras_climate.weights.pretrained.segformer_b0_ade20k

segformer_b0_ade20k(input_shape=(512, 512, 3), cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def segformer_b0_ade20k(input_shape=(512, 512, 3), cache_dir=None, strict=True):
    from transformers import SegformerForSemanticSegmentation

    hf_model = SegformerForSemanticSegmentation.from_pretrained(
        "nvidia/segformer-b0-finetuned-ade-512-512", cache_dir=cache_dir
    )
    hf_state_dict = {k: v.detach().numpy() for k, v in hf_model.state_dict().items()}
    cfg = MIT_CONFIGS["b0"]
    state_dict = convert_hf_segformer_state_dict(hf_state_dict, cfg)

    model = SegFormer(input_shape=input_shape, num_classes=150, variant="b0")
    model(np.zeros((1,) + input_shape, dtype="float32"))

    mapper = build_segformer_mapper(cfg)
    param_kind_map = build_segformer_param_kind_map(cfg)
    report = WeightConverter(
        model, state_dict, mapper, param_kind_map=param_kind_map
    ).convert(strict=strict, verbose=True)
    return model, report

keras_climate.weights.pretrained.satmae_vit_base_mae

satmae_vit_base_mae(img_size=224, cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def satmae_vit_base_mae(img_size=224, cache_dir=None, strict=True):
    path = _download(
        "https://dl.fbaipublicfiles.com/mae/visualize/mae_visualize_vit_base.pth",
        "mae_visualize_vit_base.pth",
        cache_dir,
    )
    encoder = SatMAEEncoder(
        img_size=img_size,
        patch_size=16,
        in_chans=3,
        embed_dim=768,
        depth=12,
        num_heads=12,
        mode="single",
    )
    decoder = SatMAEDecoder(
        num_patches=(img_size // 16) ** 2,
        patch_size=16,
        in_chans=3,
        decoder_embed_dim=512,
        decoder_depth=8,
        decoder_num_heads=16,
        encoder_embed_dim=768,
    )
    x0 = np.zeros((1, img_size, img_size, 3), dtype="float32")
    tok0, mask0, ids0 = encoder(x0, apply_masking=True, mask_ratio=0.75)
    decoder(tok0, ids0)

    state_dict = load_torch_state_dict_as_numpy(path)
    mapper = build_satmae_mapper()
    enc_report = WeightConverter(
        encoder,
        state_dict,
        mapper,
        skip_patterns=[r"^decoder", r"^mask_token$"],
    ).convert(strict=strict, verbose=True)
    dec_report = WeightConverter(
        decoder,
        state_dict,
        mapper,
        skip_patterns=[
            r"^cls_token$",
            r"^pos_embed$",
            r"^patch_embed",
            r"^blocks\.",
            r"^norm\.(weight|bias)$",
        ],
    ).convert(strict=strict, verbose=True)
    return encoder, decoder, {"encoder": enc_report, "decoder": dec_report}

keras_climate.weights.pretrained.prithvi_eo_100m

prithvi_eo_100m(img_size=224, cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
def prithvi_eo_100m(img_size=224, cache_dir=None, strict=True):
    path = _download(
        "https://huggingface.co/ibm-nasa-geospatial/Prithvi-EO-1.0-100M/resolve/main/"
        "Prithvi_EO_V1_100M.pt",
        "Prithvi_EO_V1_100M.pt",
        cache_dir,
    )
    encoder = PrithviEncoder(
        img_size=img_size,
        patch_size=16,
        num_frames=3,
        tubelet_size=1,
        in_chans=6,
        embed_dim=768,
        depth=12,
        num_heads=12,
        name="encoder",
    )
    encoder(np.zeros((1, 3, img_size, img_size, 6), dtype="float32"))

    state_dict = load_torch_state_dict_as_numpy(path, key_prefix_strip="encoder.")
    mapper = build_vit_mapper("encoder")
    report = WeightConverter(
        encoder,
        state_dict,
        mapper,
        param_kind_map={"encoder/patch_embed/proj/kernel": "conv3d_kernel"},
        skip_patterns=[r"^decoder"],
    ).convert(strict=strict, verbose=True)
    return encoder, report

keras_climate.weights.pretrained.scalemae_vitlarge_fmow

scalemae_vitlarge_fmow(img_size=224, cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
def scalemae_vitlarge_fmow(img_size=224, cache_dir=None, strict=True):
    path = _download(
        "https://huggingface.co/isaaccorley/vit_large_patch16_224_fmow_rgb_scalemae/resolve/main/"
        "vit_large_patch16_224_fmow_rgb_scalemae-386989c9.pth",
        "vit_large_patch16_224_fmow_rgb_scalemae-386989c9.pth",
        cache_dir,
    )
    encoder = ScaleMAEEncoder(
        img_size=img_size,
        patch_size=16,
        in_chans=3,
        embed_dim=1024,
        depth=24,
        num_heads=16,
    )
    encoder(
        [
            np.zeros((1, img_size, img_size, 3), dtype="float32"),
            np.zeros((1,), dtype="float32"),
        ]
    )

    state_dict = load_torch_state_dict_as_numpy(path)
    mapper = build_scalemae_mapper()
    report = WeightConverter(
        encoder,
        state_dict,
        mapper,
        skip_patterns=SCALEMAE_SKIP_PATTERNS,
    ).convert(strict=False, verbose=True)
    expected_missing = {
        "scalemae_encoder/pos_embed/grid_h",
        "scalemae_encoder/pos_embed/grid_w",
        "scalemae_encoder/pos_embed/omega",
    }
    if strict and (
        set(report["missing_in_source"]) - expected_missing
        or report["unused_source_keys"]
    ):
        raise ValueError(
            f"Strict conversion failed: {len(report['missing_in_source'])} missing "
            f"(beyond the expected GSD buffers), {len(report['unused_source_keys'])} unused."
        )
    return encoder, report

keras_climate.weights.pretrained.ssl4eo_resnet50_moco

ssl4eo_resnet50_moco(input_shape=(224, 224, 13), cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
def ssl4eo_resnet50_moco(input_shape=(224, 224, 13), cache_dir=None, strict=True):
    path = _download(
        "https://hf.co/torchgeo/resnet50_sentinel2_all_moco/resolve/"
        "da4f3c9dbe09272eb902f3b37f46635fa4726879/resnet50_sentinel2_all_moco-df8b932e.pth",
        "resnet50_sentinel2_all_moco-df8b932e.pth",
        cache_dir,
    )
    model = SSL4EOResNet50(input_shape=input_shape)
    model(np.zeros((1,) + input_shape, dtype="float32"))

    state_dict = load_torch_state_dict_as_numpy(path)
    mapper = build_ssl4eo_mapper(layer_counts=(3, 4, 6, 3))
    report = WeightConverter(
        model,
        state_dict,
        mapper,
        skip_patterns=[r"num_batches_tracked$"],
    ).convert(strict=strict, verbose=True)
    return model, report

keras_climate.weights.pretrained.satclip_location_encoder_resnet18_l10

satclip_location_encoder_resnet18_l10(cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
def satclip_location_encoder_resnet18_l10(cache_dir=None, strict=True):
    path = _download(
        "https://huggingface.co/microsoft/SatCLIP-ResNet18-L10/resolve/main/satclip-resnet18-l10.ckpt",
        "satclip-resnet18-l10.ckpt",
        cache_dir,
    )
    model = SatCLIPLocationEncoder(
        legendre_polys=10, dim_hidden=512, num_hidden_layers=2, embed_dim=256
    )
    model(np.zeros((1, 2), dtype="float32"))

    state_dict = load_satclip_checkpoint(path)
    mapper = build_satclip_location_mapper(num_hidden_layers=2)
    report = WeightConverter(
        model,
        state_dict,
        mapper,
        skip_patterns=SATCLIP_SKIP_PATTERNS,
    ).convert(strict=strict, verbose=True)
    return model, report

keras_climate.weights.pretrained.prithvi_eo_v2_300m

prithvi_eo_v2_300m(img_size=224, num_frames=4, cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
def prithvi_eo_v2_300m(img_size=224, num_frames=4, cache_dir=None, strict=True):
    path = _download(
        "https://huggingface.co/ibm-nasa-geospatial/Prithvi-EO-2.0-300M/resolve/main/"
        "Prithvi_EO_V2_300M.pt",
        "Prithvi_EO_V2_300M.pt",
        cache_dir,
    )
    cfg = PRITHVI_CONFIGS["prithvi_eo_v2_300m"]
    encoder = PrithviEncoder(
        img_size=img_size,
        patch_size=cfg["patch_size"],
        num_frames=num_frames,
        tubelet_size=1,
        in_chans=6,
        embed_dim=cfg["embed_dim"],
        depth=cfg["depth"],
        num_heads=cfg["num_heads"],
        name="encoder",
    )
    encoder(np.zeros((1, num_frames, img_size, img_size, 6), dtype="float32"))

    state_dict = load_torch_state_dict_as_numpy(path, key_prefix_strip="encoder.")
    mapper = build_vit_mapper("encoder")
    report = WeightConverter(
        encoder,
        state_dict,
        mapper,
        param_kind_map={"encoder/patch_embed/proj/kernel": "conv3d_kernel"},
        skip_patterns=[r"^decoder"],
    ).convert(strict=strict, verbose=True)
    return encoder, report

keras_climate.weights.pretrained.fourcastnet_backbone

fourcastnet_backbone(cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
def fourcastnet_backbone(cache_dir=None, strict=True):
    path = _download(
        "https://portal.nersc.gov/project/m4134/FCN_weights_v0/backbone.ckpt",
        "fourcastnet_backbone.ckpt",
        cache_dir,
    )
    img_size, patch_size = (720, 1440), 8
    grid_h, grid_w = img_size[0] // patch_size, img_size[1] // patch_size
    model = FourCastNet(
        img_size=img_size,
        patch_size=patch_size,
        in_chans=20,
        out_chans=20,
        embed_dim=768,
        depth=12,
        num_blocks=8,
    )
    model(np.zeros((1,) + img_size + (20,), dtype="float32"))

    raw_state_dict = load_fourcastnet_checkpoint(path)
    state_dict = convert_fourcastnet_state_dict(raw_state_dict, grid_h, grid_w)
    mapper = build_fourcastnet_mapper(depth=12)
    report = WeightConverter(model, state_dict, mapper).convert(
        strict=strict, verbose=True
    )
    return model, report

keras_climate.weights.pretrained.climax_1_40625deg

climax_1_40625deg(cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
def climax_1_40625deg(cache_dir=None, strict=True):
    path = _download(
        "https://huggingface.co/microsoft/ClimaX/resolve/main/1.40625deg.ckpt",
        "climax_1_40625deg.ckpt",
        cache_dir,
    )
    img_size, patch_size, num_vars = (128, 256), 4, 48
    model = ClimaX(
        img_size=img_size,
        patch_size=patch_size,
        num_vars=num_vars,
        embed_dim=1024,
        depth=8,
        decoder_depth=2,
        num_heads=16,
    )
    model(
        [
            np.zeros((1,) + img_size + (num_vars,), dtype="float32"),
            np.zeros((1, 1), dtype="float32"),
        ]
    )

    state_dict = load_torch_state_dict_as_numpy(path, key_prefix_strip="net.")
    mapper = build_climax_mapper(num_vars=num_vars, depth=8, decoder_depth=2)
    report = WeightConverter(model, state_dict, mapper).convert(
        strict=strict, verbose=True
    )
    return model, report

keras_climate.weights.pretrained.pangu_weather_24

pangu_weather_24(cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
def pangu_weather_24(cache_dir=None, strict=True):
    zip_path = _download(
        "https://huggingface.co/datasets/zhaoshan/pangu_pytorch/resolve/main/pretrained_model.zip",
        "pangu_pretrained_model.zip",
        cache_dir,
    )
    extract_dir = os.path.join(os.path.dirname(zip_path), "pangu_pretrained_model")
    pth_path = os.path.join(
        extract_dir, "pretrained_model", "pangu_weather_24_torch.pth"
    )
    if not os.path.exists(pth_path):
        with zipfile.ZipFile(zip_path) as zf:
            zf.extractall(extract_dir)

    model = PanguWeather()

    import torch

    ckpt = torch.load(pth_path, map_location="cpu", weights_only=False)
    state_dict = {k: v.detach().numpy() for k, v in ckpt["model"].items()}
    state_dict = convert_pangu_weather_state_dict(state_dict)

    mapper = build_pangu_weather_mapper(depths=(2, 6, 6, 2))
    report = WeightConverter(model, state_dict, mapper).convert(
        strict=False, verbose=True
    )
    expected_missing = {
        k for k in report["missing_in_source"] if k.endswith("attn_mask")
    }
    if strict and (
        set(report["missing_in_source"]) - expected_missing
        or report["unused_source_keys"]
    ):
        raise ValueError(
            f"Strict conversion failed: {len(report['missing_in_source'])} missing "
            f"(beyond the expected attn_mask buffers), {len(report['unused_source_keys'])} unused."
        )
    return model, report

keras_climate.weights.pretrained.croma_base

croma_base(img_size=120, cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
445
446
def croma_base(img_size=120, cache_dir=None, strict=True):
    return _croma(size="base", img_size=img_size, cache_dir=cache_dir, strict=strict)

keras_climate.weights.pretrained.croma_large

croma_large(img_size=120, cache_dir=None, strict=True)
Source code in keras_climate/weights/pretrained.py
449
450
def croma_large(img_size=120, cache_dir=None, strict=True):
    return _croma(size="large", img_size=img_size, cache_dir=cache_dir, strict=strict)

keras_climate.weights.pretrained.anysat_base

anysat_base(modalities=None, input_shapes=None, scale=1, cache_dir=None, strict=False)
Source code in keras_climate/weights/pretrained.py
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
def anysat_base(
    modalities=None, input_shapes=None, scale=1, cache_dir=None, strict=False
):
    path = _download(
        "https://huggingface.co/g-astruc/AnySat/resolve/main/models/AnySat.pth",
        "AnySat.pth",
        cache_dir,
    )
    if modalities is None:
        modalities = ["aerial", "s2"]

    proj_cfgs = anysat_projector_configs(768)
    if input_shapes is None:
        input_shapes = {}
        for m in modalities:
            pc = proj_cfgs[m]
            if pc["kind"] == "image":
                res = int(10 / pc["resolution"])
                gs = res // pc["patch_size"]
                side = gs * scale * pc["patch_size"]
                input_shapes[m] = (side, side, pc["in_chans"])
            else:
                se = max(1, scale // pc["reduce_scale"])
                input_shapes[m] = (8, se, se, pc["in_channels"])

    model = AnySatRelease(modalities, input_shapes, scale, size="base")
    dummy = {}
    for m in modalities:
        shp = input_shapes[m]
        if proj_cfgs[m]["kind"] == "image":
            dummy[m] = np.zeros((1,) + shp, dtype="float32")
        else:
            dummy[m] = (
                np.zeros((1,) + shp, dtype="float32"),
                np.zeros((1, shp[0]), dtype="float32"),
            )
    model(dummy)

    state_dict = load_torch_state_dict_as_numpy(path)
    mapper = build_anysat_release_mapper(modalities, depth=6)
    report = WeightConverter(
        model,
        state_dict,
        mapper,
        skip_patterns=[r"pad_parameter$"],
    ).convert(strict=False, verbose=True)
    expected_missing = {
        w for w in report["missing_in_source"] if w.endswith("/pe_denom")
    }
    if strict and (
        set(report["missing_in_source"]) - expected_missing
        or report["unused_source_keys"]
    ):
        raise ValueError(
            f"Strict conversion failed: {len(report['missing_in_source'])} missing "
            f"(beyond the expected pe_denom buffers), {len(report['unused_source_keys'])} unused "
            f"(unused is expected/nonzero when `modalities` is a subset of ANYSAT_MODALITIES)."
        )
    return model, report