Spaces:
Sleeping
Sleeping
Nihal Arya commited on
Commit ·
b8e4c73
1
Parent(s): d6bf786
files added to push to huggingfaces
Browse filesFiles changed (3)
- Model/model.h5Added+3
- Oxford-102_Flower_dataset_labels.txtAdded+102
- app.pyAdded+75
123version https://git-lfs.github.com/spec/v1oid sha256:73ed908fb076b4562d9fa52f9b23a363e891154fd7ef11c2bbb82d10a57a3956size 37247336123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 pink primrose hard-leaved pocket orchid canterbury bells sweet pea english marigold tiger lily moon orchid bird of paradise monkshood globe thistle snapdragon colt's foot king protea spear thistle yellow iris globe-flower purple coneflower peruvian lily balloon flower giant white arum lily fire lily pincushion flower fritillary red ginger grape hyacinth corn poppy prince of wales feathers stemless gentian artichoke sweet william carnation garden phlox love in the mist mexican aster alpine sea holly ruby-lipped cattleya cape flower great masterwort siam tulip lenten rose barbeton daisy daffodil sword lily poinsettia bolero deep blue wallflower marigold buttercup oxeye daisy common dandelion petunia wild pansy primula sunflower pelargonium bishop of llandaff gaura geranium orange dahlia pink-yellow dahlia cautleya spicata japanese anemone black-eyed susan silverbush californian poppy osteospermum spring crocus bearded iris windflower tree poppy gazania azalea water lily rose thorn apple morning glory passion flower lotus toad lily anthurium frangipani clematis hibiscus columbine desert-rose tree mallow magnolia cyclamen watercress canna lily hippeastrum bee balm ball moss foxglove bougainvillea camellia mallow mexican petunia bromelia blanket flower trumpet creeper blackberry lily123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475# All importsimport streamlit as stimport tensorflow as tffrom tensorflow import kerasfrom PIL import Imagefrom tensorflow.keras.preprocessing import imageimport iofrom collections import Counterimport 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)
def load_models(): 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() flower_dict = dict(enumerate(data, 1)) return flower_dict 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 predict(model, categories, img): img_array = tf.keras.preprocessing.image.img_to_array(img) prediction = [img_array] prediction_test = [1] test_ds = tf.data.Dataset.from_tensor_slices((prediction, prediction_test)) test_ds = test_ds.cache().batch(32).prefetch(buffer_size = tf.data.experimental.AUTOTUNE)
prediction = model.predict(test_ds) prediction_dict = dict(enumerate(prediction.flatten(), 1)) k = Counter(prediction_dict) # Finding 3 highest values high = k.most_common(3)
percentages = [] flowers = [] for i in high: key, value = i flowers.append(categories[key]) percentages.append(np.round(value*100, 2)) return flowers, percentages
def main(): st.title('Oxford 102 Flower CLassification Demo') model = load_models() categories = load_labels() image = load_image() result = st.button('Run on image') if result: st.write('Calculating results...') flowers, percentages = predict(model, categories, image) st.text(flowers) st.text(percentages)
if __name__ == '__main__': main()
Model/model.h5Added+3
Oxford-102_Flower_dataset_labels.txtAdded+102
app.pyAdded+75