MCPcopy Create free account
hub / github.com/294coder/Dif-PAN / test_fn

Function test_fn

diffusion_engine.py:352–505  ·  view source on GitHub ↗
(
    test_data_path,
    weight_path,
    schedule_type="cosine",
    batch_size=320,
    n_steps=1500,
    show=False,
    device="cuda:0",
    full_res=False,
    dataset_name="gf2",
    division=1023,
)

Source from the content-addressed store, hash-verified

350
351@torch.no_grad()
352def test_fn(
353 test_data_path,
354 weight_path,
355 schedule_type="cosine",
356 batch_size=320,
357 n_steps=1500,
358 show=False,
359 device="cuda:0",
360 full_res=False,
361 dataset_name="gf2",
362 division=1023,
363):
364 # lazy import
365 from models.sr3_dwt import UNetSR3 as Unet
366 from diffusion.diffusion_ddpm_pan import GaussianDiffusion
367
368 torch.cuda.set_device(device)
369
370 # load model
371 if dataset_name in ['harvard', 'cave']:
372 image_n_channel = 31
373 image_size = 512 if dataset_name == 'cave' else 1000
374 pan_channel = 3
375 rgb_channels = [39, 19, 9]
376 elif dataset_name in ['wv3', 'gf2', 'qb']:
377 image_size = 512 if full_res else 256
378 image_n_channel = 8 if dataset_name == 'wv3' else 4
379 pan_channel = 1
380 rgb_channels = [4, 2, 0] if dataset_name == 'wv3' else [2, 1, 0]
381 denoise_fn = Unet(
382 in_channel=image_n_channel,
383 out_channel=image_n_channel,
384 lms_channel=image_n_channel,
385 pan_channel=pan_channel,#1,
386 inner_channel=32, # 32,
387 norm_groups=1,
388 channel_mults=(1, 2, 2, 4), # (64, 32, 16, 8)
389 attn_res=(8,),
390 dropout=0.2,
391 image_size=64,
392 self_condition=True,
393 ).to(device)
394 denoise_fn = model_load(weight_path, denoise_fn, device=device)
395
396 denoise_fn.eval()
397 print(f"load weight {weight_path}")
398 diffusion = GaussianDiffusion(
399 denoise_fn,
400 image_size=image_size,
401 channels=image_n_channel,
402 pred_mode="x_start",
403 loss_type="l1",
404 device=device,
405 clamp_range=(0, 1),
406 )
407 diffusion.set_new_noise_schedule(
408 betas=make_beta_schedule(schedule="cosine", n_timestep=n_steps, cosine_s=8e-3)
409 )

Callers 1

Calls 11

model_loadFunction · 0.90
GaussianDiffusionClass · 0.90
make_beta_scheduleFunction · 0.90
PanDatasetClass · 0.90
HISRDataSetsClass · 0.90
AnalysisPanAccClass · 0.90
NonAnalysisPanAccClass · 0.90
path_legal_checkerFunction · 0.90
interpolateMethod · 0.80
print_strMethod · 0.45

Tested by

no test coverage detected