<jupyter_start><jupyter_text>load data and model<jupyter_code># get dataloader and model
(train_loader, test_loader), model = load_dataloader_and_pretrained_model(p, img_size=256)
torch.manual_seed(p.seed)
im = iter(test_loader).next()[0][0:64].to(device)<jupyter_output><empty_output><jupyter_text>initialize filter<jupyter_code># wavelet transform with initialization
wt_orig = Wavelet_Transform(biort='near_sym_b', qshift='qshift_b', J=5)
viz_im_r(im[0], wt_orig.inverse(wt_orig(im))[0])
print("Recon={:.5f}".format(torch.norm(wt_orig.inverse(wt_orig(im)) - im)**2/im.size(0)))
wt = initialize_filters(wt_orig, noise_level=0.1)
(fl_filt_reals, fl_filt_imags), (sl_filt_reals, sl_filt_imags) = get_2dfilts(wt, wt_type='DTCWT')
viz_im_r(im[0], wt.inverse(wt(im))[0])
print("Recon={:.5f}".format(torch.norm(wt.inverse(wt(im)) - im)**2/im.size(0)))
viz_list(fl_filt_reals)
viz_list(fl_filt_imags)
viz_list(sl_filt_reals)
viz_list(sl_filt_imags)<jupyter_output><empty_output><jupyter_text>optimize filter<jupyter_code># train
params = list(wt.xfm.parameters()) + list(wt.ifm.parameters())
optimizer = torch.optim.SGD(params, lr=0.001)
loss_f = get_loss_f(lamL1attr=10, lamL1Maxattr=0)
trainer = Trainer(model, wt, Attributer, optimizer, loss_f, device=device)
trainer(train_loader, epochs=1)
plt.plot(trainer.train_losses)
(fl_filt_reals, fl_filt_imags), (sl_filt_reals, sl_filt_imags) = get_2dfilts(wt, wt_type='DTCWT')
viz_im_r(im[0], wt.inverse(wt(im))[0])
print("Recon={:.5f}".format(torch.norm(wt.inverse(wt(im)) - im)**2/im.size(0)))
viz_list(fl_filt_reals)
viz_list(fl_filt_imags)
viz_list(sl_filt_reals)
viz_list(sl_filt_imags)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1683704149128082, 'fraction_numerical': 0.022248947684906796, 'mean_word_length': 11.511278195488721, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '632594', 'license': 'MIT', 'n_tokens_mistral': 780, 'n_tokens_neox': 753, 'n_words': 81, 'path': 'notebooks/cosmology/dual-tree/complex_wt.ipynb', 'repo_name': 'Yu-Group/adaptive-wavelets', 'size': '1663'}