PANDA: Patch-based unsupervised deep learning for brain anomaly detection via age prediction in fetal MRI.
One block of code here has a permanent identifier (oscr:b:…), listed with the matches below: citable for good, with a page of its own. Select a match and press Cite to copy it. What a block identifier is.
The 2 matches
- [1] § Materials and Methods › Training details ↔ train.py, lines 72 to 130 · score 0.69 · weight decay, epochs, GPU, checkpoint, optimizer, Loss · block
oscr:b:M7CH37ZH3585Q-U· Report a mismatch - [2] § Materials and Methods › Training details ↔ train.py, lines 72 to 130 · score 0.59 · weight decay, GPU, optimizer, loss, training, batch · block
oscr:b:M7CH37ZH3585Q-U· Report a mismatch
Paper
Loaded from Europe PMC by your browser; OSCR does not store it: 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
- from sfcn import SFCN
- from monai.networks.nets import ResNet, ResNetBottleneck
- import torch
- from fdataset import FetalBrainDataset
- from pathlib import Path
- import random
- import warnings
- import torch.nn as nn
- from math import sqrt
- from torch.nn import functional as F
- import numpy as np
- import os
- from torch.utils.data import Dataset, Subset
- import nibabel as nib
- from matplotlib import pyplot as plt
- from datetime import datetime
- from tqdm import tqdm
- import pandas as pd
- def create_id_to_age_lookup(file_path, id_column='ID', age_column='Age'):
- df = pd.read_excel(file_path, engine='openpyxl')
- id_age_dict = df.set_index(id_column)[age_column].to_dict()
- result_dict = {}
- for id_key, age_value in id_age_dict.items():
- input_str = str(age_value)
- if "+" in input_str:
- parts = input_str.split("+")
- result = int(parts[0]) * 7 + int(parts[1])
- else:
- result = int(input_str) * 7
- result_dict[id_key] = result
- return result_dict
- file = '/path/to/age'
- id_age_map = create_id_to_age_lookup(file)
- def loss_f2(age, recon_age):
- return torch.abs(age - recon_age).mean()
- def train(model, train_loader, optimizer, device):
- model.train()
- total_loss = 0
- for batch in train_loader:
- brain, filenames = batch
- brain = brain.to(device)
- optimizer.zero_grad()
- ages = [id_age_map.get(fname.split('_')[0], float('nan')) for fname in filenames]
- age = torch.tensor(ages, dtype=torch.float32).to(device)
- predicted_age = model(brain)[0].squeeze()
- loss = loss_f2(age, predicted_age)
- loss.backward()
- optimizer.step()
- total_loss += loss.item()
- len_loss = len(train_loader)
- return total_loss / len_loss
- def val(model, val_loader, device):
- model.eval()
- total_loss = 0
- with torch.no_grad():
- for batch in val_loader:
- brain, filenames = batch
- brain = brain.to(device)
- ages = [id_age_map.get('fb' + fname.split('_')[0], float('nan')) for fname in filenames]
- age = torch.tensor(ages, dtype=torch.float32).to(device)
- predicted_age = model(brain)[0].squeeze()
- loss = loss_f2(age, predicted_age)
- total_loss += loss.item()
- len_loss = len(val_loader)
- return total_loss / len_loss
- if __name__ == "__main__":
- gpu_index = 0
- device = torch.device(f'cuda:{gpu_index}')
- model = SFCN(select_patch=True).to(device)
- lr = 0.0001
- max_epochs = 1000
- optimizer = torch.optim.Adam(model.parameters(), lr=lr, amsgrad=True, weight_decay=0.00001)
- train_datapath = "/data/birth/lmx/work/Class_projects/course5/work/fetal/Data/new_age_data/train"
- train_dataset = FetalBrainDataset(train_datapath, split = 'test')
- print(f"Original train_dataset size: {len(train_dataset)}")
- train_dataloader = torch.utils.data.DataLoader(train_dataset,batch_size=32,shuffle=True,drop_last=True,num_workers=6)
- val_datapath = "/data/birth/lmx/work/Class_projects/course5/work/fetal/Data/new_age_data/val"
- val_dataset = FetalBrainDataset(val_datapath, split = 'test')
- print(f"Original val_dataset size: {len(val_dataset)}")
- val_dataloader = torch.utils.data.DataLoader(val_dataset,batch_size=32,shuffle=False,drop_last=True,num_workers=6)
- progress_bar = tqdm(range(1, max_epochs + 1), desc="Training Progress")
- train_losses = []
- val_losses = []
- best_val_loss = float('inf')
- for epoch in progress_bar:
- train_loss = train(model, train_dataloader, optimizer, device)
- train_losses.append(train_loss)
- val_loss = val(model, val_dataloader, device)
- val_losses.append(val_loss)
- print(f"Epoch [{epoch}/{1000}]")
- print(f"Loss : Train: {train_loss:.8f}, Val: {val_loss:.8f}")
- output_folder = "/your/output/folder"
- if val_loss < best_val_loss:
- best_val_loss = val_loss
- checkpoint_path = os.path.join('/your/output/folder', 'best_model.pt')
- os.makedirs(os.path.dirname(checkpoint_path), exist_ok=True)
- torch.save({
- 'epoch': epoch,
- 'model_state_dict': model.state_dict(),
- 'optimizer_state_dict': optimizer.state_dict(),
- 'best_val_loss': best_val_loss}, checkpoint_path)
- if epoch % 25 == 0:
- current_time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
- epochs = range(4, len(train_losses) + 1)
- plt.figure(figsize=(10, 5))
- plt.plot(epochs, train_losses[3:], color='green', label='Train Loss Age')
- plt.plot(epochs, val_losses[3:], color='orange', label='Val Loss Age')
- plt.title('Age Loss')
- plt.xlabel('Epoch')
- plt.ylabel('Loss')
- plt.legend()
- plt.grid(True)
- plt.tight_layout()
- age_loss_path = os.path.join(output_folder, f"age_loss_{current_time}.png")
- plt.savefig(age_loss_path, bbox_inches='tight', pad_inches=0)
- plt.close()
train.py at commit 84b13d6, under MIT · at the source
Overview
- Department of Radiology, West China Second University Hospital, Sichuan University, Chengdu, Sichuan Province, China
- School of Biomedical Engineering, Tsinghua Medicine, Tsinghua University, Beijing, China
- Key Laboratory of Birth Defects and Related Diseases of Women and Children, Ministry of Education, Chengdu, Sichuan Province, China
- Department of Radiology, Chengdu Seventh People’s Hospital (Affiliated Cancer Hospital of Chengdu Medical College), Chengdu, China
- 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
- Chengdu Women’s and Children’s Central Hospital, School of Medicine, University of Electronic Science and Technology of China, Chengdu, China
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
40e00a386b65d617b056bc332bb112c78fb059d2, 27 April 2026Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
7 files
- fdataset.py, Python, 61 lines
- inference.py, Python, 44 lines
- preprocess.py, Python, 112 lines
- sfcn.py, Python, 80 lines
- train.py, Python, 130 lines
- LICENSE, License, 21 lines
- README.md, Text, 71 lines
birthlab/PANDA
84b13d6320bf3c62817e8fb09f5ac802e1a4b166, 18 June 2026Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
7 files
- fdataset.py, Python, 61 lines
- inference.py, Python, 44 lines
- preprocess.py, Python, 112 lines
- sfcn.py, Python, 80 lines
- train.py, Python, 130 lines, 2 matches
- LICENSE, License, 21 lines
- README.md, Text, 91 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:
- 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://
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://
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/
url = {https://
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/
VL - 4
SP - IMAG.a.1293
SN - 2837-6056
PB - MIT Press
DO - 10.1162/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1162/
"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":
"volume": "4",
"page": "IMAG.a.1293",
"DOI": "10.1162/
"PMID": "42453641",
"PMCID": "PMC13366612",
"ISSN": "2837-6056",
"publisher": "MIT Press",
"URL": "https://
"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.neuroimage.2025.121442 [code]
- Conditional deep generative normative modeling for structural and developmental anomaly detection in the fetal brain.Journal: NeuroImageIn common: MONAI, NiBabel, PyTorch, 3 other tools, developmental, structural MRI / diffusion, 3 references
- [2] doi:10.1038/s41467-025-56321-y [code]
- Evaluating normative representation learning in generative AI for robust anomaly detection in brain imaging.Journal: Nature communicationsIn common: MONAI, NiBabel, PyTorch, 3 other tools, 2 references
- [3] doi:10.1002/advs.202307965 [code]
- DIMOND: DIffusion Model OptimizatioN with Deep Learning.Journal: Advanced science (Weinheim, Baden-Wurttemberg, Germany)In common: NiBabel, PyTorch, pandas, 2 other tools, structural MRI / diffusion, author Qiyuan Tian
- [4] 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
- [5] doi:10.1007/s00247-025-06403-2 [code]
- Towards automated fetal brain biometry reporting for 3-dimensional T2-weighted 0.55-3T magnetic resonance imaging at 20-40 weeks gestational age range.Journal: Pediatric radiologyIn common: MONAI, NiBabel, PyTorch, 3 other tools, developmental, structural MRI / diffusion, 1 reference
- [6] doi:10.1007/s00247-025-06165-x [code]
- Scanner-based real-time three-dimensional brain + body slice-to-volume reconstruction for T2-weighted 0.55-T low-field fetal magnetic resonance imaging.Journal: Pediatric radiologyIn common: MONAI, NiBabel, PyTorch, 3 other tools, developmental, structural MRI / diffusion, 1 reference
- [7] doi:10.1002/jmri.70180 [code]
- Developmental Brain Age Estimation From MRI Data: A Systematic Review of Deep Learning Approaches and Open Datasets.Journal: Journal of magnetic resonance imaging : JMRIIn common: NiBabel, PyTorch, pandas, 2 other tools, developmental, structural MRI / diffusion, 2 references
- [8] doi:10.1162/imag_a_00552 [code]
- Brain age identification from diffusion MRI synergistically predicts neurodegenerative disease.Journal: Imaging neuroscience (Cambridge, Mass.)In common: MONAI, NiBabel, PyTorch, 3 other tools, structural MRI / diffusion, 1 reference
- [9] doi:10.1126/sciadv.adr3757 [code]
- Genetically supported targets and drug repurposing for brain aging: A systematic study in the UK Biobank.Journal: Science advancesIn common: MONAI, PyTorch, pandas, 2 other tools, structural MRI / diffusion, 2 references
- [10] doi:10.1016/j.neuroimage.2024.120603 [code]
- Fetal brain MRI atlases and datasets: A review.Journal: NeuroImageIn common: MONAI, NiBabel, PyTorch, 3 other tools, structural MRI / diffusion, 1 reference
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: 2 repositories of the authors' code, each at its verified commit and with its license, 10 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:fb1472efc87749e5…
Add the badge to the code's README
If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.
Markdown
<!-- oscr-badge:start -->
[](https://openscicode.org/badge/doi/10.1162/imag.a.1293)
<!-- oscr-badge:end -->reStructuredText
.. oscr-badge:start
.. image:: https://openscicode.org/badge/doi/10.1162/imag.a.1293.svg
:target: https://openscicode.org/badge/doi/10.1162/imag.a.1293
:alt: OSCR
.. oscr-badge:endHTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1162/imag.a.1293"><img src="https://openscicode.org/badge/doi/10.1162/imag.a.1293.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".
If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge 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: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.
Report a mismatch between the code and the paper · Report a code error (signed in)
Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.
Report a reproduction failure (signed in)
Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
