itsanmolgupta commited on
Commit
05a860d
·
verified ·
1 Parent(s): f27d3bd
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. app.py +61 -0
  3. model.keras +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from PIL import Image
5
+ import io
6
+
7
+ # Load your pre-trained model
8
+ model = tf.keras.models.load_model('model.keras')
9
+
10
+ # Define the image preprocessing function
11
+ # Define the image preprocessing function
12
+ def preprocess_image(image):
13
+ # Convert image to RGB if it's grayscale
14
+ if image.mode != 'RGB':
15
+ image = image.convert('RGB')
16
+
17
+ # Resize and preprocess the image
18
+ image = image.resize((224, 224)) # Adjust the size as per your model's requirement
19
+ image_array = np.array(image) / 255.0 # Normalize the image
20
+ image_array = np.expand_dims(image_array, axis=0) # Add batch dimension
21
+ return image_array
22
+
23
+ # Define the class labels
24
+ class_labels = ['Atelectasis', 'Cardiomegaly', 'Consolidation', 'Edema', 'Effusion',
25
+ 'Emphysema', 'Fibrosis', 'Infiltration', 'Mass',
26
+ 'Nodule', 'Pleural_Thickening', 'Pneumothorax']
27
+ # class_labels = ["Class1", "Class2", "Class3", "Class4", "Class5"] # Update with actual class names
28
+
29
+ # Streamlit app
30
+ st.title("Image Classification with Grad-CAM")
31
+
32
+ st.write("Upload an image to get predictions:")
33
+
34
+ # Upload image
35
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
36
+
37
+ if uploaded_file is not None:
38
+ # Read and display the image
39
+ image = Image.open(uploaded_file)
40
+ st.image(image, caption='Uploaded Image', use_column_width=True)
41
+
42
+ # Preprocess the image
43
+ preprocessed_image = preprocess_image(image)
44
+
45
+ # Make predictions
46
+ predictions = model.predict(preprocessed_image)[0]
47
+
48
+ # Get top 3 predictions with probability greater than 0.5
49
+ top_predictions = [(label, prob) for label, prob in zip(class_labels, predictions) if prob > 0.5]
50
+ top_predictions = sorted(top_predictions, key=lambda x: x[1], reverse=True)[:3]
51
+
52
+ # Display results
53
+ st.write("Predictions with probability greater than 0.5:")
54
+ for label, prob in top_predictions:
55
+ st.write(f"{label}: {prob*100:.2f}%")
56
+ percentage = int(prob * 100)
57
+ # st.progress(prob)
58
+ st.progress(percentage)
59
+
60
+ if not top_predictions:
61
+ st.write("No predictions with probability greater than 0.5.")
model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fb2bf1ac2b5c0692ab11f325750c71af7bd4417cd4571f00fe29293bb056a09
3
+ size 88710372