--- license: apache-2.0 language: - en metrics: - accuracy library_name: keras pipeline_tag: image-classification tags: - astronomy widget: - src: https://huggingface.co/IT-Guy007/AstroVisionV1/blob/main/images/spiral-example.png output: text: one_one --- # Model Card for Model ID This model classifies RGB images to the 2 classes, Spheroid or Spiral. ## Model Details ### Model Description - **Developed by:** Jeroen den Otter, Michael Rutkowski - **Funded by:** NASA - **Model type:** Keras Sequential - **License:** Apache2 ### Model Sources - **Repository:** https://www.kaggle.com/c/galaxy-zoo-the-galaxy-challenge/overview ## Uses The model can be used for identifying different galaxies from cutout images. It does not provide bounding boxes, so multiple galaxies in 1 image is not desired. ## How to Get Started with the Model Use the code below to get started with the model. ```python model = tf.keras.models.load_model('model.keras') prediction = model.predict(image) print(prediction) ``` ## Training Details ### Training Data From the kaggle zoo challenge the classes one_one(Spheroid) 80%> and one_two(Spiral) 90%> are used. Furthermore are the image segmented for noice removal ### Training Procedure ```python train_ds, val_ds = image_dataset_from_directory( dataset_directory, validation_split=0.2, subset="both", seed=123, image_size=(200, 200), batch_size=32, color_mode='grayscale' ) data_augmentation = tf.keras.Sequential([ tf.keras.layers.RandomFlip('horizontal'), tf.keras.layers.RandomRotation(0.2), tf.keras.layers.RandomZoom(0.2), tf.keras.layers.RandomContrast(0.2), tf.keras.layers.RandomBrightness(0.2), tf.keras.layers.GaussianNoise(0.1), ]) AUTOTUNE = tf.data.AUTOTUNE train_ds = train_ds.cache().shuffle(1000).prefetch(buffer_size=AUTOTUNE) val_ds = val_ds.cache().prefetch(buffer_size=AUTOTUNE) model = tf.keras.Sequential([ data_augmentation, tf.keras.layers.Rescaling(1./255, input_shape=(200, 200, 1)), tf.keras.layers.Conv2D(32, (3, 3), activation='relu'), tf.keras.layers.MaxPooling2D(2, 2), tf.keras.layers.Conv2D(64, (3, 3), activation='relu'), tf.keras.layers.MaxPooling2D(2, 2), tf.keras.layers.Conv2D(128, (3, 3), activation='relu'), tf.keras.layers.MaxPooling2D(2, 2), tf.keras.layers.Conv2D(128, (3, 3), activation='relu'), tf.keras.layers.MaxPooling2D(2, 2), tf.keras.layers.Flatten(), tf.keras.layers.Dropout(0.5), tf.keras.layers.Dense(512, activation='relu'), tf.keras.layers.Dense(2, activation='softmax') ]) model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001), loss='sparse_categorical_crossentropy', metrics=['accuracy']) ``` ## Evaluation ### Testing Data, Factors & Metrics ### Model summary ```text ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ Layer (type) ┃ Output Shape ┃ Param # ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ sequential (Sequential) │ (None, 200, 200, 1) │ 0 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ rescaling (Rescaling) │ (None, 200, 200, 1) │ 0 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ conv2d (Conv2D) │ (None, 198, 198, 64) │ 640 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ max_pooling2d (MaxPooling2D) │ (None, 99, 99, 64) │ 0 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ conv2d_1 (Conv2D) │ (None, 97, 97, 128) │ 73,856 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ max_pooling2d_1 (MaxPooling2D) │ (None, 48, 48, 128) │ 0 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ conv2d_2 (Conv2D) │ (None, 46, 46, 256) │ 295,168 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ max_pooling2d_2 (MaxPooling2D) │ (None, 23, 23, 256) │ 0 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ conv2d_3 (Conv2D) │ (None, 21, 21, 256) │ 590,080 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ max_pooling2d_3 (MaxPooling2D) │ (None, 10, 10, 256) │ 0 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ flatten (Flatten) │ (None, 25600) │ 0 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ dropout (Dropout) │ (None, 25600) │ 0 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ dense (Dense) │ (None, 1024) │ 26,215,424 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ dense_1 (Dense) │ (None, 2) │ 2,050 │ └─────────────────────────────────┴────────────────────────┴───────────────┘ Total params: 81,531,656 (311.02 MB) Trainable params: 27,177,218 (103.67 MB) Non-trainable params: 0 (0 MB) Optimizer params 54,354,438 (207.35 MB) ``` ### Loss and Accuracy ![Loss and Accuracy](./images/loss-accuracy.png) ### Results | | precision | recall | f1-score | support | |-----------|-----------|--------|----------|---------| | one_one | 0.98 | 0.98 | 0.96 | 1637 | | one_two | 0.98 | 0.98 | 0.98 | 1740 | | accuracy | | | 0.96 | 3377 | | macro avg | 0.98 | 0.98 | 0.98 | 3377 | | weighted avg| 0.98 | 0.98 | 0.98 | 3377 | ## Environmental Impact - **Hardware Type:** M3 Pro - **Hours used:** 72