shamimjony1000 commited on
Commit
cb5cdea
1 Parent(s): 022cc41

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +50 -0
  2. my_cnn.h5 +3 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import streamlit as st
3
+ from tensorflow.keras.preprocessing import image
4
+ from tensorflow.keras.models import load_model
5
+ from tensorflow.keras.applications.resnet50 import preprocess_input
6
+ import matplotlib.pyplot as plt
7
+
8
+ # Load the trained model
9
+ model_path = '/content/my_cnn.h5' # or '/content/my_model.keras'
10
+ model = load_model(model_path)
11
+
12
+ # Preprocess the image
13
+ def preprocess_image(img):
14
+ img_array = image.img_to_array(img)
15
+ img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
16
+ img_array = preprocess_input(img_array) # Ensure correct preprocessing for ResNet50
17
+ return img_array
18
+
19
+ # Make predictions and map to class labels
20
+ def classify_image(img):
21
+ img_array = preprocess_image(img)
22
+ predictions = model.predict(img_array)
23
+ predicted_class = np.argmax(predictions, axis=1) # Get the index of the highest probability
24
+
25
+ class_labels = {0: 'Aedes Aegypti', 1: 'Anopheles Stephensi', 2: 'Culex Quinquefasciatus'}
26
+ species = class_labels.get(predicted_class[0], "Unknown")
27
+
28
+ return species, predictions
29
+
30
+ # Streamlit application
31
+ def main():
32
+ st.title("Mosquito Species Classification")
33
+ st.write("Upload a mosquito image to classify its species.")
34
+
35
+ # File uploader for image input
36
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
37
+
38
+ if uploaded_file is not None:
39
+ # Load the image for display
40
+ img = image.load_img(uploaded_file, target_size=(224, 224))
41
+ st.image(img, caption='Uploaded Image', use_column_width=True)
42
+
43
+ # Classify the image
44
+ result, probabilities = classify_image(img)
45
+ st.write(f'Predicted mosquito species: **{result}**')
46
+ st.write(f'Prediction probabilities: {probabilities}')
47
+
48
+ # Run the app
49
+ if __name__ == "__main__":
50
+ main()
my_cnn.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0d4bf561354e781adaec7cdad52cd4e89342c5e517253e0c98526ad9a60ca410
3
+ size 22384944
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit==1.24.0
2
+ tensorflow==2.13.0
3
+ numpy==1.23.5
4
+ Pillow==10.0.0
5
+ matplotlib==3.7.2