Cross-Site Generalization of CNN-Based $$ {B}_1^{+} $$ Mapping in UHF MRI.
The 2 matches
- [1] § Methods › MRI Data Acquisition and Data Processing ↔ Train_Complex_Model_Save_Model.ipynb, lines 40–122 · score 0.63 · imaginary parts, localizer images, Tx channels, split, magnitude, training
- [2] § Methods › MRI Data Acquisition and Data Processing ↔ Train_Complex_Model_Save_Model.ipynb, lines 603–744 · score 0.54 · trainable parameters, ADAM, epoch, batch, optimizer, validation
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Jupyter notebook · 762 lines · 24 KB · no license · 2 matches
- # %% [markdown]
- # # Packages
- # %%
- ! git clone https://github.com/soumickmj/pytorch-complex.git
- ! mv /content/pytorch-complex/* .
- !pip install torchinfo
- # %%
- # Import necessary libraries
- import os
- import time
- import numpy as np
- import matplotlib.pyplot as plt
- import h5py
- import torch
- import torch.optim as optim
- import torch.nn as nn
- import torch.nn.functional as F
- import torch.optim.lr_scheduler as lr_scheduler
- from torch.utils.data import Dataset, TensorDataset, random_split, SubsetRandomSampler, ConcatDataset, DataLoader
- from sklearn.model_selection import KFold, train_test_split
- from skimage.metrics import structural_similarity as ssim
- from torchinfo import summary
- # Import custom complex number support for PyTorch
- import torchcomplex
- from torchcomplex import nn
- # %%
- device = "cuda" # if torch.cuda.is_available() else "cpu"
- device = torch.device('cuda:0')
- # %%
- # %% [markdown]
- # # Data Import
- # %%
- def process_training_data(train_file_path):
- """
- Load training data from an HDF5 (.mat) file and convert
- real/imaginary channel pairs into complex-valued arrays.
- Parameters
- ----------
- train_file_path : str
- Path to the training HDF5 file.
- Returns
- -------
- x_ : np.ndarray
- Complex-valued localizer training data.
- y_ : np.ndarray
- Complex-valued input (target) training data.
- """
- # ------------------------------------------------------------
- # Load data
- # ------------------------------------------------------------
- with h5py.File(train_file_path, "r") as train_file:
- # "x" data (localizer)
- localizer_data_train = train_file["lvLovalizerSave"][:, :, :, :].astype(np.float32)
- # "y" data (input / target)
- input_data_train = train_file["lvSaveDataInput"][:, :, :, :].astype(np.float32)
- print("\nOriginal Shapes:")
- print("Training Input Data Shape:", input_data_train.shape)
- print("Training Localizer Data Shape:", localizer_data_train.shape)
- # ------------------------------------------------------------
- # Move channel axis: axis 2 -> last
- # ------------------------------------------------------------
- localizer_data_train = np.moveaxis(localizer_data_train, 2, -1)
- input_data_train = np.moveaxis(input_data_train, 2, -1)
- print("\nAfter Moving Axis:")
- print("Training Input Data Shape:", input_data_train.shape)
- print("Training Localizer Data Shape:", localizer_data_train.shape)
- # ------------------------------------------------------------
- # Remove magnitude channel (localizer with all Tx channels on)
- # ------------------------------------------------------------
- localizer_data_train = np.delete(localizer_data_train, 0, axis=1)
- print("\nAfter Deleting Magnitude Value:")
- print("Training Localizer Data Shape:", localizer_data_train.shape)
- # ------------------------------------------------------------
- # Split real / imaginary parts
- # ------------------------------------------------------------
- # Localizer
- localizer_real_train = localizer_data_train[:, ::2, :, :]
- localizer_imag_train = localizer_data_train[:, 1::2, :, :]
- # Input / target
- input_real_train = input_data_train[:, ::2, :, :]
- input_imag_train = input_data_train[:, 1::2, :, :]
- # ------------------------------------------------------------
- # Combine into complex-valued arrays
- # ------------------------------------------------------------
- x_ = localizer_real_train + 1j * localizer_imag_train
- y_ = input_real_train + 1j * input_imag_train
- print("\nComplex Training Data Shapes:")
- print("Complex Training Localizer Data Shape:", x_.shape)
- print("Complex Training Input Data Shape:", y_.shape)
- return x_, y_
- # ------------------------------------------------------------
- # Example usage
- # ------------------------------------------------------------
- train_file_path = "TrainingData.mat"
- x_, y_ = process_training_data(train_file_path)
- # %% [markdown]
- # %%
- def process_validation_data(val_file_path):
- """
- Load validation data from an HDF5 (.mat) file and convert
- real/imaginary channel pairs into complex-valued arrays.
- Parameters
- ----------
- val_file_path : str
- Path to the validation HDF5 file.
- Returns
- -------
- x_test_ : np.ndarray
- Complex-valued localizer validation data.
- y_test_ : np.ndarray
- Complex-valued input (target) validation data.
- """
- # ------------------------------------------------------------
- # Load data
- # ------------------------------------------------------------
- with h5py.File(val_file_path, "r") as val_file:
- # "x_test" data (localizer)
- localizer_data_val = val_file["lvLovalizerSave"][:, :, :]
- # "y_test" data (input / target)
- input_data_val = val_file["lvSaveDataInput"][:, :, :, :]
- print("\nOriginal Shapes:")
- print("Validation Input Data Shape:", input_data_val.shape)
- print("Validation Localizer Data Shape:", localizer_data_val.shape)
- # ------------------------------------------------------------
- # Move axes
- # ------------------------------------------------------------
- localizer_data_val = np.moveaxis(localizer_data_val, 2, -1)
- input_data_val = np.moveaxis(input_data_val, 2, -1)
- input_data_val = np.moveaxis(input_data_val, 1, -1)
- print("\nAfter Moving Axis:")
- print("Validation Input Data Shape:", input_data_val.shape)
- print("Validation Localizer Data Shape:", localizer_data_val.shape)
- # ------------------------------------------------------------
- # Remove magnitude channel (localizer with all Tx channels on)
- # ------------------------------------------------------------
- localizer_data_val = np.delete(localizer_data_val, 0, axis=1)
- print("\nAfter Deleting Magnitude Value:")
- print("Validation Localizer Data Shape:", localizer_data_val.shape)
- # ------------------------------------------------------------
- # Split real / imaginary parts
- # ------------------------------------------------------------
- # Localizer
- localizer_real_val = localizer_data_val[:, ::2, :, :]
- localizer_imag_val = localizer_data_val[:, 1::2, :, :]
- # Input / target
- input_real_val = input_data_val[:, ::2, :, :]
- input_imag_val = input_data_val[:, 1::2, :, :]
- # ------------------------------------------------------------
- # Combine into complex-valued arrays
- # ------------------------------------------------------------
- x_test_ = localizer_real_val + 1j * localizer_imag_val
- y_test_ = input_real_val + 1j * input_imag_val
- print("\nComplex Validation Data Shapes:")
- print("Complex Validation Localizer Data Shape:", x_test_.shape)
- print("Complex Validation Input Data Shape:", y_test_.shape)
- return x_test_, y_test_
- # ------------------------------------------------------------
- # Example usage
- # ------------------------------------------------------------
- val_file_path = ("ValidationData.mat")
- x_test_, y_test_ = process_validation_data(val_file_path)
- # %%
- # Convert to PyTorch tensor and move to device
- x_test_tensor = torch.from_numpy(x_test_).to(device)
- # %%
- # %% [markdown]
- # # Custom Functions
- # %%
- def size_of(x):
- print(x.numel()*x.element_size()/1024/1024)
- def count(net):
- return sum(p.numel() for p in net.parameters())
- # %%
- ###---###---###---###
- ''' Initial weights '''
- ###---###---###---###
- def _init_weights(module):
- if isinstance(module, torchcomplex.nn.Conv2d):
- module.weight.data.normal_(mean=0.0, std=0.02)
- # %% [markdown]
- # # Loss Function
- # %%
- ###---###---###---###
- """ Loss Function """
- ###---###---###---###
- class ComplexMSELoss:
- def __call__(self, true, prediction):
- # Convert NumPy arrays to PyTorch tensors of complex64 type right at the beginning
- true_tensor = torch.tensor(true, dtype=torch.complex64)
- prediction_tensor = torch.tensor(prediction, dtype=torch.complex64)
- # Perform the MSE computation
- return (0.5 * (true_tensor - prediction_tensor) ** 2).mean()
- class PerpLoss(nn.Module):
- def __init__(self, eps=1e-8, l1factor=1.0, mask=False):
- super(PerpLoss, self).__init__()
- self.eps = eps
- self.l1factor = l1factor
- self.mask = mask
- def forward(self, target, prediction):
- # Calculate the cross term as the absolute value of the determinant of the complex numbers
- cross = torch.abs(target.real * prediction.imag - target.imag * prediction.real)
- # Calculate the perpendicular loss component
- ploss_raw = cross / (torch.abs(prediction) + self.eps)
- # Corrected: Ensure the mask is a boolean tensor
- # Here, it's assumed that you want to mask based on the condition that involves 'target'
- # Adjust the condition according to your specific requirements
- mask = target.abs() > 1e-3 # This now produces a boolean tensor
- angle_smaller_90 = ((target / prediction).real > 0).detach() # is the angle < pi/2 ?
- # Calculate the final loss with the conditional mask applied
- # torch.where now receives a boolean tensor as expected
- ploss = torch.where(angle_smaller_90, ploss_raw, 2 * torch.abs(target) - ploss_raw)
- l1loss = torch.nn.functional.l1_loss(prediction, target, reduction='none')
- loss = ploss + self.l1factor * l1loss
- if self.mask:
- loss = (loss * mask).sum() / (mask.sum() + self.eps) # Returning the maksed mean loss over all elements
- else:
- loss = loss.mean() # return the mean over all elements
- return loss
- # %% [markdown]
- # # 2D Convolutional Block
- # %%
- ###---###---###---###
- """ 2D Convolutional Block """
- ###---###---###---###
- class C2D_Block(nn.Module):
- def __init__(self, in_c, n_filters, batchnorm, skip):
- super().__init__()
- self.conv1 = torchcomplex.nn.Conv2d(in_c, n_filters, kernel_size=3, padding=1)
- if batchnorm:
- self.bn1 = torchcomplex.nn.BatchNorm2d(n_filters)
- self.bn2 = torchcomplex.nn.BatchNorm2d(n_filters)
- else:
- self.bn1 = None
- self.bn2 = None
- # self.relu1 = torchcomplex.nn.CReLU() - do not use CReLU here, look up in docs
- self.relu1 = torchcomplex.nn.AdaptiveCmodReLU(n_filters)
- self.conv2 = torchcomplex.nn.Conv2d(n_filters, n_filters, kernel_size=3, padding=1)
- # self.relu2 = torchcomplex.nn.CReLU() - do not use CReLU here, look up in docs
- self.relu2 = torchcomplex.nn.AdaptiveCmodReLU(n_filters)
- if skip:
- self.skip = torchcomplex.nn.Conv2d(in_c, n_filters, kernel_size=1)
- with torch.no_grad():
- self.skip.bias.zero_()
- else:
- self.skip = None
- def forward(self, xin):
- x = self.conv1(xin)
- if self.bn1:
- x = self.bn1(x)
- x = self.relu1(x)
- x = self.conv2(x)
- if self.bn2:
- x = self.bn2(x)
- if self.skip:
- x = x + self.skip(xin)
- x = self.relu2(x)
- return x
- # %% [markdown]
- # # Encoder
- # %%
- ###---###---###---###
- """ Encoder """
- ###---###---###---###
- class Encoder(nn.Module):
- def __init__(self, in_c, dropout, features, maxpool, batchnorm, skip):
- super().__init__()
- self.encBlocks = nn.ModuleList()
- self.downsamples = nn.ModuleList()
- for feature in features:
- self.encBlocks.append(C2D_Block(in_c, feature, batchnorm=batchnorm, skip=skip))
- if maxpool:
- self.downsamples.append(torchcomplex.nn.MaxPool2d(2))
- in_c = feature
- else:
- down = torch.nn.Sequential(
- torchcomplex.nn.Conv2d(feature, features[-1], kernel_size=3, stride=2, padding=1), torchcomplex.nn.AdaptiveCmodReLU(features[-1])
- )
- self.downsamples.append(down)
- in_c = features[-1]
- self.dropouts = torchcomplex.nn.Dropout2d(dropout) if dropout else torch.nn.Identity()
- self.dropout2 = torchcomplex.nn.Dropout2d(dropout * 2) if dropout else torch.nn.Identity()
- self.dropout3 = torchcomplex.nn.Dropout2d(dropout * 3) if dropout else torch.nn.Identity()
- # self.bottleneck = C2D_Block(features[-1], features[-1]*2)
- self.bottleneck = torch.nn.Sequential(
- torchcomplex.nn.Conv2d(features[-1], features[-1], kernel_size=3, padding=1), torchcomplex.nn.AdaptiveCmodReLU( features[-1])
- )
- def forward(self, x):
- skip_connections = []
- # downsampling
- for depth, (block, down) in enumerate(zip(self.encBlocks, self.downsamples)):
- x = block(x)
- skip_connections.append(x)
- x = down(x)
- if depth < 2:
- x = self.dropout1(x)
- else:
- x = self.dropout2(x)
- x = self.bottleneck(x)
- x = self.dropout3(x)
- return x, skip_connections
- # %% [markdown]
- # # Decoder
- # %%
- ###---###---###---###
- """ Decoder """
- ###---###---###---###
- class Decoder(nn.Module):
- def __init__(self, dropout, features, upsample, batchnorm, skip):
- super().__init__()
- features_out = list(reversed(features))
- features_in = [features[-1], *features[:0:-1]]
- self.upConvs = nn.ModuleList()
- self.decBlocks = nn.ModuleList()
- for fin, fout in zip(features_in, features_out):
- if upsample:
- self.upConvs.append(
- torch.nn.Sequential(
- torchcomplex.nn.Upsample(mode="bilinear", scale_factor=2, size=None),
- torchcomplex.nn.Conv2d(fin, fout, kernel_size=3, padding=1),
- torchcomplex.nn.AdaptiveCmodReLU(fout),
- )
- )
- else:
- self.upConvs.append(
- torch.nn.Sequential(
- torchcomplex.nn.ConvTranspose2d(fin, fout, 2, stride=2),
- torchcomplex.nn.AdaptiveCmodReLU(fout),
- )
- )
- self.decBlocks.append(C2D_Block(2 * fout, fout, batchnorm=batchnorm, skip=skip))
- # with torch.no_grad():
- # self.upConvs.apply(_init_weights)
- self.dropout1 = torchcomplex.nn.Dropout2d(dropout) if dropout else torch.nn.Identity()
- self.dropout2 = torchcomplex.nn.Dropout2d(dropout * 2) if dropout else torch.nn.Identity()
- def forward(self, x, skipped_feautures):
- for depth, (up, block, skipped) in enumerate(zip(self.upConvs, self.decBlocks, skipped_feautures, strict=True)):
- x = up(x)
- x = torch.cat([x, skipped], dim=1)
- x = block(x)
- if depth < 2:
- x = self.dropout2(x)
- else:
- x = self.dropout1(x)
- return x
- def crop(self, encFeaturs, x):
- (_, _, H, W) = x.shape
- encFeaturs = CenterCrop([H, W])(encFeaturs)
- return encFeaturs
- # %%
- class Head(nn.Module):
- def __init__(self, features_in, features_out=1, features_hidden=(64,32,16)):
- super().__init__()
- modules = []
- fin = features_in
- for fout in features_hidden:
- modules.append(torchcomplex.nn.Conv2d(fin,fout, 3, padding=1))
- modules.append(torchcomplex.nn.AdaptiveCmodReLU(fout))
- fin = fout
- modules.append(torchcomplex.nn.Conv2d(fin, features_out, 3, padding=1))
- self.net = torch.nn.Sequential(*modules)
- with torch.no_grad():
- self.net[-1].bias.zero_()
- def forward(self,x):
- return self.net(x)
- # %% [markdown]
- # # UNet
- # %%
- ###---###---###---###
- """ UNet """
- ###---###---###---###
- class UNet(nn.Module):
- def __init__(self, in_c, out_c, dropout, features, maxpool=True, upsample=False, batchnorm=False, skip=True):
- super().__init__()
- self.encoder = Encoder(in_c, dropout, features, maxpool=maxpool, batchnorm=batchnorm, skip=skip)
- self.decoder1 = Decoder(dropout, features, upsample=upsample, batchnorm=batchnorm, skip=skip)
- self.decoder2 = Decoder(dropout, features ,upsample=upsample, batchnorm=batchnorm, skip=skip)
- self.decoder3 = Decoder(dropout, features ,upsample=upsample, batchnorm=batchnorm, skip=skip)
- self.decoder4 = Decoder(dropout, features ,upsample=upsample, batchnorm=batchnorm, skip=skip)
- self.decoder5 = Decoder(dropout, features ,upsample=upsample, batchnorm=batchnorm, skip=skip)
- self.decoder6 = Decoder(dropout, features ,upsample=upsample, batchnorm=batchnorm, skip=skip)
- self.decoder7 = Decoder(dropout, features ,upsample=upsample, batchnorm=batchnorm, skip=skip)
- self.decoder8 = Decoder(dropout, features ,upsample=upsample, batchnorm=batchnorm, skip=skip)
- self.head1 = Head(features[0], out_c)
- self.head2 = Head(features[0], out_c)
- self.head3 = Head(features[0], out_c)
- self.head4 = Head(features[0], out_c)
- self.head5 = Head(features[0], out_c)
- self.head6 = Head(features[0], out_c)
- self.head7 = Head(features[0], out_c)
- self.head8 = Head(features[0], out_c)
- def forward(self, x):
- x, encFeatures = self.encoder(x)
- decFeatures1 = self.decoder1(x, encFeatures[::-1])
- output1 = self.head1(decFeatures1)
- decFeatures2 = self.decoder2(x, encFeatures[::-1])
- output2 = self.head2(decFeatures2)
- decFeatures3 = self.decoder3(x, encFeatures[::-1])
- output3 = self.head3(decFeatures3)
- decFeatures4 = self.decoder4(x, encFeatures[::-1])
- output4 = self.head4(decFeatures4)
- decFeatures5 = self.decoder5(x, encFeatures[::-1])
- output5 = self.head5(decFeatures5)
- decFeatures6 = self.decoder6(x, encFeatures[::-1])
- output6 = self.head6(decFeatures6)
- decFeatures7 = self.decoder7(x, encFeatures[::-1])
- output7 = self.head7(decFeatures7)
- decFeatures8 = self.decoder8(x, encFeatures[::-1])
- output8 = self.head8(decFeatures8)
- return output1, output2, output3, output4, output5, output6, output7, output8
- # %%
- # %% [markdown]
- # # Data preparation
- # %%
- # ============================================================
- # Data preparation
- # ============================================================
- # Convert input data to PyTorch tensor
- x_tensor = torch.from_numpy(x_)
- # Select first 8 channels from target data
- y_tensor = torch.tensor(y_[:, 0:8, :, :])
- # Create TensorDataset:
- # x_tensor : input
- # y_tensor split : one tensor per Tx channel
- data = TensorDataset(
- x_tensor,
- *y_tensor.unsqueeze(2).unbind(1)
- )
- # Split into training and validation sets (80 / 20)
- train_dataset, val_dataset = random_split(
- data,
- [0.8, 0.2]
- )
- # Concatenate back if a unified dataset is required
- dataset = ConcatDataset([train_dataset, val_dataset])
- # %% [markdown]
- # # Hyperparameters
- # %%
- # ============================================================
- # Hyperparameters
- # ============================================================
- # Add light Gaussian noise to input images in a fraction of cases
- params = dict(
- lr=1e-4, # lower LR for long, stable training
- gamma=0.9985, # very slow exponential decay over 4000 epochs
- batch_size=1,
- dropout=0.005, # slightly higher to counter long training
- num_epochs=4000,
- weight_decay=0.05, # regularization to prevent overfitting
- features=(32, 32, 64, 128, 256),
- maxpool=True,
- batchnorm=False,
- skip=True,
- upsample=True,
- clip_grad_norm=1.0, # safety for long runs
- )
- # ------------------------------------------------------------
- # Loss function
- # ------------------------------------------------------------
- criterion = lambda gt, pred: torch.nn.functional.mse_loss(
- torch.view_as_real(gt),
- torch.view_as_real(pred),
- )
- # %% [markdown]
- # # Train Model
- # %%
- # ============================================================
- # Reproducibility
- # ============================================================
- torch.manual_seed(42)
- # ============================================================
- # Model
- # ============================================================
- model = UNet(
- in_c=32,
- out_c=1,
- dropout=params["dropout"],
- features=params["features"],
- maxpool=params["maxpool"],
- skip=params["skip"],
- batchnorm=params["batchnorm"],
- upsample=params["upsample"],
- ).to(device)
- n_params = sum(p.numel() for p in model.parameters())
- print(f"{n_params / 1e6:.2f} Mio.")
- print("number_trainable_parameters =", n_params)
- print(model)
- # If criterion is a callable/loss instance, this is just informational
- try:
- print("criterion =", criterion.__class__.__name__)
- except Exception:
- pass
- # ============================================================
- # Train/val split (via samplers)
- # ============================================================
- train_loss = []
- valid_loss = []
- start_time = time.time()
- train_idx, val_idx = torch.utils.data.random_split(
- torch.arange(len(dataset)),
- (0.9, 0.1),
- )
- train_loader = DataLoader(
- dataset,
- batch_size=params["batch_size"],
- sampler=SubsetRandomSampler(train_idx),
- num_workers=10,
- )
- val_loader = DataLoader(
- dataset,
- batch_size=params["batch_size"],
- sampler=SubsetRandomSampler(val_idx),
- num_workers=10,
- )
- # ============================================================
- # Optimizer + scheduler
- # ============================================================
- optimizer = optim.AdamW(
- model.parameters(),
- lr=params["lr"],
- weight_decay=params["weight_decay"],
- )
- scheduler = lr_scheduler.ExponentialLR(
- optimizer,
- gamma=params["gamma"],
- )
- # ============================================================
- # Training loop
- # ============================================================
- for epoch in range(params["num_epochs"]):
- epoch_start = time.time()
- # ------------------------
- # Train
- # ------------------------
- model.train()
- train_epoch_loss = 0.0
- for step, (x, *y) in enumerate(train_loader):
- x = x.to(device)
- y = [yi.to(device) for yi in y]
- optimizer.zero_grad()
- outputs = model(x) # expected: iterable/list of heads
- head_losses = [criterion(out_i, y_i) for out_i, y_i in zip(outputs, y)]
- loss = sum(head_losses) / len(head_losses)
- loss.backward()
- torch.nn.utils.clip_grad_norm_(model.parameters(), params["clip_grad_norm"])
- optimizer.step()
- train_epoch_loss += loss.item()
- avg_train_loss = train_epoch_loss / len(train_loader)
- train_loss.append(avg_train_loss)
- # LR step (printed explicitly)
- lr_before = optimizer.param_groups[0]["lr"]
- scheduler.step()
- lr_after = optimizer.param_groups[0]["lr"]
- print("\n" + "-" * 60)
- print(f"Epoch {epoch + 1:4d}/{params['num_epochs']} | train_loss: {avg_train_loss:.6f}")
- print(f"lr: {lr_before:.6e} -> {lr_after:.6e}")
- # ------------------------
- # Validation
- # ------------------------
- model.eval()
- val_epoch_loss = 0.0
- with torch.no_grad():
- for x, *y in val_loader:
- x = x.to(device)
- y = [yi.to(device) for yi in y]
- outputs = model(x)
- head_losses = [criterion(out_i, y_i) for out_i, y_i in zip(outputs, y)]
- val_loss = sum(head_losses) / len(head_losses)
- val_epoch_loss += val_loss.item()
- avg_val_loss = val_epoch_loss / len(val_loader)
- valid_loss.append(avg_val_loss)
- epoch_time = time.time() - epoch_start
- print(f"val_loss: {avg_val_loss:.6f} | epoch_time: {epoch_time:.2f}s")
- # ============================================================
- # Done
- # ============================================================
- total_time = time.time() - start_time
- print(f"\n[INFO] total time taken to train the model: {total_time:.2f}s")
- # %% [markdown]
- # # Save Model
- # %%
- torch.save(
- {
- "epochs": epoch,
- "parameters": params,
- "model_state_dict": model.state_dict(),
- "optimizer_state_dict": optimizer.state_dict(),
- "train_loss": train_loss[-1],
- "validation_loss": valid_loss[-1],
- },
- 'SaveModel.pth',
- )
Train_Complex_Model_Save_Model.ipynb at commit 7d80d96, no license · at the source
Overview
- Physikalisch‐Technische Bundesanstalt Berlin Germany
- Medical Physics in Radiology German Cancer Research Center (DKFZ) Heidelberg Germany
- Faculty of Physics and Astronomy Heidelberg University Heidelberg Germany
- Center for Magnetic Resonance Research University of Minnesota Minneapolis Minnesota USA
- Institute for Applied Medical Informatics University Medical Center Hamburg‐Eppendorf (UKE) Hamburg Germany
- Max Planck Research Group MR Physics, Max Planck Institute for Human Development Berlin Germany
Abstract
Convolutional neural networks (CNNs) can rapidly predict channel‐wise B1+ maps from 7T localizer images, reducing acquisition time to seconds. This paper investigates if a CNN trained on one site's data can generalize to predict B1+ maps for brain imaging at unseen sites supporting the feasibility of a universal network for subject‐specific B1+‐ mapping. We evaluated a U‐Net CNN cross‐site generalization by training on datasets from two different 7T sites and testing its performance across three 7T sites (1 additional testing site) to assess robustness, adaptability, and generalization. The study design included both commercially same systems and the identical physical hardware unit transported between two sites, enabling a more insightful attribution of performance differences to either hardware issues or dataset‐specific variations.
To assess prediction quality, we examined magnitude/
While on‐site B1+ transversal magnitude RMSE scores were as low as 3.0% and 3.1% for the two CNNs, their respective transfer yielded 3.6% and 4.1%. The dynamic pTx‐application showed a CV of 6.5% when using B1+ maps predicted by a network trained on its own site. The transfer case, using a map predicted from a network trained on a different site, yielded an increased CV of 13.7%.
Although cross‐site applications introduced larger deviations, the predicted maps remained qualitatively plausible and enabled practical use cases, such as calculating dynamic‐pTx. These findings support the potential of cross‐site training, suggesting CNNs trained at one site may generalize sufficiently to unseen sites without additional adjustments. This strengthens the feasibility of a transferable training approach where a single network could be deployed across different institutions without extensive retraining.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 2 matches between paragraphs and lines of code.
hkimon/B1P_Mapping_CCN
7d80d9675182f215bbe3e8c16080c05cbc002a27, 23 January 2026Availability: 1 check, the latest on 28 September 2026: the link answers
- 28 September 2026: the link answers
5 files
- Load_Complex_Model_Save_
Model.ipynb , Jupyter, 654 lines - Load_Model_Test_Mulitple
Models.ipynb , Jupyter, 529 lines - Train_Complex_Model_Save
_Model.ipynb , Jupyter, 762 lines, 2 matches - Train_Model_Save_Model.i
pynb , Jupyter, 503 lines - Train_Model_Save_Model_2
p5D.ipynb , Jupyter, 600 lines
The paper's code and data availability statement is in the Data section.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 5 scripts, each with its path and the digest of its content;
- 2 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
- zenodo:18338273, at Zenodo; found in “Data Availability Statement”
Data Availability Statement
The data supporting the findings of this study are openly available in Zenodo at https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 2, 28 September 2026
- Publisher: n/a → Wiley
Version 1, 28 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 14 authors, 7 keywords, 5 MeSH terms, 1 funder, 43 references.
Cite
This paper
Hadjikiriakos, K., Krüger, F., Zimmermann, F. F., Grimm, J. A., Schorling, C., Lutz, M., Schmidt, S., Riemann, L. T., Degenhardt, K., Schäffter, T., Ladd, M. E., Metzger, G. J., Aigner, C. S., & Schmitter, S. (2026). Cross-Site Generalization of CNN-Based $$ {B}_1^{+} $$ Mapping in UHF MRI. NMR in biomedicine, 39(5), e70263. https://
BibTeX
@article{hadjikiriakos20
author = {Hadjikiriakos, Kimon and Krüger, Felix and Zimmermann, Felix Frederik and Grimm, Johannes A. and Schorling, Constantin and Lutz, Max and Schmidt, Simon and Riemann, Layla Tabea and Degenhardt, Katja and Schäffter, Tobias and Ladd, Mark E. and Metzger, Gregory J. and Aigner, Christoph Stefan and Schmitter, Sebastian},
title = {{Cross-Site Generalization of CNN-Based \$\$ \{B\}\_1\textasciicircum
journal = {NMR in biomedicine},
year = {2026},
month = may,
volume = {39},
number = {5},
pages = {e70263},
publisher = {Wiley},
issn = {0952-3480},
doi = {10.1002/
url = {https://
pmid = {41937594},
pmcid = {PMC13051333}
}
RIS
TY - JOUR
AU - Hadjikiriakos, Kimon
AU - Krüger, Felix
AU - Zimmermann, Felix Frederik
AU - Grimm, Johannes A.
AU - Schorling, Constantin
AU - Lutz, Max
AU - Schmidt, Simon
AU - Riemann, Layla Tabea
AU - Degenhardt, Katja
AU - Schäffter, Tobias
AU - Ladd, Mark E.
AU - Metzger, Gregory J.
AU - Aigner, Christoph Stefan
AU - Schmitter, Sebastian
TI - Cross-Site Generalization of CNN-Based $$ {B}_1^{+} $$ Mapping in UHF MRI
T2 - NMR in biomedicine
J2 - NMR Biomed
PY - 2026
DA - 2026/
VL - 39
IS - 5
SP - e70263
SN - 0952-3480
PB - Wiley
DO - 10.1002/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1002/
"type": "article-journal",
"title": "Cross-Site Generalization of CNN-Based $$ {B}_1^{+} $$ Mapping in UHF MRI",
"container-title": "NMR in biomedicine",
"author": [
{
"family": "Hadjikiriakos",
"given": "Kimon"
},
{
"family": "Krüger",
"given": "Felix"
},
{
"family": "Zimmermann",
"given": "Felix Frederik"
},
{
"family": "Grimm",
"given": "Johannes A."
},
{
"family": "Schorling",
"given": "Constantin"
},
{
"family": "Lutz",
"given": "Max"
},
{
"family": "Schmidt",
"given": "Simon"
},
{
"family": "Riemann",
"given": "Layla Tabea"
},
{
"family": "Degenhardt",
"given": "Katja"
},
{
"family": "Schäffter",
"given": "Tobias"
},
{
"family": "Ladd",
"given": "Mark E."
},
{
"family": "Metzger",
"given": "Gregory J."
},
{
"family": "Aigner",
"given": "Christoph Stefan"
},
{
"family": "Schmitter",
"given": "Sebastian"
}
],
"container-title-short":
"volume": "39",
"issue": "5",
"page": "e70263",
"DOI": "10.1002/
"PMID": "41937594",
"PMCID": "PMC13051333",
"ISSN": "0952-3480",
"publisher": "Wiley",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
5,
1
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1002/mrm.70431 [code]
- SelExNet: A Self-Supervised Physics-Informed Framework for Multi-Channel Joint RF and Gradient Waveform Optimization in 2D Spatially Selective Excitation.Journal: Magnetic resonance in medicineIn common: PyTorch, SciPy, Matplotlib, 1 other tool, structural MRI / diffusion, 5 references
- [2] doi:10.1162/imag.a.1362 [code]
- Human fMRI at 11.7T: Assessing feasibility, stability, and reliability on the Iseult scanner.Journal: Imaging neuroscience (Cambridge, Mass.)In common: h5py, pandas, SciPy, 2 other tools, methods / tools, 4 references
- [3] doi:10.1093/nar/gkag706 [code]
- scDifformer: diffusion-based post-training for virtual cell modeling across large-scale single-cell data.Journal: Nucleic acids researchIn common: Keras, TensorFlow, scikit-image, 7 other tools
- [4] doi:10.1162/imag.a.1183 [code]
- Learning-based segmentation of diffusion-weighted MR images with arbitrary &
lt;i& gt;q& lt;/ i& gt;-space samplings. Journal: Imaging neuroscience (Cambridge, Mass.)In common: Keras, TensorFlow, scikit-image, 6 other tools, methods / tools, structural MRI / diffusion - [5] doi:10.1364/boe.605322 [code]
- Generalized plaque digitization framework for multi-dimensional mesoscopic images.Journal: Biomedical optics expressIn common: Keras, TensorFlow, scikit-image, 7 other tools
- [6] doi:10.3389/fnsys.2026.1822122 [code]
- Convergence-divergence circuits for multimodal integration of innate and learned opponent valences.Journal: Frontiers in systems neuroscienceIn common: Keras, TensorFlow, scikit-image, 7 other tools
- [7] doi:10.1038/s41467-026-72057-9 [code]
- Sex-specific behavioral feedback modulates sensorimotor processing and drives flexible social behavior.Journal: Nature communicationsIn common: Keras, TensorFlow, scikit-image, 7 other tools
- [8] doi:10.1080/07853890.2026.2685416 [code]
- Pulmonary and cerebral damage in COVID-19 survivors: is there any association?Journal: Annals of medicineIn common: Keras, TensorFlow, scikit-image, 6 other tools, structural MRI / diffusion
- [9] doi:10.1038/s41592-026-03057-2 [code]
- CREsted: modeling genomic and synthetic cell-type-specific enhancers across tissues and species.Journal: Nature methodsIn common: Keras, TensorFlow, h5py, 6 other tools, methods / tools
- [10] doi:10.1038/s41597-025-05174-7 [code]
- A large-scale MEG and EEG dataset for object recognition in naturalistic scenesJournal: n/aIn common: Keras, TensorFlow, h5py, 6 other tools, methods / tools
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 5 scripts, and 2 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:1e889d43b38d0836…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
