GalaxyZoo-CapsNet investigates the ability of a Capsule Network (CapsNet) to classify galaxy morphologies using image data from the Galaxy Zoo 2 survey. The project aims to reproduce human classification performance and well-known physical relationships in galaxy evolution by predicting Galaxy Zoo vote fractions and structural parameters from the Simard et al. (2011) catalogue.
- Implementation of CapsNet and ResNet for galaxy morphology prediction.
- Training and inference scripts supporting RGB and grayscale images.
- Data processing pipeline for converting raw image folders into model-ready tensors.
- Visualization tools for reconstructed images and accuracy evolution.
- Statistical comparison utilities (e.g., KS test, ROC curves, and colorβmass relations).
- Supports large-scale training on GPU clusters (e.g., Lancaster University HEC).
Languages & Frameworks
β’ Python (3.8+)
β’ PyTorch
β’ Torchvision
Libraries
β’ NumPy, Pandas
β’ scikit-learn, SciPy
β’ scikit-image
β’ Matplotlib, Seaborn
β’ PIL
Hardware
β’ Optimized for GPU acceleration (CUDA).
β’ Developed on a Tesla V100 (Lancaster University HEC Cluster).
GalaxyZoo-CapsNet/
β
βββ CapsNet/
β βββ CapsNetRegressor_2.py
β βββ CapsNetRegressor_all.py
β βββ CapsNetPredictor_2.py
β βββ CapsNetPredictor_all.py
β βββ CapsNetReconstructor.py
β
βββ ResNet/
β βββ ResNetRGB.py
β βββ ResNetGrey.py
β βββ ResNetRGBPredict.py
β βββ ResNetGreyPredict.py
β
βββ Dataloader/
β βββ Dataloader.py
β βββ Segmenter_Dataloader.py
β
βββ DataAnalysis/
β βββ AccuracyPlot.py
β βββ ColourBar_Plot.py
β βββ Colour_Mass_Plot.py
β βββ HistogramPlot.py
β βββ KS_Test.py
β βββ ROC_BinaryLabel.py
β βββ ROC_Plotter.py
β βββ ReconstructImages.py
β βββ SersicVotes_Errors.py
β
βββ results/
β βββ acc.png
β
βββ README.md
# Clone the repository and install dependencies:
git clone https://github.com/Commit2Cosmos/DeepCaps_Pytorch.git
cd DeepCaps_Pytorch
pip install -r requirements.txt
# If using a GPU, ensure PyTorch is installed with CUDA support.
# You can verify this by running:
python -c "import torch; print(torch.cuda.is_available())"Place all galaxy images in a directory and prepare a CSV file where:
- The first column contains relative image paths.
- The remaining columns contain Galaxy Zoo vote fractions or structural parameters.
#Run the dataloader:
python Dataloader/Dataloader.py --root_dir ./images --csv_file ./data/labels.csv
# Example (CapsNet Regressor):
python CapsNet/CapsNetRegressor_2.py# To predict using pretrained weights:
python CapsNet/CapsNetPredictor_2.py --weights epoch_50.pt
# Accuracy over epochs
python DataAnalysis/AccuracyPlot.py
# ROC curve
python DataAnalysis/ROC_Plotter.py
# Image reconstructions
python DataAnalysis/ReconstructImages.py- Organize images in a single directory (e.g., ./data/custom_images).
- Prepare a CSV file with:
- Column 1: image filenames.
- Columns 2βN: target vote fractions or labels.
- Adjust input channels in scripts:
in_channels = 3 # for RGB
in_channels = 1 # for grayscale

