<jupyter_start><jupyter_text>Load an example dataset and example kernels<jupyter_code>images = (
    tfds.load(name="set14", split="test")
    .map(datasets.get_value("hr"))
    .map(datasets.to_float32)
    .map(datasets.from_255_to_1_range)
)

tf.random.set_seed(99)  # Random seed for reproducability
mode = "wrap"  # Border mode ('constant' or 'wrap')
noise_stddev = 0.04
image = datasets.get_one_example(images, index=0)[None, ...]
kernel = dppp.conv2D_filter_rgb(dppp.NB_DEBLURRING_LEVIN_KERNELS[0])<jupyter_output><empty_output><jupyter_text>Degrade the image<jupyter_code>degraded = dppp.blur(image, kernel, noise_stddev, clip_final=False, mode=mode)<jupyter_output><empty_output><jupyter_text>Reconstruct the image<jupyter_code># Load the denoiser
denoiser, (denoiser_min_stddev, denoiser_max_stddev) = dppp.load_denoiser(
    "models/drugan+_0.0-0.2.h5"
)

# Define the noise stddev used for the stochastic evaluation of the prior
if denoiser_min_stddev <= 0.1 <= denoiser_max_stddev:
    denoiser_stddev = 0.1
else:
    denoiser_stddev = denoiser_max_stddev

# Callbacks
log_dir = os.path.join("logs", "dmsp_nb")
callbacks = [
    # Print the PSNR every 20th step
    dppp.callback_print_psnr("psnr", 20, image),
    # Log the SSIM to TensorBoard
    dppp.callback_tb_ssim(log_dir, "ssim", image),
]

# Reconstruct the image
reconstructed = dppp.dmsp_deblur_nb(
    degraded=degraded,
    kernel=kernel,
    denoiser=denoiser,
    denoiser_stddev=denoiser_stddev,
    noise_stddev=noise_stddev,
    num_steps=300,
    conv_mode=mode,
    callbacks=callbacks,
)

# Print PSNR and LPIPS
psnr = dppp.psnr(image, reconstructed).numpy()[0]
lpips = dppp.lpips_alex(image, reconstructed).numpy()[0]
print(f"Reconstructed PSNR: {psnr:0.2f}, LPIPS: {lpips:0.4f}")

# Visualize
visualize.draw_images([image[0], degraded[0], reconstructed[0]])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12386545648691938, 'fraction_numerical': 0.02189001601708489, 'mean_word_length': 5.7898550724637685, 'pattern_counts': {'":': 0, '<': 15, '<?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': '140489', 'license': 'MIT', 'n_tokens_mistral': 779, 'n_tokens_neox': 744, 'n_words': 123, 'path': 'notebooks/example_deblur_dmsp.ipynb', 'repo_name': 'HedgehogCode/deep-plug-and-play-prior', 'size': '1873'}