Skip to content

Latest commit

Β 

History

History
173 lines (125 loc) Β· 4.11 KB

File metadata and controls

173 lines (125 loc) Β· 4.11 KB

GalaxyZoo-CapsNet


πŸ“˜ Overview

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.


✨ Features

  • 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).

🧠 Tech Stack

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

βš™οΈ Installation

# 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())"

πŸš€ Usage

1. Prepare Data

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

2. Train the Model

# Example (CapsNet Regressor):
python CapsNet/CapsNetRegressor_2.py

3. Evaluate and Predict

# 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

πŸ“Š Results

Accuracy plot
RMSE Plot

🧬 Using Your Own Dataset

  1. Organize images in a single directory (e.g., ./data/custom_images).
  2. Prepare a CSV file with:
    • Column 1: image filenames.
    • Columns 2–N: target vote fractions or labels.
  3. Adjust input channels in scripts:
	in_channels = 3  # for RGB
	in_channels = 1  # for grayscale

πŸ“š References

  1. Galaxy Zoo
  2. Simard et al. (2011)
  3. CapsNet Base Model: Reza Katebi et al., Galaxy Morphology Classification with Capsule Networks