Powered by AstroClass 1.2 Flash — a drop-in ResNet-34 backbone trained in PyTorch 2.x across 70,541 astronomical images streamed directly into RAM (zero disk writes) from SDSS DR18, DECaLS, NASA Images API, ESA/Hubble, and Wikimedia Commons, paired with in-process Qwen 2.5-7B neural auditing and SQLite classification tracking.
A modular deep learning ecosystem combining zero-disk RAM streaming across five astronomical archives, astro-aware GPU training, SQLite auto-sorting, and local 4-bit Qwen 2.5 neural validation.
training/streaming/ streams 70,541 observations from SDSS DR18, DECaLS, NASA Images API, ESA/Hubble, and Wikimedia Commons as 256×256 JPEGs in RAM (~806 MB, zero disk writes), with 8-dihedral dHash & cosine deduplication alongside image_collection.py.
training/stream_train.py fine-tunes ResNet-34 over 23,601 steps (~3.02M samples seen, ~120 min on RTX 4060 Laptop) with AdamW, label smoothing (0.05), bfloat16 autocast, EMA weights (0.9985), and GPU photometric/geometric augmentations.
network_sorting/ & src/validator/qwen_validator.py sort captures into 5 classes, log audit telemetry to SQLite (classified_images.db), run local 4-bit Qwen2.5-Coder-7B-Instruct supervision, and serve a Flask inspection UI.
Every stage in nasa-image-training operates as a decoupled module — from RAM-only multi-survey streaming to local LLM-guided weight auditing.
Located in training/stream_train.py and training/streaming/. Streams ~70,500 images from 14 concurrent source workers directly into RAM as 256×256 JPEG buffers (~806 MB total, zero disk writes) while training ResNet-34 at ~419 img/s.
sqrt(size) × group_weight) & 5% MD5 held-out split.
Located in training/eval_streamed_holdout.py and training/audit_local_images.py. Re-streams only the deterministic 5% held-out validation split (md5(seed:uid)) to benchmark multiple weight checkpoints side-by-side.
galaxy/decals, star/sdss_faint, etc.).images/nasaDownloads, network_sorting) to inspect model disagreements.
Located in src/data_collection/image_collection.py. Downloads high-resolution astronomical targets across NASA APOD and MAST Hubble Space Telescope archives using keyword matching (galaxy, nebula, planet, cluster, hubble, webb).
images/nasaDownloads/ and images/mastDownloads/.
Located in network_sorting/image_classifier.ipynb. Scans raw unclassified image directories, performs batch tensor inference with trained_net.pth (drop-in compatible with 1.2 Flash), and moves files into class folders.
network_sorting/<star|galaxy|quasar|nebula|planet>/.network_sorting/classified_images.db.training/plot_training_metrics.ipynb for learning curves & confusion matrix heatmaps.
Located in src/validator/qwen_validator.py. Runs 100% locally in-process on GPU with 4-bit quantization (zero external APIs). Audits ResNet-34 classifications image-by-image and performs online weight refinement.
high, medium, low) with frozen BatchNorm statistics.--update-db) and exports JSON reports (--save-report).
Located in src/viewer/classification_viewer.py. A lightweight local web application serving a clean semantic HTML interface at http://localhost:5000 to inspect all sorted records in classified_images.db.
star, galaxy, nebula, planet, and quasar.
For AstroClass 1.2 Flash, images are streamed from spectroscopic/catalog surveys and curated press archives, downscaled to 256×256 JPEG in RAM (~806 MB), deduplicated, and never written to disk.
Queries SpecPhoto + PhotoObjAll (zWarning=0): 18,332 quasars (QSO), 7,034 galaxies (framed at 5.5× Petrosian R90), and 20,094 stars across bright (6,031), crowded-field (6,036), and faint isolated (8,027) cohorts matching quasar magnitude (15 ≤ r ≤ 19).
Streams 11,000 catalog-confirmed galaxies from Smith42/galaxies via Parquet row-group range reads in RAM, providing rich spiral, elliptical, lenticular, and merging morphologies.
Streams 8,491 planetary bodies (Cassini, Juno, MRO HiRISE, Voyager, New Horizons, LRO), 364 galaxies, 234 nebulae, 61 star clusters, and 13 quasars, filtered by word-bounded regex gates (NASA_JUNK_TITLE / NASA_JUNK_HEAD).
Harvests 2,514 galaxies and 1,794 nebulae from Wikimedia Commons categories (depth-2 traversal) plus 610 ESA/Hubble images (Supermaxman/esa-hubble: 381 galaxies, 100 nebulae, 95 stars, 18 planets, 16 quasars).
5% of unique images (3,620 in the training run) were held out deterministically before training via md5(seed:uid). Total memory footprint in RAM: 806 MB.
| Class | Images | Source Group Breakdown |
|---|---|---|
galaxy |
21,293 | DECaLS (11,000), SDSS (7,034), Commons (2,514), ESA (381), NASA (364) |
star |
20,250 | SDSS faint (8,027), SDSS field (6,036), SDSS bright (6,031), ESA (95), NASA (61) |
quasar |
18,361 | SDSS spectroscopic QSOs (18,332), ESA/Hubble (16), NASA (13) |
planet |
8,509 | NASA Images API Solar System bodies (8,491), ESA/Hubble (18) |
nebula |
2,128 | Wikimedia Commons (1,794), NASA (234), ESA/Hubble (100) |
ImageStore enforces perceptual deduplication and quality gates on every streamed frame so twin press releases never leak across the train/validation boundary:
dup_img): 64-bit canonical dHash minimised over all 8 dihedral flips/rotations (Hamming distance ≤ 6) plus a 16×16 low-frequency signature (cosine similarity ≥ 0.93) on curated sources.conflict): Multi-object frames or republished images matching an existing hash under a different class label are rejected.bad):
2,441 blank/constant cutouts (quasar: 1,930, star: 429, galaxy: 50, planet: 18, nebula: 14),
1,153 extreme aspect ratios > 2.6 or < 48px (planet: 1,034, galaxy: 59, nebula: 59, star: 1),
565 overly bright charts/diagrams exceeding luminance ceilings (135 Commons / 175 NASA; planet: 347, galaxy: 109, nebula: 108, quasar: 1), and 4 huge lossless frames (>120 MP).
dup_uid): Prevented redundant network downloads across overlapping search queries.Honest, reproducible evaluation on the 5% held-out streamed split (never seen during training) and 85 real-world astronomical pictures independently labelled by three reviewers.
Evaluated side-by-side on the exact same re-streamed 5% held-out split (n = 4,131, ESA excluded) and 85 real-world images. Note: the previous trained_net.pth in the repo had degraded to near-uniform outputs (predicting galaxy ~90% of the time), so v1.0 (trained_net.pth.backup) is the true baseline.
| Evaluation Metric | 1.2 Flash (New) | v1.0 (.backup) | Degraded .pth |
|---|---|---|---|
| Held-Out Streamed Acc. (n = 4,131) | 93.4% | 36.7% | 25.6% |
| Held-Out 95% Confidence Interval | 92.6% – 94.1% | 35.2% – 38.2% | 24.3% – 26.9% |
| Held-Out Balanced Accuracy | 93.8% | 45.9% | 22.3% |
| Held-Out Macro F1 Score | 93.8% | 40.8% | 11.0% |
| Held-Out Source-Balanced Recall | 93.7% | 48.9% | 36.6% |
| Curated Sources Only (NASA/Commons, n = 898) | 97.0% | 75.1% | 22.3% |
| Training-Run Val (n = 3,620, EMA + 8× TTA) | 94.0% (CI 93.1–94.7%) | — | 29.5% |
| Real-World Pictures (85 imgs, 3 reviewers) | 87.1% (74/85) | 71.8% (61/85) | 38.8% (33/85) |
| Training Corpus & Hardware | 70,541 • RTX 4060 (120m) | 5,000 • Colab T4 | 5,000 • Colab T4 |
v1.0 scores low on the held-out set primarily because it never saw SDSS-style star (1.6% recall) and quasar (2.1% recall) cutouts. On real-world curated photographs, 1.2 Flash boosts accuracy from 71.8% to 87.1%.
| Class | 1.2 Flash Recall | 1.2 Flash Prec. | v1.0 Recall | Real-World (1.2) | Real-World (v1.0) |
|---|---|---|---|---|---|
star (n=1,377) |
90.6% | 94.5% | 1.6% | 2/6 | 2/6 |
galaxy (n=1,048) |
97.2% | 95.0% | 90.6% | 25/27 (92.6%) | 18/27 (66.7%) |
quasar (n=1,004) |
89.9% | 86.9% | 2.1% | 0/3 | 1/3 |
nebula (n=132) |
91.7% | 93.8% | 56.1% | 37/38 (97.4%) | 31/38 (81.6%) |
planet (n=570) |
99.5% | 99.5% | 78.9% | 10/11 (90.9%) | 9/11 (81.8%) |
Rows represent true spectroscopic/catalog labels; columns represent 1.2 Flash predictions on the 4,131 held-out test images. The primary confusion is between faint SDSS point-source star and quasar cutouts (122 stars predicted as quasar, 64 quasars as star).
| True \ Pred | star |
galaxy |
quasar |
nebula |
planet |
Recall |
|---|---|---|---|---|---|---|
star |
1,248 | 5 | 122 | 2 | 0 | 90.6% |
galaxy |
6 | 1,019 | 14 | 6 | 3 | 97.2% |
quasar |
64 | 37 | 903 | 0 | 0 | 89.9% |
nebula |
2 | 9 | 0 | 121 | 0 | 91.7% |
planet |
0 | 3 | 0 | 0 | 567 | 99.5% |
Generated automatically by training/stream_train.py across 23,601 steps (300-step warmup, lr = 2e-4 body / 4e-4 head, cosine decay over final 5,000 steps to 4e-6, final smoothed train loss 0.2986, train acc 96.5%).
Smoothed Training Loss, Held-Out Validation Accuracy/Balanced Acc., and Cosine Learning Rate Schedule (23,601 steps)
Training-Run Held-Out Confusion Matrix (n = 3,620, EMA weights + 8-fold TTA, 94.0% Accuracy)
Scientific transparency requires documenting where the model struggles and why:
galaxy: Dense stellar clusters (e.g., 47 Tucanae, M10, NGC 6366) are often predicted as galaxy because star training data is predominantly SDSS point-source cutouts (~20,094) with only ~156 curated cluster/field images.quasar training data is 99.8% SDSS point-source QSOs (18,332), which look stellar.nebula: Reachable archives yielded 2,128 clean nebula images (~101–132 held-out), so its held-out recall estimate has wider variance than galaxy or star (though it achieves 37/38 [97.4%] on real-world photos).other Class): Non-class captures such as Moon panoramas, Milky Way landscapes, comets, meteor showers, and protoplanetary discs (e.g., PDS 70) are forced into one of the 5 classes (18 such images were excluded from the 103-image real-world folder, leaving 85).star & quasar: In the 85-image real-world benchmark (labelled by 3 independent reviewers, 97/103 unanimous), star (6 images) and quasar (3 images) have very few samples, making those two percentages noisy.
Retrained from scratch on 70,541 RAM-streamed images (SDSS DR18, DECaLS, NASA, ESA/Hubble, Wikimedia Commons) after detecting weight degradation in the repository's previous trained_net.pth. Trained for 23,601 steps (batch 128, 3.02M samples, AdamW, label smoothing 0.05, bf16, EMA 0.9985). Achieves 93.4% held-out accuracy (97.0% curated-only) and 87.1% (74/85) on real-world images. Output weights: training/trained_net_stream.pth.
Refined baseline weights with 203 adaptive online gradient descent steps supervised locally by Qwen2.5-Coder-7B-Instruct (4-bit CUDA quantization). Integrated photometric feature extraction (mean luminance, dark background ratio, RGB dynamics, core concentration, edge contrast) and froze BatchNorm running statistics during single-sample updates, reaching 94.2% on the v1.1 test split and publishing to Hugging Face Hub.
Initial ResNet-34 transfer learning model trained for 25 epochs on 5,000 images (1,000 per class from NASA APOD and MAST HST) on a Google Colab T4 GPU (preserved as trained_net.pth.backup, scoring 71.8% on the 85 real-world benchmark).
Interactive 3D manifold projection of 512-dimensional feature vectors extracted from the ResNet-34 penultimate layer, illustrating cluster separation across all 5 astrophysical classes.
astroclass_ai (1.2 Flash, trained_net_stream.pth / trained_net.pth) uses the exact same ResNet-34 architecture and 5-class order as v1.0/v1.1.0 — making it an instant drop-in replacement.
Astrophysical Deep Learning Backbone (ResNet-34) fine-tuned on 70,541 streamed images from SDSS DR18, DECaLS, NASA Images API, ESA/Hubble & Wikimedia Commons, with local Qwen 2.5 validation.
1.2 Flash (tag v1.2-flash)
trained_net_stream.pth / astroclass_ai.pth
star, galaxy, quasar, nebula, planet
# Install dependencies:
pip install torch torchvision pillow huggingface_hub
import torch
from torchvision.models import resnet34
from torchvision import transforms
from PIL import Image
from huggingface_hub import hf_hub_download
# 1. Load AstroClass 1.2 Flash weights (local or Hugging Face Hub)
model_path = hf_hub_download(
repo_id="RaulSalasSahuquillo/astroclass_ai",
filename="astroclass_ai.pth",
revision="main" # or revision="v1.2-flash" / local "training/trained_net.pth"
)
# 2. Build ResNet-34 with 5 astrophysical classes (drop-in replacement)
classes = ["star", "galaxy", "quasar", "nebula", "planet"]
model = resnet34(weights=None)
model.fc = torch.nn.Linear(model.fc.in_features, len(classes))
model.load_state_dict(torch.load(model_path, map_location="cpu", weights_only=True))
model.eval()
# 3. Preprocess observation (224x224 ImageNet normalization) and predict
preprocess = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
img = Image.open("space_observation.jpg").convert("RGB")
tensor = preprocess(img).unsqueeze(0)
with torch.no_grad():
probs = torch.softmax(model(tensor), dim=1)[0]
best_idx = probs.argmax().item()
print(f"Prediction: {classes[best_idx]} ({probs[best_idx]*100:.2f}%)")
AstroClass AI is 100% open source under the CC BY-NC-SA 4.0 license. Clone the repository to run RAM-streamed training, held-out evaluation, Qwen 2.5 auditing, and the Flask viewer.
# 1. Clone the open source repository
git clone https://github.com/RaulSalasSahuquillo/nasa-image-training.git
cd nasa-image-training
# 2. Create Python virtual environment and install dependencies
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# 3. Configure environment variables (.env)
cp .env.example .env
# 4. Run 1.2 Flash large-scale RAM streaming fine-tuning & held-out benchmark
python training/stream_train.py --target 20000
python training/eval_streamed_holdout.py --weights training/trained_net.pth.backup training/trained_net.pth
# 5. Audit classifications with in-process 4-bit Qwen 2.5 AI validator
python src/validator/qwen_validator.py --limit 5
# 6. Launch the SQLite Flask Classification Web Viewer (http://localhost:5000)
python src/viewer/classification_viewer.py
I am a 16-year-old AI developer and high school student from Spain with a passionate focus on computer vision and observational astrophysics.
To help catalog the vast amounts of unclassified imagery across astronomical surveys, I built AstroClass AI (nasa-image-training) and its latest release, AstroClass 1.2 Flash: an open-source deep learning pipeline unifying zero-disk RAM streaming across 70,541 images (SDSS DR18, DECaLS, NASA, ESA/Hubble, Wikimedia Commons), ResNet-34 EMA training, in-process Qwen 2.5 validation, and SQLite audit inspection.
"In a universe of billions of galaxies, make some code-guided discoveries — streaming tens of thousands of spectroscopic and deep-space observations directly into memory to classify the cosmos in milliseconds."