MA29 commited on
Commit
41bf89a
·
verified ·
1 Parent(s): 2b4ef90

Add measured ensemble test accuracy (0.9910)

Browse files
Files changed (1) hide show
  1. README.md +119 -95
README.md CHANGED
@@ -1,95 +1,119 @@
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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 split: 446 images, reconstructed from the training notebook's
79
+ `image_dataset_from_directory(validation_split=0.3, seed=42)` then
80
+ `temp_ds.skip(14)`. Per-class supports match the notebook's own reports.
81
+
82
+ | Model | Test accuracy |
83
+ |---|---|
84
+ | DenseNet201 branch alone | 0.9888 |
85
+ | VGG19 branch alone | 0.9888 |
86
+ | **Ensemble (this model)** | **0.9910** (442/446) |
87
+
88
+ Macro F1 0.990, weighted F1 0.991, mean confidence 98.4%.
89
+
90
+ | class | precision | recall | f1 | support |
91
+ |---|---|---|---|---|
92
+ | black_hole | 1.000 | 0.952 | 0.976 | 21 |
93
+ | earth | 1.000 | 1.000 | 1.000 | 35 |
94
+ | galaxy | 0.962 | 1.000 | 0.980 | 25 |
95
+ | jupiter | 1.000 | 1.000 | 1.000 | 39 |
96
+ | mars | 0.978 | 0.957 | 0.967 | 46 |
97
+ | mercury | 1.000 | 1.000 | 1.000 | 50 |
98
+ | neptune | 1.000 | 1.000 | 1.000 | 52 |
99
+ | pluto | 1.000 | 1.000 | 1.000 | 37 |
100
+ | saturn | 1.000 | 1.000 | 1.000 | 41 |
101
+ | uranus | 1.000 | 1.000 | 1.000 | 48 |
102
+ | venus | 0.962 | 0.981 | 0.971 | 52 |
103
+
104
+ All four errors: three venus/mars confusions, and one black_hole predicted as
105
+ galaxy at 100% confidence — worth knowing that high confidence is not a
106
+ reliable correctness signal here.
107
+
108
+ Note the test split is drawn from the same curated dataset as training, so this
109
+ figure reflects in-distribution performance only.
110
+
111
+ ## Limitations
112
+
113
+ - Trained on a curated, fairly clean dataset of planet and deep-sky imagery; it
114
+ has not been evaluated on telescope captures, noisy frames or unusual crops.
115
+ - Closed-world over 11 classes — every input is forced into one of them. There
116
+ is no "none of the above", so out-of-distribution images get confident and
117
+ meaningless labels.
118
+ - Several classes are visually similar under poor lighting or low resolution;
119
+ treat single-image predictions as indicative.