Senasu commited on
Commit
ca717aa
·
verified ·
1 Parent(s): 49a5083

Upload Main Files

Browse files
Files changed (3) hide show
  1. app.py +86 -0
  2. cnn_model.h5 +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from tensorflow.keras.models import load_model
3
+ from PIL import Image
4
+ import numpy as np
5
+ import matplotlib.pyplot as plt
6
+ import seaborn as sns
7
+
8
+ model = load_model('cnn_model.h5')
9
+
10
+ def process_image(img):
11
+ img = img.convert('RGB')
12
+ img = img.resize((64, 64))
13
+ img = np.array(img)
14
+ img = img / 255.0
15
+ img = np.expand_dims(img, axis=0)
16
+ return img
17
+
18
+ st.title('Large Scale Fish Detection :fish:')
19
+ st.write('Upload a fish image and the model will detect type of fish.')
20
+
21
+ file = st.file_uploader('Select an image', type=['jpg', 'jpeg', 'png'])
22
+
23
+ if file is not None:
24
+ # Display the uploaded image
25
+ img = Image.open(file)
26
+ st.image(img, caption='Uploaded Image')
27
+
28
+ # Preprocess the image
29
+ image = process_image(img)
30
+
31
+ # Model prediction
32
+ with st.spinner('Classifying the image...'):
33
+ predictions = model.predict(image)
34
+ predicted_class = np.argmax(predictions)
35
+ predicted_prob = predictions[0][predicted_class]
36
+
37
+ # Class names for prediction
38
+ class_names = ['Hourse Mackerel',
39
+ 'Black Sea Sprat',
40
+ 'Sea Bass',
41
+ 'Red Mullet',
42
+ 'Trout',
43
+ 'Striped Red Mullet',
44
+ 'Shrimp',
45
+ 'Gilt-Head Bream',
46
+ 'Red Sea Bream']
47
+
48
+ # Display the prediction
49
+ st.subheader(f"Prediction: {class_names[predicted_class]}")
50
+ st.write(f"Confidence: {predicted_prob * 100:.2f}%")
51
+
52
+ # Display prediction probabilities
53
+ st.write("Prediction Probabilities for Each Class:")
54
+ probabilities = predictions[0]
55
+ prob_dict = {class_names[i]: probabilities[i] for i in range(len(class_names))}
56
+
57
+ # Plot settings
58
+ sns.set(style="white") # Clean style with no grid background
59
+
60
+ # Create the figure
61
+ fig, ax = plt.subplots(figsize=(12, 8)) # Adjust figure size for better readability
62
+
63
+ # Plot the bar chart
64
+ ax.bar(list(prob_dict.keys()), list(prob_dict.values()), color='#0367A6', edgecolor='black')
65
+ ax.set_ylabel('Probability', fontsize=14)
66
+ ax.set_title('Prediction Probabilities for Each Class', fontsize=20)
67
+
68
+ # Rotate x-axis labels for better readability
69
+ plt.xticks(rotation=90, ha='right', fontsize=15)
70
+
71
+ # Annotate bars with percentage values
72
+ for index, value in enumerate(prob_dict.values()):
73
+ ax.text(index, value, f'{value * 100:.0f}%', va='bottom', ha='center', fontsize=10)
74
+
75
+ # Remove background grid and spines
76
+ ax.spines['top'].set_visible(False)
77
+ ax.spines['right'].set_visible(False)
78
+ ax.spines['left'].set_visible(False)
79
+ ax.spines['bottom'].set_visible(False)
80
+ ax.grid(False)
81
+
82
+ # Adjust layout to prevent clipping
83
+ fig.tight_layout()
84
+
85
+ # Display the plot in Streamlit
86
+ st.pyplot(fig)
cnn_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:04be5d2aa066ed5e73b0314b20ca0cfe5555605adac226f74ed224dd25db30f7
3
+ size 134069296
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ tensorflow
3
+ matplotlib
4
+ seaborn