Johnyquest7/TN5000-thyroid-nodule-classification
TN5000 Thyroid Nodule Classification Dataset A preprocessed, CNN-ready version of the TN5000 thyroid ultrasound dataset, cropped to individual nodule regions of interest and standardized to 224×224 PNG images for binary classification (Benign vs. Malignant). Source Dataset This dataset is derived from: TN5000: An Ultrasound Image Dataset for Thyroid Nodule Detection and ClassificationXiaoxian Yu et al., Scientific Data (Nature Publishing Group), 2025DOI:… See the full description on the dataset page: https://huggingface.co/datasets/Johnyquest7/TN5000-thyroid-nodule-classification.
TN5000 Thyroid Nodule Classification Dataset
A preprocessed, CNN-ready version of the TN5000 thyroid ultrasound dataset, cropped to individual nodule regions of interest and standardized to 224×224 PNG images for binary classification (Benign vs. Malignant).
Source Dataset
This dataset is derived from:
TN5000: An Ultrasound Image Dataset for Thyroid Nodule Detection and Classification Xiaoxian Yu et al., Scientific Data (Nature Publishing Group), 2025 DOI: https://www.nature.com/articles/s41597-025-05757-4
The original TN5000 dataset contains 5,000 thyroid ultrasound images with Pascal VOC–style bounding box annotations labeling each nodule as benign (0) or malignant (1), along with predefined train/validation/test splits.
Modifications Made
The following processing pipeline was applied to the original TN5000 dataset to produce this version:
- Nodule cropping: Each image was cropped to the annotated bounding box of the thyroid nodule. When an image contained multiple bounding boxes, the largest by area was used.
- Square padding with context: The crop was expanded to a square using the longer bounding box dimension as the base, then extended by 20% on each side to include surrounding tissue context. Crops were clamped to image boundaries.
- Resize to 224×224: All crops were resized to 224×224 pixels using Lanczos resampling, compatible with standard CNN architectures (ResNet, EfficientNet, ViT, etc.).
- Format conversion: Images were saved as lossless PNG files to avoid JPEG compression artifacts.
- Split organization: Images were organized into
Train / Valid / Testdirectories, each containingBenignandMalignantsubdirectories, following the original dataset's predefined splits.
The processing script `prepare_dataset.py` is included in this repository for full reproducibility.
Dataset Structure
TN5000/
├── README.md
├── prepare_dataset.py
├── Train/
│ ├── Benign/ # 1,032 images
│ └── Malignant/ # 2,468 images
├── Valid/
│ ├── Benign/ # 125 images
│ └── Malignant/ # 375 images
└── Test/
├── Benign/ # 269 images
└── Malignant/ # 731 imagesClass Distribution
Note on class imbalance: Malignant nodules constitute ~71.5% of the dataset. When training a CNN, it is recommended to use class-weighted loss or weighted random sampling to prevent the model from being biased toward the majority class.
Image Specifications
Usage
PyTorch (ImageFolder)
from torchvision import datasets, transforms
from torch.utils.data import DataLoader
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]), # ImageNet stats
])
train_ds = datasets.ImageFolder("TN5000/Train", transform=transform)
valid_ds = datasets.ImageFolder("TN5000/Valid", transform=transform)
test_ds = datasets.ImageFolder("TN5000/Test", transform=transform)
# Class indices: {'Benign': 0, 'Malignant': 1}
print(train_ds.class_to_idx)
train_loader = DataLoader(train_ds, batch_size=32, shuffle=True, num_workers=4)
valid_loader = DataLoader(valid_ds, batch_size=32, shuffle=False, num_workers=4)
test_loader = DataLoader(test_ds, batch_size=32, shuffle=False, num_workers=4)Handling Class Imbalance (PyTorch)
import torch
from torch.utils.data import WeightedRandomSampler
# Compute per-sample weights inversely proportional to class frequency
class_counts = torch.tensor([1032, 2468], dtype=torch.float)
class_weights = 1.0 / class_counts
sample_weights = class_weights[train_ds.targets]
sampler = WeightedRandomSampler(sample_weights, num_samples=len(train_ds), replacement=True)
train_loader = DataLoader(train_ds, batch_size=32, sampler=sampler, num_workers=4)Hugging Face datasets
from datasets import load_dataset
ds = load_dataset("imagefolder", data_dir="TN5000", drop_labels=False)
print(ds)Recommended Augmentations
Because this is medical ultrasound data, consider using these augmentations during training:
train_transform = transforms.Compose([
transforms.RandomHorizontalFlip(),
transforms.RandomVerticalFlip(),
transforms.RandomRotation(15),
transforms.ColorJitter(brightness=0.2, contrast=0.2),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
])Reproducing This Dataset
The script `prepare_dataset.py` converts the original TN5000 dataset into this format. It requires:
- Python 3.8+
- Pillow (
pip install Pillow) - The original TN5000 dataset with
JPEGImages/,Annotations/, andImageSets/Main/directories
Update the BASE_DIR path in the script to point to your local copy of the original TN5000 dataset, then run:
python prepare_dataset.pyLicense
This dataset is released under the Creative Commons Attribution 4.0 International (CC BY 4.0) license, inherited from the original TN5000 dataset.
You are free to:
- Share — copy and redistribute the material in any medium or format
- Adapt — remix, transform, and build upon the material for any purpose, including commercially
Under the following terms:
- Attribution — You must give appropriate credit to the original authors (see citation below), provide a link to the license, and indicate if changes were made.
Full license text: https://creativecommons.org/licenses/by/4.0/
Citation
If you use this dataset in your research, please cite the original paper:
@article{yu2025tn5000,
title = {TN5000: An Ultrasound Image Dataset for Thyroid Nodule Detection and Classification},
author = {Yu, Xiaoxian and others},
journal = {Scientific Data},
publisher = {Nature Publishing Group},
year = {2025},
doi = {10.1038/s41597-025-05757-4},
url = {https://www.nature.com/articles/s41597-025-05757-4}
}Disclaimer
This dataset is intended for research and educational purposes only. It should not be used as a substitute for professional medical diagnosis or clinical decision-making.
