Nihal Arya commited on
Commit
b8e4c73
·
1 Parent(s): d6bf786

files added to push to huggingfaces

Browse files
Files changed (3) hide show
  1. Model/model.h5 +3 -0
  2. Oxford-102_Flower_dataset_labels.txt +102 -0
  3. app.py +75 -0
Model/model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:73ed908fb076b4562d9fa52f9b23a363e891154fd7ef11c2bbb82d10a57a3956
3
+ size 37247336
Oxford-102_Flower_dataset_labels.txt ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pink primrose
2
+ hard-leaved pocket orchid
3
+ canterbury bells
4
+ sweet pea
5
+ english marigold
6
+ tiger lily
7
+ moon orchid
8
+ bird of paradise
9
+ monkshood
10
+ globe thistle
11
+ snapdragon
12
+ colt's foot
13
+ king protea
14
+ spear thistle
15
+ yellow iris
16
+ globe-flower
17
+ purple coneflower
18
+ peruvian lily
19
+ balloon flower
20
+ giant white arum lily
21
+ fire lily
22
+ pincushion flower
23
+ fritillary
24
+ red ginger
25
+ grape hyacinth
26
+ corn poppy
27
+ prince of wales feathers
28
+ stemless gentian
29
+ artichoke
30
+ sweet william
31
+ carnation
32
+ garden phlox
33
+ love in the mist
34
+ mexican aster
35
+ alpine sea holly
36
+ ruby-lipped cattleya
37
+ cape flower
38
+ great masterwort
39
+ siam tulip
40
+ lenten rose
41
+ barbeton daisy
42
+ daffodil
43
+ sword lily
44
+ poinsettia
45
+ bolero deep blue
46
+ wallflower
47
+ marigold
48
+ buttercup
49
+ oxeye daisy
50
+ common dandelion
51
+ petunia
52
+ wild pansy
53
+ primula
54
+ sunflower
55
+ pelargonium
56
+ bishop of llandaff
57
+ gaura
58
+ geranium
59
+ orange dahlia
60
+ pink-yellow dahlia
61
+ cautleya spicata
62
+ japanese anemone
63
+ black-eyed susan
64
+ silverbush
65
+ californian poppy
66
+ osteospermum
67
+ spring crocus
68
+ bearded iris
69
+ windflower
70
+ tree poppy
71
+ gazania
72
+ azalea
73
+ water lily
74
+ rose
75
+ thorn apple
76
+ morning glory
77
+ passion flower
78
+ lotus
79
+ toad lily
80
+ anthurium
81
+ frangipani
82
+ clematis
83
+ hibiscus
84
+ columbine
85
+ desert-rose
86
+ tree mallow
87
+ magnolia
88
+ cyclamen
89
+ watercress
90
+ canna lily
91
+ hippeastrum
92
+ bee balm
93
+ ball moss
94
+ foxglove
95
+ bougainvillea
96
+ camellia
97
+ mallow
98
+ mexican petunia
99
+ bromelia
100
+ blanket flower
101
+ trumpet creeper
102
+ blackberry lily
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # All imports
2
+ import streamlit as st
3
+ import tensorflow as tf
4
+ from tensorflow import keras
5
+ from PIL import Image
6
+ from tensorflow.keras.preprocessing import image
7
+ import io
8
+ from collections import Counter
9
+ import numpy as np
10
+
11
+ def load_image():
12
+ uploaded_file = st.file_uploader(label='Pick an image to test')
13
+ if uploaded_file is not None:
14
+ image_data = uploaded_file.getvalue()
15
+ st.image(image_data)
16
+
17
+ def load_models():
18
+ model_name = 'Model/model.h5'
19
+ model = tf.keras.models.load_model(model_name)
20
+ return model
21
+
22
+ def load_labels():
23
+ with open('Oxford-102_Flower_dataset_labels.txt', 'r') as file:
24
+ data = file.read().splitlines()
25
+ flower_dict = dict(enumerate(data, 1))
26
+ return flower_dict
27
+
28
+ def load_image():
29
+ uploaded_file = st.file_uploader(label='Pick an image to test')
30
+ if uploaded_file is not None:
31
+ image_data = uploaded_file.getvalue()
32
+ st.image(image_data)
33
+ img = Image.open(io.BytesIO(image_data))
34
+ img = img.resize((224,224))
35
+ return img
36
+ else:
37
+ return None
38
+
39
+ def predict(model, categories, img):
40
+ img_array = tf.keras.preprocessing.image.img_to_array(img)
41
+ prediction = [img_array]
42
+ prediction_test = [1]
43
+ test_ds = tf.data.Dataset.from_tensor_slices((prediction, prediction_test))
44
+ test_ds = test_ds.cache().batch(32).prefetch(buffer_size = tf.data.experimental.AUTOTUNE)
45
+
46
+ prediction = model.predict(test_ds)
47
+ prediction_dict = dict(enumerate(prediction.flatten(), 1))
48
+ k = Counter(prediction_dict)
49
+
50
+ # Finding 3 highest values
51
+ high = k.most_common(3)
52
+
53
+ percentages = []
54
+ flowers = []
55
+ for i in high:
56
+ key, value = i
57
+ flowers.append(categories[key])
58
+ percentages.append(np.round(value*100, 2))
59
+ return flowers, percentages
60
+
61
+ def main():
62
+ st.title('Oxford 102 Flower CLassification Demo')
63
+ model = load_models()
64
+ categories = load_labels()
65
+ image = load_image()
66
+ result = st.button('Run on image')
67
+ if result:
68
+ st.write('Calculating results...')
69
+ flowers, percentages = predict(model, categories, image)
70
+ st.text(flowers)
71
+ st.text(percentages)
72
+
73
+ if __name__ == '__main__':
74
+ main()
75
+