Skip to content

Commit

Permalink
uploading app.py with tensor mode and README
Browse files Browse the repository at this point in the history
  • Loading branch information
Velvetklr committed Jan 25, 2024
1 parent c01797f commit 6c50101
Show file tree
Hide file tree
Showing 14 changed files with 406 additions and 6 deletions.
Binary file modified .DS_Store
Binary file not shown.
54 changes: 51 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
![app_image](https://www.tetratech.com/wp-content/uploads/2023/10/Evaluating-the-Risk-of-Microplastics-in-Coastal-Waters-One-Water.jpg)

# P4_MicroPystics

## Description
Using Machine Learning, Image Recognition, and Computer Vision to detect microplastics in water samples.

**Original Data Source:**
Microplastic Dataset for Computer Vision, MOHAMADREZA MOMENI
https://www.kaggle.com/datasets/imtkaggleteam/microplastic-dataset-for-computer-vision
## Table of Contents
- [Installation](#installation)
- [Data](#data)
- [License](#license)
- [Dashboard](#dashboard)
- [Contact](#contact)

## Installation
To run the model in Google Colab we installed:
- tensorflow
- drive
- numpy
- os
- skimage.color
- matplotlib

For the Flask API to run the following was installed:
- os
- flask
- tensorflow
- Pillow
- numpy

# Data

## Source Data
- #### [Microplastic Dataset for Computer Vision, MOHAMADREZA MOMENI:](https://www.kaggle.com/datasets/imtkaggleteam/microplastic-dataset-for-computer-vision)
- #### Place holder for Aspen data

# Results and evaluation


## License
MIT

## Dashboard
#### [Tableu Dashboard]

## Contact
If there are any questions or concerns, we can be reached at:
##### [github: aspenjack](https://github.com/aspenjack)
##### [github: arpitas0690](https://github.com/arpitas0690)
##### [github: S-Bonillas](https://github.com/S-Bonillas)
##### [github: Sequoiabm](https://github.com/Sequoiabm)
##### [github: velvetklr](https://github.com/velvetklr)


Binary file added Resources/.DS_Store
Binary file not shown.
53 changes: 50 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,62 @@
# Import libraries
import os
from flask import Flask, render_template, request, url_for, redirect, flash, jsonify
import pickle
import tensorflow as tf
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import load_img
from tensorflow.keras.applications.vgg16 import preprocess_input
from tensorflow.keras.preprocessing import image
from PIL import Image
import numpy as np

# Create upload file path

upload_folder = "static/upload"
temp = "model/"

# Create an app
app = Flask(__name__)
app.config['upload_folder'] = upload_folder

# Load the model
#model = pickle.load(open('./model.pkl','rb'))
#model_path = os.path.abspath("model/microP.h5")
#model = load_model(model_path)
#model = load_model(model_path)
model = tf.keras.models.load_model("model/saved_model")




@app.route('/')
def home():
return render_template("index.html")


def preprocess_image(image_path):
# Read the image using OpenCV
image = Image.open(image_path).convert("RGB")

# print("Image Channels (PIL):", image.mode)
# print("Image Shape (PIL):", np.array(image).shape)

# Resize the image to (150, 150)
image = tf.image.resize(image, (128, 128))

# Convert the image to a NumPy array
image_array = np.array(image)

# Normalize the image
image_array = image_array / 255.0 # Assuming pixel values are in the range [0, 255]

image_array = np.transpose(image_array, (0, 1, 2))

# Add batch dimension
image_array = np.expand_dims(image_array, axis=0)

image_tensor = tf.convert_to_tensor(image_array, dtype=tf.float32)

return image_tensor

@app.route('/predict',methods=['POST','GET'])
def predict():
# Get the data from the POST request.
Expand All @@ -34,7 +72,16 @@ def predict():

print("Path:",path)

return render_template("results.html", image_path=path)
input_data = preprocess_image(path)
predictions = model.predict(input_data)

binary_predictions = (predictions > 0.5).astype(int)

class_predict = "Clean" if binary_predictions == 0 else "Microplastics"

return render_template("results.html", image_path=path, class_predict=class_predict)

return render_template('index.html')

if __name__ == '__main__':
app.run(debug=True,port=5001)
Binary file added model/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions model/saved_model/fingerprint.pb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�碢��ǰ"����প�)�������Π ��އ�����(��������x2
301 changes: 301 additions & 0 deletions model/saved_model/keras_metadata.pb

Large diffs are not rendered by default.

Binary file added model/saved_model/saved_model.pb
Binary file not shown.
Binary file not shown.
Binary file added model/saved_model/variables/variables.index
Binary file not shown.
Binary file added static/.DS_Store
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed static/upload/download.jpg
Binary file not shown.
3 changes: 3 additions & 0 deletions templates/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<h1>Wow, Look at those Results!</h1>
<img src="{{ image_path }}" alt="Uploaded Image">

<h2> Prediction: </h2>
<p>{{ class_predict }}</p>

</div>

</body>
Expand Down

0 comments on commit 6c50101

Please sign in to comment.