Heartformer is a specialized object detection model for identifying and localizing different types of heart anatomy visualizations in medical images. Built on the RF-DETR architecture, this model can detect and classify seven distinct categories of cardiac imaging and illustration modalities.
📋 Model Description
Heartformer addresses the challenge of automatically categorizing diverse representations of cardiac anatomy, from real cadaver specimens to textbook illustrations. This capability is valuable for:
Medical Education: Automatically organizing and categorizing cardiac anatomy learning materials
Content Curation: Indexing large medical image databases by visualization type
Research Support: Filtering cardiac datasets by imaging modality for meta-analyses
Educational Technology: Building intelligent tutoring systems that adapt to different anatomy representation types
Key Features
Multi-modal Detection: Simultaneously detects 7 different heart anatomy visualization types
High Accuracy: Achieves 97.7% mAP@50 on held-out test set
Real-time Inference: Optimized RF-DETR Nano architecture for fast detection
Robust Generalization: Tested on diverse image sources and artistic styles
Architecture Overview
Input Image (any size)
↓
Backbone: DINOv2 ViT (Vision Transformer)
├── Patch Embedding (16×16 patches)
├── Transformer Encoder (12 layers)
└── Feature Extraction
↓
Neck: Feature Pyramid Network (FPN)
└── Multi-scale feature fusion
↓
Head: Transformer Decoder
├── Object Queries (300 learnable embeddings)
├── Cross-attention with image features
└── Self-attention between queries
↓
Detection Heads
├── Classification Head → Class probabilities (7 + 1 background)
└── Regression Head → Bounding box coordinates (x, y, w, h)
Key Components
Backbone: DINOv2-based Vision Transformer
Self-supervised pre-trained on large-scale image data
Patch size: 16×16 pixels
Produces rich semantic features
Transformer Encoder-Decoder
Encoder: Processes image features with self-attention
Decoder: Uses cross-attention to localize objects
Set-based prediction (no NMS required)
Detection Head
Bipartite matching loss for optimal assignment
Joint classification and localization
Model Specifications
Parameters: 30.5M total
Input: RGB images (resized to 640×640 during training)
Output: Up to 300 detection proposals per image
Inference Speed: <2 seconds per image on Apple M3 (MPS backend)
📊 Dataset
Heart Anatomy Types v2 (Roboflow)
The model was trained on a curated dataset of 621 annotated images from Roboflow Universe, specifically designed to capture the diversity of cardiac anatomy representations.
Dataset Statistics
Split
Images
Annotations
Distribution
Train
497
767
80.0%
Valid
62
78
10.0%
Test
62
95
10.0%
Total
621
940
100%
Class Distribution (Test Set)
Class
Count
Description
heart_cadaver
16
Real anatomical specimens from dissection
heart_cell
17
Microscopic/cellular views of cardiac tissue
heart_ct_scan
7
CT imaging of the heart
heart_drawing
10
Hand-drawn or digital medical illustrations
heart_textbook
38
Educational anatomy images from textbooks
heart_wall
6
Cross-sectional views showing heart wall layers
heart_xray
1
Radiographic chest/heart images
Data Sources
Medical textbooks (openly licensed)
Roboflow Universe community contributions
Educational anatomy databases
All images verified for appropriate licensing
Annotation Format
Annotations follow the COCO format:
json
1{2"categories":[3{"id":0,"name":"heart-anatomy-images","supercategory":"none"},4{"id":1,"name":"heart_cadaver","supercategory":"heart-anatomy-images"},5 ...
6],7"images":[...],8"annotations":[9{10"id":1,11"image_id":1,12"category_id":1,13"bbox":[x, y, width, height],14"area":12345,15"iscrowd":016}17]18}
🔬 Training Procedure
Training Configuration
python
1{2"model":"RF-DETR Nano",3"epochs":30,4"early_stopping_patience":8,5"batch_size":4,6"gradient_accumulation_steps":4,# Effective batch size: 167"learning_rate":1e-4,8"optimizer":"AdamW",9"weight_decay":1e-4,10"lr_scheduler":"cosine annealing with warmup",11"warmup_epochs":5,12"image_size":640,13"augmentations":[14"random_horizontal_flip",15"random_brightness_contrast",16"color_jitter",17"gaussian_noise"18]19}
Training Details
Hardware: Apple M3 MacBook Pro (MPS backend)
Training Time: ~1 hour 50 minutes
Best Epoch: Epoch 4 (with EMA weights)
Early Stopping: Triggered at epoch 11 (no improvement for 8 epochs)
Dataset: Heart Anatomy Types v2 from Roboflow Universe
DINOv2 Backbone: Meta AI's self-supervised vision transformer
📄 License
This model is released under the Apache License 2.0, the same license as RF-DETR.
Copyright 2024 Giannisan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.