.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/unfolded/demo_ram.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_unfolded_demo_ram.py: Reconstruct Anything Model (RAM) for solving inverse problems. ==================================================================================================== This example shows how to use the RAM foundation model to solve inverse problems. The RAM model, described in the following `paper `_, is a modified DRUNet architecture that is trained on a large number of inverse problems. .. GENERATED FROM PYTHON SOURCE LINES 9-52 .. code-block:: Python import torch import deepinv as dinv from deepinv.models import RAM device = "cuda" if torch.cuda.is_available() else "cpu" # Load the pretrained model model = RAM(device=device) # load image x = dinv.utils.load_example("butterfly.png", img_size=(127, 129)).to(device) # create forward operator physics = dinv.physics.Inpainting( img_size=(3, 127, 129), mask=0.3, noise_model=dinv.physics.GaussianNoise(0.05), device=device, ) # generate measurement y = physics(x) # run inference with torch.no_grad(): x_hat = model(y, physics=physics) # compute PSNR in_psnr = dinv.metric.PSNR()(x, y).item() out_psnr = dinv.metric.PSNR()(x, x_hat).item() # plot dinv.utils.plot( [x, y, x_hat], [ "Original", "Measurement\n PSNR = {:.2f}dB".format(in_psnr), "Reconstruction\n PSNR = {:.2f}dB".format(out_psnr), ], figsize=(8, 3), ) .. image-sg:: /auto_examples/unfolded/images/sphx_glr_demo_ram_001.png :alt: Original, Measurement PSNR = 6.03dB, Reconstruction PSNR = 25.80dB :srcset: /auto_examples/unfolded/images/sphx_glr_demo_ram_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Downloading: "https://huggingface.co/mterris/ram/resolve/main/ram.pth.tar" to /home/runner/.cache/torch/hub/checkpoints/ram.pth.tar 0%| | 0.00/136M [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_ram.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_ram.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_