Learn Straight line readout pattern#

A small pytorch example to showcase learning k-space sampling patterns. In this example we learn the 2D sampling pattern for a 3D MRI image, assuming straight line readouts. This example showcases the auto-diff capabilities of the NUFFT operator The image resolution is kept small to reduce computation time.

Warning

This example only showcases the autodiff capabilities, the learned sampling pattern is not scanner compliant as the scanner gradients required to implement it violate the hardware constraints. In practice, a projection \(\Pi_\mathcal{Q}(\mathbf{K})\) into the scanner constraints set \(\mathcal{Q}\) is recommended (see [Proj]). This is implemented in the proprietary SPARKLING package [Sparks]. Users are encouraged to contact the authors if they want to use it.

Imports#

import time
import joblib

import brainweb_dl as bwdl
import matplotlib.pyplot as plt
import numpy as np
import torch
from tqdm import tqdm
from PIL import Image, ImageSequence

from mrinufft import get_operator

Setup a simple class to learn trajectory#

Note

While we are only learning the NUFFT operator, we still need the gradient wrt_data=True to have all the gradients computed correctly. See [Projector] for more details.

class Model(torch.nn.Module):
    def __init__(self, num_shots, img_size, factor_cartesian=0.3):
        super(Model, self).__init__()
        self.num_samples_per_shot = 128
        cart_del = 1 / img_size[0]
        num_cart_points = np.round(np.sqrt(factor_cartesian * num_shots)).astype(int)
        edge_center = cart_del * num_cart_points / 2

        self.central_points = torch.nn.Parameter(
            data=torch.stack(
                torch.meshgrid(
                    torch.linspace(-edge_center, edge_center, num_cart_points),
                    torch.linspace(-edge_center, edge_center, num_cart_points),
                    indexing="ij",
                ),
                axis=-1,
            ).reshape(-1, 2),
            requires_grad=False,
        )
        self.non_center_points = torch.nn.Parameter(
            data=torch.Tensor(
                np.random.random((num_shots - self.central_points.shape[0], 2)) - 0.5
            ),
            requires_grad=True,
        )
        self.operator = get_operator("gpunufft", wrt_data=True, wrt_traj=True)(
            np.random.random(
                (self.get_2D_points().shape[0] * self.num_samples_per_shot, 3)
            )
            - 0.5,
            shape=img_size,
            density=True,
            squeeze_dims=False,
        )

    def get_trajectory(self, get_as_shot=False):
        samples = self._get_3D_points(self.get_2D_points())
        if not get_as_shot:
            return samples
        return samples.reshape(-1, self.num_samples_per_shot, 3)

    def get_2D_points(self):
        return torch.vstack([self.central_points, self.non_center_points])

    def _get_3D_points(self, samples2D):
        line = torch.linspace(
            -0.5,
            0.5,
            self.num_samples_per_shot,
            device=samples2D.device,
            dtype=samples2D.dtype,
        )
        return torch.stack(
            [
                line.repeat(samples2D.shape[0], 1),
                samples2D[:, 0].repeat(self.num_samples_per_shot, 1).T,
                samples2D[:, 1].repeat(self.num_samples_per_shot, 1).T,
            ],
            dim=-1,
        ).reshape(-1, 3)

    def forward(self, x):
        self.operator.samples = self.get_trajectory()
        kspace = self.operator.op(x)
        adjoint = self.operator.adj_op(kspace).abs()
        return adjoint / torch.mean(adjoint)

Util function to plot the state of the model#

def plot_state(mri_2D, traj, recon, loss=None, save_name=None, i=None):
    fig_grid = (2, 2)
    if loss is None:
        fig_grid = (1, 3)
    fig, axs = plt.subplots(*fig_grid, figsize=tuple(i * 5 for i in fig_grid[::-1]))
    axs = axs.flatten()
    axs[0].imshow(np.abs(mri_2D[0][..., 11]), cmap="gray")
    axs[0].axis("off")
    axs[0].set_title("MR Image")
    if traj.shape[-1] == 3:
        if i is not None and i > 50:
            axs[1].scatter(*traj.T[1:3, 0], s=10, color="blue")
        else:
            fig_kwargs = {}
            plt_kwargs = {"s": 1, "alpha": 0.2}
            if i is not None:
                fig_kwargs["azim"], fig_kwargs["elev"] = (
                    i / 50 * 60 - 60,
                    30 - i / 50 * 30,
                )
                plt_kwargs["alpha"] = 0.2 + 0.8 * i / 50
                plt_kwargs["s"] = 1 + 9 * i / 50
            axs[1].remove()
            axs[1] = fig.add_subplot(*fig_grid, 2, projection="3d", **fig_kwargs)
            for shot in traj:
                axs[1].scatter(*shot.T, color="blue", **plt_kwargs)
    else:
        axs[1].scatter(*traj.T, s=10)
    axs[1].set_title("Trajectory")
    axs[2].imshow(np.abs(recon[0][0][..., 11].detach().cpu().numpy()), cmap="gray")
    axs[2].axis("off")
    axs[2].set_title("Reconstruction")
    if loss is not None:
        axs[3].plot(loss)
        axs[3].grid("on")
        axs[3].set_title("Loss")
    if save_name is not None:
        plt.savefig(save_name, bbox_inches="tight")
        plt.close()
    else:
        plt.show()

Setup model and optimizer#

cart_data = np.flipud(bwdl.get_mri(4, "T1")).T[::8, ::8, ::8].astype(np.complex64)
model = Model(253, cart_data.shape)
optimizer = torch.optim.Adam(model.parameters(), lr=1e-2)

Setup data#

mri_3D = torch.Tensor(cart_data)[None]
mri_3D = mri_3D / torch.mean(mri_3D)
model.eval()
recon = model(mri_3D)
plot_state(mri_3D, model.get_trajectory(True).detach().cpu().numpy(), recon)
MR Image, Reconstruction, Trajectory
/volatile/github-ci-mind-inria/_work/mri-nufft/mri-nufft/examples/GPU/example_learn_straight_line_readouts.py:174: UserWarning: Casting complex values to real discards the imaginary part (Triggered internally at ../aten/src/ATen/native/Copy.cpp:308.)
  mri_3D = torch.Tensor(cart_data)[None]

Start training loop#

losses = []
image_files = []
model.train()
with tqdm(range(100), unit="steps") as tqdms:
    for i in tqdms:
        out = model(mri_3D)
        loss = torch.nn.functional.mse_loss(out, mri_3D[None])
        numpy_loss = loss.detach().cpu().numpy()
        tqdms.set_postfix({"loss": numpy_loss})
        losses.append(numpy_loss)
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()
        with torch.no_grad():
            # Clamp the value of trajectory between [-0.5, 0.5]
            for param in model.parameters():
                param.clamp_(-0.5, 0.5)
        # Generate images for gif
        hashed = joblib.hash((i, "learn_line", time.time()))
        filename = "/tmp/" + f"{hashed}.png"
        plot_state(
            mri_3D,
            model.get_trajectory(True).detach().cpu().numpy(),
            out,
            losses,
            save_name=filename,
            i=i,
        )
        image_files.append(filename)

# Make a GIF of all images.
imgs = [Image.open(img) for img in image_files]
imgs[0].save(
    "mrinufft_learn_2d_sampling_pattern.gif",
    save_all=True,
    append_images=imgs[1:],
    optimize=False,
    duration=2,
    loop=0,
)

# sphinx_gallery_thumbnail_path = 'generated/autoexamples/GPU/images/mrinufft_learn_2d_sampling_pattern.gif'
  0%|          | 0/100 [00:00<?, ?steps/s]
  0%|          | 0/100 [00:00<?, ?steps/s, loss=0.30334628]
  1%|          | 1/100 [00:03<06:10,  3.74s/steps, loss=0.30334628]
  1%|          | 1/100 [00:04<06:10,  3.74s/steps, loss=0.28526625]
  2%|▏         | 2/100 [00:07<06:10,  3.78s/steps, loss=0.28526625]
  2%|▏         | 2/100 [00:07<06:10,  3.78s/steps, loss=0.27382597]
  3%|▎         | 3/100 [00:11<06:06,  3.77s/steps, loss=0.27382597]
  3%|▎         | 3/100 [00:11<06:06,  3.77s/steps, loss=0.26730937]
  4%|▍         | 4/100 [00:16<06:43,  4.20s/steps, loss=0.26730937]
  4%|▍         | 4/100 [00:16<06:43,  4.20s/steps, loss=0.25987548]
  5%|▌         | 5/100 [00:20<06:50,  4.32s/steps, loss=0.25987548]
  5%|▌         | 5/100 [00:20<06:50,  4.32s/steps, loss=0.25399935]
  6%|▌         | 6/100 [00:25<07:11,  4.59s/steps, loss=0.25399935]
  6%|▌         | 6/100 [00:25<07:11,  4.59s/steps, loss=0.25090066]
  7%|▋         | 7/100 [00:31<07:34,  4.88s/steps, loss=0.25090066]
  7%|▋         | 7/100 [00:31<07:34,  4.88s/steps, loss=0.24816301]
  8%|▊         | 8/100 [00:35<07:03,  4.61s/steps, loss=0.24816301]
  8%|▊         | 8/100 [00:35<07:03,  4.61s/steps, loss=0.24653663]
  9%|▉         | 9/100 [00:39<06:46,  4.47s/steps, loss=0.24653663]
  9%|▉         | 9/100 [00:39<06:46,  4.47s/steps, loss=0.24430549]
 10%|█         | 10/100 [00:42<06:10,  4.12s/steps, loss=0.24430549]
 10%|█         | 10/100 [00:42<06:10,  4.12s/steps, loss=0.24154301]
 11%|█         | 11/100 [00:46<05:53,  3.97s/steps, loss=0.24154301]
 11%|█         | 11/100 [00:46<05:53,  3.97s/steps, loss=0.23875257]
 12%|█▏        | 12/100 [00:50<05:59,  4.09s/steps, loss=0.23875257]
 12%|█▏        | 12/100 [00:50<05:59,  4.09s/steps, loss=0.23727962]
 13%|█▎        | 13/100 [00:54<05:43,  3.95s/steps, loss=0.23727962]
 13%|█▎        | 13/100 [00:54<05:43,  3.95s/steps, loss=0.23592062]
 14%|█▍        | 14/100 [00:58<05:30,  3.84s/steps, loss=0.23592062]
 14%|█▍        | 14/100 [00:58<05:30,  3.84s/steps, loss=0.23413292]
 15%|█▌        | 15/100 [01:02<05:31,  3.90s/steps, loss=0.23413292]
 15%|█▌        | 15/100 [01:02<05:31,  3.90s/steps, loss=0.2324738]
 16%|█▌        | 16/100 [01:05<05:27,  3.90s/steps, loss=0.2324738]
 16%|█▌        | 16/100 [01:06<05:27,  3.90s/steps, loss=0.23144874]
 17%|█▋        | 17/100 [01:09<05:13,  3.78s/steps, loss=0.23144874]
 17%|█▋        | 17/100 [01:09<05:13,  3.78s/steps, loss=0.23042053]
 18%|█▊        | 18/100 [01:13<05:17,  3.87s/steps, loss=0.23042053]
 18%|█▊        | 18/100 [01:13<05:17,  3.87s/steps, loss=0.2295474]
 19%|█▉        | 19/100 [01:17<05:16,  3.91s/steps, loss=0.2295474]
 19%|█▉        | 19/100 [01:17<05:16,  3.91s/steps, loss=0.22821033]
 20%|██        | 20/100 [01:21<05:07,  3.84s/steps, loss=0.22821033]
 20%|██        | 20/100 [01:21<05:07,  3.84s/steps, loss=0.22642592]
 21%|██        | 21/100 [01:24<04:57,  3.76s/steps, loss=0.22642592]
 21%|██        | 21/100 [01:24<04:57,  3.76s/steps, loss=0.22525012]
 22%|██▏       | 22/100 [01:28<04:55,  3.79s/steps, loss=0.22525012]
 22%|██▏       | 22/100 [01:28<04:55,  3.79s/steps, loss=0.22482114]
 23%|██▎       | 23/100 [01:32<04:50,  3.77s/steps, loss=0.22482114]
 23%|██▎       | 23/100 [01:32<04:50,  3.77s/steps, loss=0.22519]
 24%|██▍       | 24/100 [01:36<04:44,  3.74s/steps, loss=0.22519]
 24%|██▍       | 24/100 [01:36<04:44,  3.74s/steps, loss=0.22466317]
 25%|██▌       | 25/100 [01:39<04:41,  3.75s/steps, loss=0.22466317]
 25%|██▌       | 25/100 [01:39<04:41,  3.75s/steps, loss=0.223486]
 26%|██▌       | 26/100 [01:43<04:45,  3.86s/steps, loss=0.223486]
 26%|██▌       | 26/100 [01:44<04:45,  3.86s/steps, loss=0.22310999]
 27%|██▋       | 27/100 [01:47<04:36,  3.79s/steps, loss=0.22310999]
 27%|██▋       | 27/100 [01:47<04:36,  3.79s/steps, loss=0.2227087]
 28%|██▊       | 28/100 [01:51<04:25,  3.68s/steps, loss=0.2227087]
 28%|██▊       | 28/100 [01:51<04:25,  3.68s/steps, loss=0.22214228]
 29%|██▉       | 29/100 [01:54<04:23,  3.71s/steps, loss=0.22214228]
 29%|██▉       | 29/100 [01:54<04:23,  3.71s/steps, loss=0.22108209]
 30%|███       | 30/100 [01:58<04:14,  3.63s/steps, loss=0.22108209]
 30%|███       | 30/100 [01:58<04:14,  3.63s/steps, loss=0.22047243]
 31%|███       | 31/100 [02:01<04:13,  3.67s/steps, loss=0.22047243]
 31%|███       | 31/100 [02:02<04:13,  3.67s/steps, loss=0.22032358]
 32%|███▏      | 32/100 [02:05<04:10,  3.68s/steps, loss=0.22032358]
 32%|███▏      | 32/100 [02:06<04:10,  3.68s/steps, loss=0.22038329]
 33%|███▎      | 33/100 [02:09<04:12,  3.77s/steps, loss=0.22038329]
 33%|███▎      | 33/100 [02:09<04:12,  3.77s/steps, loss=0.21998231]
 34%|███▍      | 34/100 [02:13<04:17,  3.89s/steps, loss=0.21998231]
 34%|███▍      | 34/100 [02:13<04:17,  3.89s/steps, loss=0.21948083]
 35%|███▌      | 35/100 [02:17<04:09,  3.84s/steps, loss=0.21948083]
 35%|███▌      | 35/100 [02:17<04:09,  3.84s/steps, loss=0.21901317]
 36%|███▌      | 36/100 [02:21<04:00,  3.76s/steps, loss=0.21901317]
 36%|███▌      | 36/100 [02:21<04:00,  3.76s/steps, loss=0.2188571]
 37%|███▋      | 37/100 [02:25<04:02,  3.85s/steps, loss=0.2188571]
 37%|███▋      | 37/100 [02:25<04:02,  3.85s/steps, loss=0.21854638]
 38%|███▊      | 38/100 [02:28<03:57,  3.83s/steps, loss=0.21854638]
 38%|███▊      | 38/100 [02:29<03:57,  3.83s/steps, loss=0.21818337]
 39%|███▉      | 39/100 [02:32<03:48,  3.74s/steps, loss=0.21818337]
 39%|███▉      | 39/100 [02:32<03:48,  3.74s/steps, loss=0.21798687]
 40%|████      | 40/100 [02:35<03:39,  3.66s/steps, loss=0.21798687]
 40%|████      | 40/100 [02:36<03:39,  3.66s/steps, loss=0.21792617]
 41%|████      | 41/100 [02:39<03:32,  3.60s/steps, loss=0.21792617]
 41%|████      | 41/100 [02:39<03:32,  3.60s/steps, loss=0.21772136]
 42%|████▏     | 42/100 [02:43<03:38,  3.77s/steps, loss=0.21772136]
 42%|████▏     | 42/100 [02:43<03:38,  3.77s/steps, loss=0.21743393]
 43%|████▎     | 43/100 [02:47<03:28,  3.66s/steps, loss=0.21743393]
 43%|████▎     | 43/100 [02:47<03:28,  3.66s/steps, loss=0.21702872]
 44%|████▍     | 44/100 [02:50<03:15,  3.49s/steps, loss=0.21702872]
 44%|████▍     | 44/100 [02:50<03:15,  3.49s/steps, loss=0.2166996]
 45%|████▌     | 45/100 [02:53<03:09,  3.45s/steps, loss=0.2166996]
 45%|████▌     | 45/100 [02:53<03:09,  3.45s/steps, loss=0.21650456]
 46%|████▌     | 46/100 [02:56<02:59,  3.33s/steps, loss=0.21650456]
 46%|████▌     | 46/100 [02:56<02:59,  3.33s/steps, loss=0.21677652]
 47%|████▋     | 47/100 [02:59<02:51,  3.23s/steps, loss=0.21677652]
 47%|████▋     | 47/100 [02:59<02:51,  3.23s/steps, loss=0.21708229]
 48%|████▊     | 48/100 [03:02<02:47,  3.22s/steps, loss=0.21708229]
 48%|████▊     | 48/100 [03:02<02:47,  3.22s/steps, loss=0.21700096]
 49%|████▉     | 49/100 [03:05<02:41,  3.17s/steps, loss=0.21700096]
 49%|████▉     | 49/100 [03:05<02:41,  3.17s/steps, loss=0.21659918]
 50%|█████     | 50/100 [03:08<02:36,  3.13s/steps, loss=0.21659918]
 50%|█████     | 50/100 [03:08<02:36,  3.13s/steps, loss=0.21602964]
 51%|█████     | 51/100 [03:12<02:35,  3.18s/steps, loss=0.21602964]
 51%|█████     | 51/100 [03:12<02:35,  3.18s/steps, loss=0.21589479]
 52%|█████▏    | 52/100 [03:12<01:54,  2.38s/steps, loss=0.21589479]
 52%|█████▏    | 52/100 [03:12<01:54,  2.38s/steps, loss=0.2158959]
 53%|█████▎    | 53/100 [03:13<01:25,  1.81s/steps, loss=0.2158959]
 53%|█████▎    | 53/100 [03:13<01:25,  1.81s/steps, loss=0.21594904]
 54%|█████▍    | 54/100 [03:13<01:05,  1.42s/steps, loss=0.21594904]
 54%|█████▍    | 54/100 [03:13<01:05,  1.42s/steps, loss=0.215902]
 55%|█████▌    | 55/100 [03:14<00:51,  1.15s/steps, loss=0.215902]
 55%|█████▌    | 55/100 [03:14<00:51,  1.15s/steps, loss=0.21567915]
 56%|█████▌    | 56/100 [03:14<00:42,  1.05steps/s, loss=0.21567915]
 56%|█████▌    | 56/100 [03:14<00:42,  1.05steps/s, loss=0.21558629]
 57%|█████▋    | 57/100 [03:15<00:35,  1.22steps/s, loss=0.21558629]
 57%|█████▋    | 57/100 [03:15<00:35,  1.22steps/s, loss=0.21579467]
 58%|█████▊    | 58/100 [03:15<00:33,  1.25steps/s, loss=0.21579467]
 58%|█████▊    | 58/100 [03:15<00:33,  1.25steps/s, loss=0.2157607]
 59%|█████▉    | 59/100 [03:16<00:29,  1.41steps/s, loss=0.2157607]
 59%|█████▉    | 59/100 [03:16<00:29,  1.41steps/s, loss=0.21553956]
 60%|██████    | 60/100 [03:16<00:26,  1.54steps/s, loss=0.21553956]
 60%|██████    | 60/100 [03:16<00:26,  1.54steps/s, loss=0.21545102]
 61%|██████    | 61/100 [03:17<00:23,  1.65steps/s, loss=0.21545102]
 61%|██████    | 61/100 [03:17<00:23,  1.65steps/s, loss=0.21540482]
 62%|██████▏   | 62/100 [03:17<00:21,  1.73steps/s, loss=0.21540482]
 62%|██████▏   | 62/100 [03:17<00:21,  1.73steps/s, loss=0.21540813]
 63%|██████▎   | 63/100 [03:18<00:20,  1.79steps/s, loss=0.21540813]
 63%|██████▎   | 63/100 [03:18<00:20,  1.79steps/s, loss=0.21540245]
 64%|██████▍   | 64/100 [03:18<00:19,  1.84steps/s, loss=0.21540245]
 64%|██████▍   | 64/100 [03:19<00:19,  1.84steps/s, loss=0.21545283]
 65%|██████▌   | 65/100 [03:19<00:18,  1.88steps/s, loss=0.21545283]
 65%|██████▌   | 65/100 [03:19<00:18,  1.88steps/s, loss=0.21514866]
 66%|██████▌   | 66/100 [03:19<00:17,  1.89steps/s, loss=0.21514866]
 66%|██████▌   | 66/100 [03:20<00:17,  1.89steps/s, loss=0.21512397]
 67%|██████▋   | 67/100 [03:20<00:19,  1.67steps/s, loss=0.21512397]
 67%|██████▋   | 67/100 [03:20<00:19,  1.67steps/s, loss=0.2151743]
 68%|██████▊   | 68/100 [03:21<00:18,  1.73steps/s, loss=0.2151743]
 68%|██████▊   | 68/100 [03:21<00:18,  1.73steps/s, loss=0.21527265]
 69%|██████▉   | 69/100 [03:21<00:17,  1.78steps/s, loss=0.21527265]
 69%|██████▉   | 69/100 [03:21<00:17,  1.78steps/s, loss=0.21522582]
 70%|███████   | 70/100 [03:22<00:16,  1.83steps/s, loss=0.21522582]
 70%|███████   | 70/100 [03:22<00:16,  1.83steps/s, loss=0.21515623]
 71%|███████   | 71/100 [03:22<00:15,  1.87steps/s, loss=0.21515623]
 71%|███████   | 71/100 [03:22<00:15,  1.87steps/s, loss=0.21518092]
 72%|███████▏  | 72/100 [03:23<00:14,  1.89steps/s, loss=0.21518092]
 72%|███████▏  | 72/100 [03:23<00:14,  1.89steps/s, loss=0.21521527]
 73%|███████▎  | 73/100 [03:23<00:14,  1.91steps/s, loss=0.21521527]
 73%|███████▎  | 73/100 [03:23<00:14,  1.91steps/s, loss=0.21533956]
 74%|███████▍  | 74/100 [03:24<00:13,  1.95steps/s, loss=0.21533956]
 74%|███████▍  | 74/100 [03:24<00:13,  1.95steps/s, loss=0.21533892]
 75%|███████▌  | 75/100 [03:24<00:12,  1.95steps/s, loss=0.21533892]
 75%|███████▌  | 75/100 [03:24<00:12,  1.95steps/s, loss=0.21525611]
 76%|███████▌  | 76/100 [03:25<00:14,  1.70steps/s, loss=0.21525611]
 76%|███████▌  | 76/100 [03:25<00:14,  1.70steps/s, loss=0.21511202]
 77%|███████▋  | 77/100 [03:26<00:13,  1.77steps/s, loss=0.21511202]
 77%|███████▋  | 77/100 [03:26<00:13,  1.77steps/s, loss=0.21496485]
 78%|███████▊  | 78/100 [03:26<00:12,  1.82steps/s, loss=0.21496485]
 78%|███████▊  | 78/100 [03:26<00:12,  1.82steps/s, loss=0.21500511]
 79%|███████▉  | 79/100 [03:27<00:11,  1.85steps/s, loss=0.21500511]
 79%|███████▉  | 79/100 [03:27<00:11,  1.85steps/s, loss=0.21505731]
 80%|████████  | 80/100 [03:27<00:10,  1.88steps/s, loss=0.21505731]
 80%|████████  | 80/100 [03:27<00:10,  1.88steps/s, loss=0.2150693]
 81%|████████  | 81/100 [03:28<00:09,  1.90steps/s, loss=0.2150693]
 81%|████████  | 81/100 [03:28<00:09,  1.90steps/s, loss=0.21503685]
 82%|████████▏ | 82/100 [03:28<00:09,  1.90steps/s, loss=0.21503685]
 82%|████████▏ | 82/100 [03:28<00:09,  1.90steps/s, loss=0.21496888]
 83%|████████▎ | 83/100 [03:29<00:08,  1.92steps/s, loss=0.21496888]
 83%|████████▎ | 83/100 [03:29<00:08,  1.92steps/s, loss=0.21489479]
 84%|████████▍ | 84/100 [03:29<00:08,  1.93steps/s, loss=0.21489479]
 84%|████████▍ | 84/100 [03:29<00:08,  1.93steps/s, loss=0.21493243]
 85%|████████▌ | 85/100 [03:30<00:07,  1.93steps/s, loss=0.21493243]
 85%|████████▌ | 85/100 [03:30<00:07,  1.93steps/s, loss=0.21491762]
 86%|████████▌ | 86/100 [03:30<00:08,  1.70steps/s, loss=0.21491762]
 86%|████████▌ | 86/100 [03:31<00:08,  1.70steps/s, loss=0.21490313]
 87%|████████▋ | 87/100 [03:31<00:07,  1.72steps/s, loss=0.21490313]
 87%|████████▋ | 87/100 [03:31<00:07,  1.72steps/s, loss=0.21478933]
 88%|████████▊ | 88/100 [03:32<00:06,  1.73steps/s, loss=0.21478933]
 88%|████████▊ | 88/100 [03:32<00:06,  1.73steps/s, loss=0.21460143]
 89%|████████▉ | 89/100 [03:32<00:06,  1.79steps/s, loss=0.21460143]
 89%|████████▉ | 89/100 [03:32<00:06,  1.79steps/s, loss=0.21445952]
 90%|█████████ | 90/100 [03:33<00:05,  1.84steps/s, loss=0.21445952]
 90%|█████████ | 90/100 [03:33<00:05,  1.84steps/s, loss=0.21441205]
 91%|█████████ | 91/100 [03:33<00:04,  1.88steps/s, loss=0.21441205]
 91%|█████████ | 91/100 [03:33<00:04,  1.88steps/s, loss=0.21441074]
 92%|█████████▏| 92/100 [03:34<00:04,  1.90steps/s, loss=0.21441074]
 92%|█████████▏| 92/100 [03:34<00:04,  1.90steps/s, loss=0.21450388]
 93%|█████████▎| 93/100 [03:34<00:03,  1.92steps/s, loss=0.21450388]
 93%|█████████▎| 93/100 [03:34<00:03,  1.92steps/s, loss=0.21448496]
 94%|█████████▍| 94/100 [03:35<00:03,  1.93steps/s, loss=0.21448496]
 94%|█████████▍| 94/100 [03:35<00:03,  1.93steps/s, loss=0.2144697]
 95%|█████████▌| 95/100 [03:35<00:02,  1.71steps/s, loss=0.2144697]
 95%|█████████▌| 95/100 [03:35<00:02,  1.71steps/s, loss=0.21444605]
 96%|█████████▌| 96/100 [03:36<00:02,  1.78steps/s, loss=0.21444605]
 96%|█████████▌| 96/100 [03:36<00:02,  1.78steps/s, loss=0.21442194]
 97%|█████████▋| 97/100 [03:36<00:01,  1.82steps/s, loss=0.21442194]
 97%|█████████▋| 97/100 [03:37<00:01,  1.82steps/s, loss=0.21435082]
 98%|█████████▊| 98/100 [03:37<00:01,  1.86steps/s, loss=0.21435082]
 98%|█████████▊| 98/100 [03:37<00:01,  1.86steps/s, loss=0.21430798]
 99%|█████████▉| 99/100 [03:37<00:00,  1.89steps/s, loss=0.21430798]
 99%|█████████▉| 99/100 [03:38<00:00,  1.89steps/s, loss=0.21428289]
100%|██████████| 100/100 [03:38<00:00,  1.90steps/s, loss=0.21428289]
100%|██████████| 100/100 [03:38<00:00,  2.18s/steps, loss=0.21428289]
example learn_samples

Trained trajectory#

model.eval()
recon = model(mri_3D)
plot_state(mri_3D, model.get_trajectory(True).detach().cpu().numpy(), recon, losses)
plt.show()
MR Image, Reconstruction, Loss, Trajectory

References#

[Proj]

N. Chauffert, P. Weiss, J. Kahn and P. Ciuciu, “A Projection Algorithm for Gradient Waveforms Design in Magnetic Resonance Imaging,” in IEEE Transactions on Medical Imaging, vol. 35, no. 9, pp. 2026-2039, Sept. 2016, doi: 10.1109/TMI.2016.2544251.

[Sparks]

G. R. Chaithya, P. Weiss, G. Daval-Frérot, A. Massire, A. Vignaud and P. Ciuciu, “Optimizing Full 3D SPARKLING Trajectories for High-Resolution Magnetic Resonance Imaging,” in IEEE Transactions on Medical Imaging, vol. 41, no. 8, pp. 2105-2117, Aug. 2022, doi: 10.1109/TMI.2022.3157269.

[Projector]

Chaithya GR, and Philippe Ciuciu. 2023. “Jointly Learning Non-Cartesian k-Space Trajectories and Reconstruction Networks for 2D and 3D MR Imaging through Projection” Bioengineering 10, no. 2: 158. https://doi.org/10.3390/bioengineering10020158

Total running time of the script: (3 minutes 46.967 seconds)

Gallery generated by Sphinx-Gallery