https://github.com/farzeennimran/moon-phases-prediction-using-ai
Deep learning model that predicts the phase of the moon 🌒🌓🌔🌕🌖🌗🌘
https://github.com/farzeennimran/moon-phases-prediction-using-ai
artificial-intelligence cnn cv2-library data-science data-visualization deep-learning keras matplotlib numpy opencv predictive-modeling python tensorflow
Last synced: 4 months ago
JSON representation
Deep learning model that predicts the phase of the moon 🌒🌓🌔🌕🌖🌗🌘
- Host: GitHub
- URL: https://github.com/farzeennimran/moon-phases-prediction-using-ai
- Owner: farzeennimran
- Created: 2024-07-01T12:43:04.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-25T12:39:53.000Z (over 1 year ago)
- Last Synced: 2025-05-16T18:44:10.246Z (about 1 year ago)
- Topics: artificial-intelligence, cnn, cv2-library, data-science, data-visualization, deep-learning, keras, matplotlib, numpy, opencv, predictive-modeling, python, tensorflow
- Language: Jupyter Notebook
- Homepage:
- Size: 17.4 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Moon Phase Prediction
This repository contains code for a deep learning model that predicts the phase of the moon from an input image. The model is built using Convolutional Neural Networks (CNNs) and classifies images into one of the eight moon phases.
## Table of Contents
- [Overview](#overview)
- [Dataset](#dataset)
- [Model Architecture](#model-architecture)
- [Training](#training)
- [Evaluation](#evaluation)
- [Making Predictions](#Making-Predictions)
- [Results](#results)
## Overview
The goal of this project is to accurately classify images of the moon into one of eight phases:
1. New Moon
2. Waxing Crescent
3. First Quarter
4. Waxing Gibbous
5. Full Moon
6. Waning Gibbous
7. Last Quarter
8. Waning Crescent
## Dataset
Initially the datatset was taken from kaggle that consisted of images of the moon. I labeled the images with their respective phases, such that, images are organized in subdirectories named after the phases. Ensure that the dataset is unzipped and placed in the correct directory structure.
## Model Architecture
The model is a Convolutional Neural Network (CNN) with the following architecture:
- Convolutional layers with ReLU activation
- MaxPooling layers
- Flatten layer
- Dense layers with ReLU activation
- Dropout layer
- Output layer with softmax activation
```python
model = Sequential([
Conv2D(32, (3, 3), activation='relu', input_shape=(IMG_SIZE, IMG_SIZE, 3)),
MaxPooling2D(2, 2),
Conv2D(64, (3, 3), activation='relu'),
MaxPooling2D(2, 2),
Flatten(),
Dense(128, activation='relu'),
Dropout(0.5),
Dense(len(CATEGORIES), activation='softmax')
])
model.summary()
```

## Training
The images are loaded, resized, and normalized. The labels are converted to categorical format. The dataset is split into training and testing sets. The model is then compiled and trained.
```python
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
history = model.fit(X_train, y_train, epochs=20, validation_data=(X_test, y_test))
```

## Evaluation
The model's performance is evaluated on the test set.
```python
loss, accuracy = model.evaluate(X_test, y_test)
print("Test Accuracy:", accuracy)
```

## Making Predictions
You can use the trained model to predict the moon phase of new images.
```python
def predict_moon_phase(model, img_path):
img = cv2.imread(img_path)
img_resized = cv2.resize(img, (IMG_SIZE, IMG_SIZE))
img_normalized = img_resized / 255.0
img_reshaped = np.reshape(img_normalized, (1, IMG_SIZE, IMG_SIZE, 3))
prediction = model.predict(img_reshaped)
return CATEGORIES[np.argmax(prediction)]
```
Testing model on different images
```python
img_path = 'test.jpg'
predicted_phase = predict_moon_phase(model, img_path)
print("The predicted moon phase is:", predicted_phase)
```

```python
img_path = 'test1.jpg'
predicted_phase = predict_moon_phase(model, img_path)
print("The predicted moon phase is:", predicted_phase)
```

```python
img_path = 'test2.jpg'
predicted_phase = predict_moon_phase(model, img_path)
print("The predicted moon phase is:", predicted_phase)
```

## Results
The training and validation loss and accuracy are plotted to visualize the model's performance over epochs.

