File size: 2,563 Bytes
b8e4c73
 
 
 
 
 
 
 
 
 
 
 
6370dc6
 
 
 
 
b8e4c73
6370dc6
b8e4c73
 
 
 
 
 
 
6370dc6
b8e4c73
6370dc6
 
 
b8e4c73
6370dc6
 
 
 
 
 
 
b8e4c73
 
3bd8299
5afe1da
3bd8299
5afe1da
3bd8299
5afe1da
3bd8299
5afe1da
3bd8299
5afe1da
6370dc6
 
b8e4c73
 
6370dc6
9f412c6
6370dc6
5afe1da
 
b8e4c73
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# All imports
import streamlit as st
import tensorflow as tf
from PIL import Image
import io
import numpy as np

def load_image():
    uploaded_file = st.file_uploader(label='Pick an image to test')
    if uploaded_file is not None:
        image_data = uploaded_file.getvalue()
        st.image(image_data)
        img = Image.open(io.BytesIO(image_data))
        img = img.resize((224,224))
        return img
    else:
        return None

def load_model():
    model_name = 'Model/model.h5'
    model = tf.keras.models.load_model(model_name) 
    return model

def load_labels():
    with open('Oxford-102_Flower_dataset_labels.txt', 'r') as file:
        data = file.read().splitlines()
    return data

def predict(model, labels, img):
    img_array = tf.keras.preprocessing.image.img_to_array(img)
    img_array = tf.expand_dims(img_array, 0)  # Create a batch

    prediction = model.predict(img_array)
    predicted_class = np.argmax(prediction[0], axis=-1)
    
    flower = labels[predicted_class]
    closeness = np.round(prediction[0][predicted_class] * 100, 2)
    
    return flower, closeness

def main():
    st.title('Flower Classification Using Deep Learning ')
    st.markdown('### NAME:')
    st.write('TOLULOPE')
    st.markdown('### CLASS:')
    st.write('HND2')
    st.markdown('### LEVEL:')
    st.write('400L')
    st.markdown('---')
    st.write("This is a demo of an image classification model trained on the Oxford Flower Dataset. The Oxford Flower Dataset, consisting of 102 flower categories. The images have large scale, pose and light variations. In addition, there are categories that have large variations within the category and several very similar categories. The dataset is visualized using isomap with shape and colour features. Link to the dataset is available  @ https://www.kaggle.com/datasets/yousefmohamed20/oxford-102-flower-dataset.. . To test the model, upload an image of a flower and click the 'Run on image' button.")
    st.markdown('---')
    model = load_model()
    labels = load_labels()
    image = load_image()
    result = st.button('Run on image')
    if result and image is not None:
        st.markdown('**_Calculating results..._**')
        flower, closeness = predict(model, labels, image)
        st.markdown(f'<h4 style="color:blue;">Flower Type: <span style="color:black;">{flower}</span></h4>', unsafe_allow_html=True)
        st.markdown(f'<h4 style="color:green;">Closeness: <span style="color:black;">{closeness}%</span></h4>', unsafe_allow_html=True)

if __name__ == '__main__':
    main()