OSCR

PANDA: Patch-based unsupervised deep learning for brain anomaly detection via age prediction in fetal MRI.

Code ↔ Paper

2 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 2 matches
  1. [1] § Materials and Methods › Training details ↔ train.py, lines 72–130 · score 0.69 · weight decay, epochs, GPU, checkpoint, optimizer, Loss
  2. [2] § Materials and Methods › Training details ↔ train.py, lines 72–130 · score 0.59 · weight decay, GPU, optimizer, loss, training, batch

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

Python · 130 lines · 4.9 KB · MIT · 2 matches

  1. from sfcn import SFCN
  2. from monai.networks.nets import ResNet, ResNetBottleneck
  3. import torch
  4. from fdataset import FetalBrainDataset
  5. from pathlib import Path
  6. import random
  7. import warnings
  8. import torch.nn as nn
  9. from math import sqrt
  10. from torch.nn import functional as F
  11. import numpy as np
  12. import os
  13. from torch.utils.data import Dataset, Subset
  14. import nibabel as nib
  15. from matplotlib import pyplot as plt
  16. from datetime import datetime
  17. from tqdm import tqdm
  18. import pandas as pd
  19. def create_id_to_age_lookup(file_path, id_column='ID', age_column='Age'):
  20. df = pd.read_excel(file_path, engine='openpyxl')
  21. id_age_dict = df.set_index(id_column)[age_column].to_dict()
  22. result_dict = {}
  23. for id_key, age_value in id_age_dict.items():
  24. input_str = str(age_value)
  25. if "+" in input_str:
  26. parts = input_str.split("+")
  27. result = int(parts[0]) * 7 + int(parts[1])
  28. else:
  29. result = int(input_str) * 7
  30. result_dict[id_key] = result
  31. return result_dict
  32. file = '/path/to/age'
  33. id_age_map = create_id_to_age_lookup(file)
  34. def loss_f2(age, recon_age):
  35. return torch.abs(age - recon_age).mean()
  36. def train(model, train_loader, optimizer, device):
  37. model.train()
  38. total_loss = 0
  39. for batch in train_loader:
  40. brain, filenames = batch
  41. brain = brain.to(device)
  42. optimizer.zero_grad()
  43. ages = [id_age_map.get(fname.split('_')[0], float('nan')) for fname in filenames]
  44. age = torch.tensor(ages, dtype=torch.float32).to(device)
  45. predicted_age = model(brain)[0].squeeze()
  46. loss = loss_f2(age, predicted_age)
  47. loss.backward()
  48. optimizer.step()
  49. total_loss += loss.item()
  50. len_loss = len(train_loader)
  51. return total_loss / len_loss
  52. def val(model, val_loader, device):
  53. model.eval()
  54. total_loss = 0
  55. with torch.no_grad():
  56. for batch in val_loader:
  57. brain, filenames = batch
  58. brain = brain.to(device)
  59. ages = [id_age_map.get('fb' + fname.split('_')[0], float('nan')) for fname in filenames]
  60. age = torch.tensor(ages, dtype=torch.float32).to(device)
  61. predicted_age = model(brain)[0].squeeze()
  62. loss = loss_f2(age, predicted_age)
  63. total_loss += loss.item()
  64. len_loss = len(val_loader)
  65. return total_loss / len_loss
  66. if __name__ == "__main__":
  67. gpu_index = 0
  68. device = torch.device(f'cuda:{gpu_index}')
  69. model = SFCN(select_patch=True).to(device)
  70. lr = 0.0001
  71. max_epochs = 1000
  72. optimizer = torch.optim.Adam(model.parameters(), lr=lr, amsgrad=True, weight_decay=0.00001)
  73. train_datapath = "/data/birth/lmx/work/Class_projects/course5/work/fetal/Data/new_age_data/train"
  74. train_dataset = FetalBrainDataset(train_datapath, split = 'test')
  75. print(f"Original train_dataset size: {len(train_dataset)}")
  76. train_dataloader = torch.utils.data.DataLoader(train_dataset,batch_size=32,shuffle=True,drop_last=True,num_workers=6)
  77. val_datapath = "/data/birth/lmx/work/Class_projects/course5/work/fetal/Data/new_age_data/val"
  78. val_dataset = FetalBrainDataset(val_datapath, split = 'test')
  79. print(f"Original val_dataset size: {len(val_dataset)}")
  80. val_dataloader = torch.utils.data.DataLoader(val_dataset,batch_size=32,shuffle=False,drop_last=True,num_workers=6)
  81. progress_bar = tqdm(range(1, max_epochs + 1), desc="Training Progress")
  82. train_losses = []
  83. val_losses = []
  84. best_val_loss = float('inf')
  85. for epoch in progress_bar:
  86. train_loss = train(model, train_dataloader, optimizer, device)
  87. train_losses.append(train_loss)
  88. val_loss = val(model, val_dataloader, device)
  89. val_losses.append(val_loss)
  90. print(f"Epoch [{epoch}/{1000}]")
  91. print(f"Loss : Train: {train_loss:.8f}, Val: {val_loss:.8f}")
  92. output_folder = "/your/output/folder"
  93. if val_loss < best_val_loss:
  94. best_val_loss = val_loss
  95. checkpoint_path = os.path.join('/your/output/folder', 'best_model.pt')
  96. os.makedirs(os.path.dirname(checkpoint_path), exist_ok=True)
  97. torch.save({
  98. 'epoch': epoch,
  99. 'model_state_dict': model.state_dict(),
  100. 'optimizer_state_dict': optimizer.state_dict(),
  101. 'best_val_loss': best_val_loss}, checkpoint_path)
  102. if epoch % 25 == 0:
  103. current_time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
  104. epochs = range(4, len(train_losses) + 1)
  105. plt.figure(figsize=(10, 5))
  106. plt.plot(epochs, train_losses[3:], color='green', label='Train Loss Age')
  107. plt.plot(epochs, val_losses[3:], color='orange', label='Val Loss Age')
  108. plt.title('Age Loss')
  109. plt.xlabel('Epoch')
  110. plt.ylabel('Loss')
  111. plt.legend()
  112. plt.grid(True)
  113. plt.tight_layout()
  114. age_loss_path = os.path.join(output_folder, f"age_loss_{current_time}.png")
  115. plt.savefig(age_loss_path, bbox_inches='tight', pad_inches=0)
  116. plt.close()

train.py at commit 84b13d6, under MIT · at the source

Overview

Authors: Yingqi Hao1,2, Mingxuan Liu2, Juncheng Zhu1,3,4, Hongjia Yang2, Haoxiang Li2, Min Kang5, Yan Song5, Hua Lai6, Xiaoling Zhou6, Gang Ning1,3, Yi Liao1,3, Haibo Qu1,3, Qiyuan Tian2
  1. Department of Radiology, West China Second University Hospital, Sichuan University, Chengdu, Sichuan Province, China
  2. School of Biomedical Engineering, Tsinghua Medicine, Tsinghua University, Beijing, China
  3. Key Laboratory of Birth Defects and Related Diseases of Women and Children, Ministry of Education, Chengdu, Sichuan Province, China
  4. Department of Radiology, Chengdu Seventh People’s Hospital (Affiliated Cancer Hospital of Chengdu Medical College), Chengdu, China
  5. Department of Radiology, Sichuan Provincial Women’s and Children’s Hospital, The Affiliated Women’s and Children’s Hospital of Chengdu Medical College, Chengdu, China
  6. Chengdu Women’s and Children’s Central Hospital, School of Medicine, University of Electronic Science and Technology of China, Chengdu, China
Journal: Imaging neuroscience (Cambridge, Mass.), volume 4, article IMAG.a.1293
Dates: received 13 January 2026; accepted 8 June 2026; published online 13 July 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1162/imag.a.1293 · PMID 42453641 · PMCID PMC13366612 · OpenAlex W7165013479
Open access: diamond, a free copy (OpenAlex)
Status: code verified
Categories: structural MRI / diffusion (modality), developmental (subfield)
Methods: Connectivity, Statistics, Machine learning
Keywords: age difference, anomaly localization, ventriculomegaly, germinal matrix-intraventricular hemorrhage, subependymal cyst
Topic: Fetal and Pediatric Neurological Disorders (Pediatrics, Perinatology and Child Health, Medicine), according to OpenAlex
Funding: National Natural Science Foundation of China (82572198); Scientific Research Project of Sichuan Medical Association (2024HR130); Science and Technology Department of Sichuan Province (2025ZNSFSC1768); Science and Technology Department of Sichuan Province (25SYSX0255); Tsinghua University Startup Fund; Tsinghua University Dushi Program (20241080026, 20251080056)
Citations: not cited yet (Europe PMC); 50 references in the paper

Abstract

Fetal brains frequently exhibit anomalies arising from a broad spectrum of etiologies, such as genetic, infectious, hemorrhagic, or hypoxic-ischemic insults, many of which are associated with serious clinical morbidities. Unsupervised anomaly detection, which learns exclusively from normal cases to identify significant deviations from normative patterns without prior knowledge of specific anomaly types, offers a promising approach for automatic diagnosis of such conditions. In particular, recent studies have demonstrated that the absolute age difference (AAD) between predicted gestational age (PGA) of deep learning models from MRI images and biological gestational age (BGA) shows potential for detecting fetal brain anomalies, albeit with limited performance. To enhance anomaly detection capabilities, this study introduces a three-dimensional (3D) Patch-based brain ANomaly Detection framework via Age prediction (PANDA), utilizing the maximum AAD across all patches (MaxAAD) as a biomarker for identifying fetal brain anomalies. Experiments were conducted on MRI data from a large clinical cohort of 1,316 fetuses comprising 711 normal cases and 605 abnormal cases, including 343 with ventriculomegaly (VM), 50 with germinal matrix-intraventricular hemorrhage (GMH-IVH), and 212 with subependymal cysts (SEC). PANDA achieved the best diagnostic performance with an area under the receiver operating characteristic curve (AUROC) of 0.762 and an area under the precision-recall curve (AUPR) of 0.790. Subgroup analysis across the three disease categories further revealed consistently superior performance.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

Its files are read in the Code ↔ Paper reader above, with 2 matches between paragraphs and lines of code.

yingqihao2022/PANDA

License: MIT
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: 40e00a386b65d617b056bc332bb112c78fb059d2, 27 April 2026
Languages: Python (5)
Size: 9 files, 5 scripts
Software Heritage: not archived
Found in: “Data and Code Availability”
Holds: README, license file
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Tools: PyTorch (5 files), NumPy (4 files), NiBabel (2 files), Matplotlib (1 file), MONAI (1 file), pandas (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
7 files

birthlab/PANDA

License: MIT
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: 84b13d6320bf3c62817e8fb09f5ac802e1a4b166, 18 June 2026
Languages: Python (5)
Size: 9 files, 5 scripts
Software Heritage: not archived
Found in: “Data and Code Availability”
Holds: README, license file
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Tools: PyTorch (5 files), NumPy (4 files), NiBabel (2 files), Matplotlib (1 file), MONAI (1 file), pandas (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
7 files

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:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 10 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

No dataset and no data link were found in the paper.

Data and Code Availability

Data generated or analyzed during the study are not publicly available, but are available from the corresponding author by request. The source codes of PANDA are implemented using Pytorch, which are available at: https://github.com/birthlab/PANDA (https://github.com/yingqihao2022/PANDA)

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 1, 27 September 2026: the first record

Recorded: type, language, journal, volume, pages, dates, 13 authors, 5 keywords, 6 funders, 50 references.

Cite

This paper

Hao, Y., Liu, M., Zhu, J., Yang, H., Li, H., Kang, M., Song, Y., Lai, H., Zhou, X., Ning, G., Liao, Y., Qu, H., & Tian, Q. (2026). PANDA: Patch-based unsupervised deep learning for brain anomaly detection via age prediction in fetal MRI. Imaging neuroscience (Cambridge, Mass.), 4, IMAG.a.1293. https://doi.org/10.1162/imag.a.1293

BibTeX

@article{hao2026panda,
author = {Hao, Yingqi and Liu, Mingxuan and Zhu, Juncheng and Yang, Hongjia and Li, Haoxiang and Kang, Min and Song, Yan and Lai, Hua and Zhou, Xiaoling and Ning, Gang and Liao, Yi and Qu, Haibo and Tian, Qiyuan},
title = {{PANDA: Patch-based unsupervised deep learning for brain anomaly detection via age prediction in fetal MRI}},
journal = {Imaging neuroscience (Cambridge, Mass.)},
year = {2026},
month = jul,
volume = {4},
pages = {IMAG.a.1293},
publisher = {MIT Press},
issn = {2837-6056},
doi = {10.1162/imag.a.1293},
url = {https://doi.org/10.1162/imag.a.1293},
pmid = {42453641},
pmcid = {PMC13366612}
}

RIS

TY - JOUR
AU - Hao, Yingqi
AU - Liu, Mingxuan
AU - Zhu, Juncheng
AU - Yang, Hongjia
AU - Li, Haoxiang
AU - Kang, Min
AU - Song, Yan
AU - Lai, Hua
AU - Zhou, Xiaoling
AU - Ning, Gang
AU - Liao, Yi
AU - Qu, Haibo
AU - Tian, Qiyuan
TI - PANDA: Patch-based unsupervised deep learning for brain anomaly detection via age prediction in fetal MRI
T2 - Imaging neuroscience (Cambridge, Mass.)
J2 - Imaging Neurosci (Camb)
PY - 2026
DA - 2026/07/13
VL - 4
SP - IMAG.a.1293
SN - 2837-6056
PB - MIT Press
DO - 10.1162/imag.a.1293
UR - https://doi.org/10.1162/imag.a.1293
LA - en
ER -

CSL-JSON

{
"id": "10.1162/imag.a.1293",
"type": "article-journal",
"title": "PANDA: Patch-based unsupervised deep learning for brain anomaly detection via age prediction in fetal MRI",
"container-title": "Imaging neuroscience (Cambridge, Mass.)",
"author": [
{
"family": "Hao",
"given": "Yingqi"
},
{
"family": "Liu",
"given": "Mingxuan"
},
{
"family": "Zhu",
"given": "Juncheng"
},
{
"family": "Yang",
"given": "Hongjia"
},
{
"family": "Li",
"given": "Haoxiang"
},
{
"family": "Kang",
"given": "Min"
},
{
"family": "Song",
"given": "Yan"
},
{
"family": "Lai",
"given": "Hua"
},
{
"family": "Zhou",
"given": "Xiaoling"
},
{
"family": "Ning",
"given": "Gang"
},
{
"family": "Liao",
"given": "Yi"
},
{
"family": "Qu",
"given": "Haibo"
},
{
"family": "Tian",
"given": "Qiyuan"
}
],
"container-title-short": "Imaging Neurosci (Camb)",
"volume": "4",
"page": "IMAG.a.1293",
"DOI": "10.1162/imag.a.1293",
"PMID": "42453641",
"PMCID": "PMC13366612",
"ISSN": "2837-6056",
"publisher": "MIT Press",
"URL": "https://doi.org/10.1162/imag.a.1293",
"language": "en",
"issued": {
"date-parts": [
[
2026,
7,
13
]
]
}
}

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.1016/j.patter.2026.101538 [code]
A multi-modal foundation model for brain disease diagnosis and medical imaging.
Journal: Patterns (New York, N.Y.)
In common: MONAI, NiBabel, PyTorch, 3 other tools, 2 references
[2] doi:10.1186/s40708-026-00316-y [code]
Generalizable and explainable deep learning for brain MRI: a multi-cohort evaluation of 3D architectures for age and sex prediction.
Journal: Brain informatics
In common: MONAI, PyTorch, pandas, 2 other tools, structural MRI / diffusion, 1 reference
[3] doi:10.1186/s13244-026-02365-7 [code]
Super-resolution MRI and 2.5D deep learning for intratumoral-peritumoral radiomics in preoperative prediction of rectal cancer perineural invasion.
Journal: Insights into imaging
In common: MONAI, NiBabel, PyTorch, 3 other tools, structural MRI / diffusion
[4] doi:10.1371/journal.pcbi.1014555 [code]
Body surface potential driven personalisation of electrophysiological digital twins in hypertrophic cardiomyopathy.
Journal: PLoS computational biology
In common: MONAI, NiBabel, PyTorch, 3 other tools, structural MRI / diffusion
[5] doi:10.3389/fnins.2026.1870124 [code]
An end-to-end pipeline for automated fetal brain segmentation and biometry from 3D SSFP MRI.
Journal: Frontiers in neuroscience
In common: MONAI, NiBabel, PyTorch, 3 other tools, structural MRI / diffusion
[6] doi:10.1038/s41467-026-73996-z [code]
Genetic architecture of white matter microstructure captured by unsupervised deep representation learning of fractional anisotropy maps.
Journal: Nature communications
In common: MONAI, NiBabel, PyTorch, 3 other tools, structural MRI / diffusion
[7] doi:10.1186/s13244-026-02296-3 [code]
A pre-trained foundation model framework for multiplanar MRI classification of extramural vascular invasion and mesorectal fascia invasion in rectal cancer.
Journal: Insights into imaging
In common: MONAI, NiBabel, PyTorch, 3 other tools, structural MRI / diffusion
[8] doi:10.1158/2767-9764.crc-25-0710 [code]
MRI Deep Learning for Differentiating Glioblastoma, IDH Wild-type from Central Nervous System Diffuse Large B-cell Lymphoma.
Journal: Cancer research communications
In common: MONAI, NiBabel, PyTorch, 3 other tools, structural MRI / diffusion
[9] doi:10.1038/s41467-026-71555-0 [code]
A deep representation learning model to predict response to vagus nerve stimulation.
Journal: Nature communications
In common: MONAI, NiBabel, PyTorch, 3 other tools, structural MRI / diffusion
[10] doi:10.3389/frai.2026.1771088 [code]
Few-shot deployment of pretrained MRI transformers in brain imaging tasks.
Journal: Frontiers in artificial intelligence
In common: MONAI, NiBabel, PyTorch, 3 other tools, structural MRI / diffusion

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.

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.