Instructions to use MA29/astro-image-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use MA29/astro-image-classifier with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://MA29/astro-image-classifier") - Notebooks
- Google Colab
- Kaggle
Add model card
Browse files
README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: keras
|
| 4 |
+
pipeline_tag: image-classification
|
| 5 |
+
tags:
|
| 6 |
+
- image-classification
|
| 7 |
+
- astronomy
|
| 8 |
+
- tensorflow
|
| 9 |
+
- keras
|
| 10 |
+
- transfer-learning
|
| 11 |
+
- ensemble
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Astro Image Classifier
|
| 15 |
+
|
| 16 |
+
An ensemble of two transfer-learned CNN branches that classifies astronomical
|
| 17 |
+
images into 11 classes.
|
| 18 |
+
|
| 19 |
+
- **Demo:** https://huggingface.co/spaces/MA29/astro-image-classifier
|
| 20 |
+
- **Code:** https://github.com/Majd1029/Astro-Image-Classifier
|
| 21 |
+
|
| 22 |
+
## Architecture
|
| 23 |
+
|
| 24 |
+
```
|
| 25 |
+
vgg_ensemble_input [None,224,224,3] -> vgg_branch_model -> softmax(11)
|
| 26 |
+
densenet_ensemble_input [None,224,224,3] -> densenet_branch_model -> softmax(11)
|
| 27 |
+
-> Average
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
- VGG19 and DenseNet201 backbones, ImageNet-initialised and partially unfrozen
|
| 31 |
+
- Custom heads: global average pooling, dense + batch norm, dropout
|
| 32 |
+
- The VGG branch includes a data-augmentation block, inactive at inference
|
| 33 |
+
- 40,056,982 parameters
|
| 34 |
+
- Saved with Keras 3.10; optimizer state stripped, so this file is inference-only
|
| 35 |
+
|
| 36 |
+
## Classes
|
| 37 |
+
|
| 38 |
+
`black_hole`, `earth`, `galaxy`, `jupiter`, `mars`, `mercury`, `neptune`,
|
| 39 |
+
`pluto`, `saturn`, `uranus`, `venus`
|
| 40 |
+
|
| 41 |
+
## Usage
|
| 42 |
+
|
| 43 |
+
**Both branches preprocess internally** — the densenet branch through a
|
| 44 |
+
`Lambda(preprocess_input)`, the vgg branch through a channel-swap and
|
| 45 |
+
mean-subtraction chain. Feed **raw 0-255 RGB**. Applying
|
| 46 |
+
`vgg19.preprocess_input` or `densenet.preprocess_input` beforehand preprocesses
|
| 47 |
+
twice and degrades predictions badly on some classes.
|
| 48 |
+
|
| 49 |
+
`custom_objects` is required: the densenet Lambda is serialised under the name
|
| 50 |
+
`preprocess_input`, and Keras resolves it by that name at load time.
|
| 51 |
+
|
| 52 |
+
```python
|
| 53 |
+
import numpy as np, tensorflow as tf, keras
|
| 54 |
+
from huggingface_hub import hf_hub_download
|
| 55 |
+
from PIL import Image
|
| 56 |
+
from tensorflow.keras.applications.densenet import preprocess_input
|
| 57 |
+
|
| 58 |
+
keras.mixed_precision.set_global_policy("float32") # saved under mixed_float16
|
| 59 |
+
|
| 60 |
+
path = hf_hub_download("MA29/astro-image-classifier", "ensemble_model.keras")
|
| 61 |
+
model = tf.keras.models.load_model(
|
| 62 |
+
path, custom_objects={"preprocess_input": preprocess_input}, compile=False
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
CLASSES = ["black_hole", "earth", "galaxy", "jupiter", "mars", "mercury",
|
| 66 |
+
"neptune", "pluto", "saturn", "uranus", "venus"]
|
| 67 |
+
|
| 68 |
+
img = Image.open("example.jpg").convert("RGB").resize((224, 224))
|
| 69 |
+
x = np.expand_dims(np.array(img, dtype="float32"), 0) # raw 0-255
|
| 70 |
+
names = [t.name.split(":")[0].split("/")[0] for t in model.inputs]
|
| 71 |
+
|
| 72 |
+
probs = model.predict({n: x for n in names}, verbose=0)[0]
|
| 73 |
+
print(CLASSES[int(np.argmax(probs))], probs.max())
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
## Evaluation
|
| 77 |
+
|
| 78 |
+
Held-out test performance is reported in the training notebook in the GitHub
|
| 79 |
+
repo. No independent evaluation has been run for this model card, so no headline
|
| 80 |
+
accuracy figure is quoted here.
|
| 81 |
+
|
| 82 |
+
A 110-image check (10 per class) was run against the **training** data purely to
|
| 83 |
+
validate input preprocessing. It returned 100% under raw 0-255 input versus 71.8%
|
| 84 |
+
when inputs were preprocessed twice. That number measures memorisation of
|
| 85 |
+
training images, not generalisation, and should not be read as an accuracy claim.
|
| 86 |
+
|
| 87 |
+
## Limitations
|
| 88 |
+
|
| 89 |
+
- Trained on a curated, fairly clean dataset of planet and deep-sky imagery; it
|
| 90 |
+
has not been evaluated on telescope captures, noisy frames or unusual crops.
|
| 91 |
+
- Closed-world over 11 classes — every input is forced into one of them. There
|
| 92 |
+
is no "none of the above", so out-of-distribution images get confident and
|
| 93 |
+
meaningless labels.
|
| 94 |
+
- Several classes are visually similar under poor lighting or low resolution;
|
| 95 |
+
treat single-image predictions as indicative.
|