An end-to-end Computer Vision framework powered by a custom ResNet-34 neural network in PyTorch 2.x. Automates batch data harvesting from NASA APOD & MAST Hubble/JWST archives, sorting observations into 5 astrophysical classes with SQLite audit tracking.
A fully automated, modular deep learning pipeline designed to harvest raw space captures, train robust convolutional representations, and perform audited batch classification.
src/data_collection/image_collection.py fetches high-resolution observations from NASA APOD API and MAST (Hubble Space Telescope catalog) with automated deduplication JSON registries.
training/network_training.ipynb trains a fine-tuned ResNet-34 with PyTorch Automatic Mixed Precision (AMP), geometric space augmentations (180° rotation invariance), and Adam optimization.
network_sorting/ performs batch inference, sorts images into class directories, and logs every audit record into SQLite (classified_images.db), viewable in Flask.
Each component operates as an autonomous, decoupled module within the repository ecosystem.
Located in src/data_collection/image_collection.py. Interacts with the NASA Planetary APOD endpoint using keyword filtering (galaxy, nebula, planet, cluster, star) and queries the Mikulski Archive for Space Telescopes (MAST) with Observations.query_criteria for Hubble HST science products.
downloaded.json registries.
Located in training/network_training.ipynb. Implements a transfer-learning convolutional backbone (ResNet-34) pretrained on ImageNet and re-engineered with a 5-class linear output head.
torch.amp.autocast & GradScaler).trained_net.pth.
Located in network_sorting/image_classifier.ipynb. Scans raw unclassified image directories, performs tensor inference with trained_net.pth, and dynamically moves files to organized target folders.
star, galaxy, nebula, etc.).classified_images.db.
Located in src/viewer/classification_viewer.py. A lightweight local web application serving a clean interface to inspect all audit records stored in the SQLite database.
AstroClass AI harvests observational data across premier astrophysical endpoints, harmonizing image distributions for convolutional training.
High-resolution space captures queried via REST API with keyword matching (nebula, galaxy, cluster, planet, supernova).
Science catalog observation products harvested with Astroquery, filtered by instrument, target name, and MJD date windows.
Stores complete inference records in classified_images.db: file paths, predicted classes, and audit timestamps.
Random horizontal flips, 180° rotation invariance, and ImageNet mean/std distribution tensors tailored for astronomy.
Interactive 3D manifold projection of feature vectors extracted from the ResNet-34 penultimate layer, demonstrating cluster separation across all 5 astrophysical target classes.
The fine-tuned astroclass_ai ResNet-34 model is publicly hosted on Hugging Face Hub. Download pre-trained PyTorch weights or run inference in seconds with huggingface_hub.
Astrophysical Deep Learning Backbone (ResNet-34) fine-tuned on NASA APOD and Mikulski Archive for Space Telescopes (MAST Hubble Space Telescope).
astroclass_ai.pth (85.3 MB)
# 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. Download weights directly from Hugging Face Hub
model_path = hf_hub_download(
repo_id="RaulSalasSahuquillo/astroclass_ai",
filename="astroclass_ai.pth"
)
# 2. Build ResNet-34 with 5 astrophysical classes
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"))
model.eval()
# 3. Preprocess observation 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("deep_space_capture.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"Predicted: {classes[best_idx]} ({probs[best_idx]*100:.1f}%)")
AstroClass AI is 100% open source under the CC BY-NC-SA 4.0 license. Clone the repository and execute the observation pipeline in 4 simple commands.
# 1. Clone the open source repository
git clone https://github.com/RaulSalasSahuquillo/nasa-deep-space-classifier.git
cd nasa-deep-space-classifier
# 2. Create Python virtual environment and install dependencies
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# 3. Configure your NASA API key (Optional: DEMO_KEY works out of the box)
cp .env.example .env
# 4. Harvest astronomical imagery from NASA APOD & MAST
python src/data_collection/image_collection.py
# 5. Launch the SQLite Flask Classification Web Viewer
python src/viewer/classification_viewer.py
# Navigate to http://localhost:5000 in your web browser
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 floating in astronomical archives, I built AstroClass AI (nasa-deep-space-classifier): an open-source deep learning pipeline unifying data harvesting, ResNet-34 neural training, automated sorting, and SQLite audit inspection under a reproducible open science framework.
"Artificial intelligence and deep convolutional networks allow us to illuminate the hidden structures of deep space, cataloging celestial captures in milliseconds."