ibrahim yıldız commited on
Commit
49be2d3
·
verified ·
1 Parent(s): b9ac594

Upload 8 files

Browse files
Files changed (8) hide show
  1. Dandelion2.jpg +0 -0
  2. app.py +57 -0
  3. daisy.jpg +0 -0
  4. dandelion1.jpg +0 -0
  5. requirements.txt +4 -0
  6. rose.jpg +0 -0
  7. sunflower.jpeg +0 -0
  8. tulip.jpg +0 -0
Dandelion2.jpg ADDED
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from tensorflow.keras.layers import Input
4
+ from tensorflow.keras.models import Model
5
+ from tensorflow.keras.preprocessing.image import img_to_array
6
+ import numpy as np
7
+ from PIL import Image
8
+
9
+ # Load the TensorFlow SavedModel as a layer
10
+ bit_model = tf.keras.layers.TFSMLayer('flower_BiT_model', call_endpoint='serving_default')
11
+
12
+ # Create a new Keras model
13
+ inputs = Input(shape=(224, 224, 3))
14
+ outputs = bit_model(inputs)
15
+ model = Model(inputs=inputs, outputs=outputs)
16
+
17
+ # Class labels (make sure they're in the same order as during training)
18
+ class_labels = ['dandelion','daisy', 'tulip', 'sunflower', 'rose']
19
+
20
+ def preprocess_image(img):
21
+ img = img.resize((224, 224))
22
+ img_array = img_to_array(img)
23
+ img_array = np.expand_dims(img_array, axis=0)
24
+ img_array /= 255.0
25
+ return img_array
26
+
27
+ def predict_image(image):
28
+ img_array = preprocess_image(image)
29
+ prediction = model(img_array, training=False)
30
+ if isinstance(prediction, dict):
31
+ prediction = list(prediction.values())[0]
32
+ predicted_class_index = np.argmax(prediction[0].numpy()) # Assuming the output is a probability distribution or logits
33
+ predicted_class = class_labels[predicted_class_index]
34
+ return predicted_class
35
+
36
+ # Streamlit UI
37
+ st.title("5 Flower Classification 💐")
38
+ st.write("This model is trained using Big Transfer (BiT) with 98% accuracy.")
39
+
40
+ images = ["daisy.jpg", "dandelion1.jpg", "rose.jpg", "sunflower.jpeg", "dandelion2.jpg", "tulip.jpg"]
41
+ captions = ["daisy", "dandelion", "rose", "sunflower", "dandelion", "tulip"]
42
+ current_row = 0
43
+ for _ in range(2):
44
+ cols = st.columns(3)
45
+ for col, image, caption in zip(cols, images[current_row:current_row+3], captions[current_row:current_row+3]):
46
+ col.image(image, caption=caption)
47
+ current_row += 3
48
+
49
+ st.write('Upload a flower image from the web or use these sample images above. Lets see if it is a daisy, dandelion, rose, sunflower, or tulip!')
50
+
51
+ uploaded_file = st.file_uploader("Choose an image...", type="jpg")
52
+
53
+ if uploaded_file is not None:
54
+ image = Image.open(uploaded_file)
55
+ st.image(image, caption='Uploaded Image.', use_column_width=True)
56
+ label = predict_image(image)
57
+ st.header(f"This is ***{label}***!")
daisy.jpg ADDED
dandelion1.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ tensorflow
3
+ numpy
4
+ Pillow
rose.jpg ADDED
sunflower.jpeg ADDED
tulip.jpg ADDED