Skip to content

Deep learning model that predicts the phase of the moon πŸŒ’πŸŒ“πŸŒ”πŸŒ•πŸŒ–πŸŒ—πŸŒ˜

Notifications You must be signed in to change notification settings

farzeennimran/Moon-Phases-Prediction-Using-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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

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

model

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.

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
history = model.fit(X_train, y_train, epochs=20, validation_data=(X_test, y_test))

epochs

Evaluation

The model's performance is evaluated on the test set.

loss, accuracy = model.evaluate(X_test, y_test)
print("Test Accuracy:", accuracy)

acc

Making Predictions

You can use the trained model to predict the moon phase of new images.

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

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

test_result

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

test1_result

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

test2_result

Results

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

accuracy

loss