Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

w #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

w #2

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added CFM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Deep-Learning_CNN.pptx
Binary file not shown.
1 change: 1 addition & 0 deletions Image processing.ipynb

Large diffs are not rendered by default.

86 changes: 0 additions & 86 deletions README.md

This file was deleted.

Binary file added Report.docx
Binary file not shown.
Binary file added Report_Image_Processing_project.pdf
Binary file not shown.
66 changes: 66 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from flask import Flask, request, render_template
import tensorflow as tf
import numpy as np
from PIL import Image

# Initialize the Flask app (must be before defining routes)
app = Flask(__name__)

# Load your pre-trained model (make sure to specify the correct path)
model = tf.keras.models.load_model("model.h5") # Adjust to your model's path

# Class labels (for example, CIFAR-10)
labels = [
"airplane", "automobile", "bird", "cat", "deer",
"dog", "frog", "horse", "ship", "truck"
]

# Define a route for the homepage
@app.route('/')
def home():
return render_template('upload.html') # Render the upload.html template

# Define a route for handling image uploads and predictions
@app.route('/predict', methods=['POST'])
def predict():
if 'file' not in request.files:
return "No file uploaded. Please select a file."

file = request.files['file']

if file.filename == '':
return "No file selected. Please select a valid image file."

if file:
try:
# Open the image and convert to RGB to ensure it has 3 channels
img = Image.open(file).convert('RGB')

# Resize to match the model's input size
img = img.resize((32, 32))

# Convert the image to a NumPy array and normalize it
img_array = np.array(img)
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
img_array = img_array / 255.0 # Normalize the image

# Make predictions
predictions = model.predict(img_array)
predicted_class = np.argmax(predictions)
predicted_label = labels[predicted_class]

# Get probabilities for each class
probabilities = predictions[0]
class_probabilities = {label: f"{prob:.2f}%" for label, prob in zip(labels, probabilities * 100)}

# Return the predicted class and probabilities
return render_template('result.html', predicted_label=predicted_label, class_probabilities=class_probabilities)

except Exception as e:
return f"Error processing the image: {str(e)}"

return "Something went wrong. Please try again."

# Run the app
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)
Binary file added batches.meta
Binary file not shown.
Binary file added data_batch_1
Binary file not shown.
Binary file added data_batch_2
Binary file not shown.
Binary file added data_batch_3
Binary file not shown.
Binary file added data_batch_4
Binary file not shown.
Binary file added data_batch_5
Binary file not shown.
Binary file added model.h5
Binary file not shown.
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Flask==2.1.1
tensorflow==2.17.0
pillow==10.0.0
numpy==1.26.4
Werkzeug==2.0.3 # Downgraded for Flask compatibility
36 changes: 36 additions & 0 deletions result
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prediction Result</title>
<!-- Bootstrap CSS for styling -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card shadow-sm">
<div class="card-body text-center">
<h3 class="card-title">Prediction Result</h3>
<p class="lead">Predicted Class: <strong>{{ predicted_label }}</strong></p>
<h5>Class Probabilities:</h5>
<ul class="list-group">
{% for label, probability in class_probabilities.items() %}
<li class="list-group-item d-flex justify-content-between align-items-center">
{{ label }}
<span class="badge bg-primary rounded-pill">{{ probability }}</span>
</li>
{% endfor %}
</ul>
<a href="/" class="btn btn-primary mt-3">Upload Another Image</a>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap JS (optional) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions static/css/style.css.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
body {
background-color: #f7f7f7;
font-family: Arial, sans-serif;
}

.card {
margin-top: 50px;
padding: 20px;
}

h3 {
margin-bottom: 20px;
}

.btn-primary {
background-color: #007bff;
border-color: #007bff;
}

.btn-primary:hover {
background-color: #0056b3;
border-color: #004085;
}
Loading