-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimgwebapp.py
More file actions
42 lines (33 loc) · 1.4 KB
/
imgwebapp.py
File metadata and controls
42 lines (33 loc) · 1.4 KB
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
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import tensorflow as tf
import numpy as np
import streamlit as st
from PIL import Image
import requests
from io import BytesIO
st.set_option('deprecation.showfileUploaderEncoding', False)
st.title("Cat Family Classifier")
st.text("Provide URL of bean Image for image classification")
@st.cache(allow_output_mutation=True)
def load_model():
#model = tf.keras.models.load_model('/Users/s.sriaravind/Desktop/Dev/Data_Science/Projects/Cats_Family_Detection/models')
model = tf.keras.models.load_model('/Users/s.sriaravind/Desktop/Dev/Data_Science/Projects/Cats_Family_Detection/models')
return model
with st.spinner('Loading Model Into Memory....'):
model = load_model()
classes=['Cheetah', 'Jaguar', 'Tiger']
def decode_img(image):
img = tf.image.decode_jpeg(image, channels=3)
img = tf.image.resize(img,[224,224])
return np.expand_dims(img, axis=0)
path = st.text_input('Enter Image URL to Classify.. ','https://content.jwplatform.com/thumbs/h5Ko1nUT-720.jpg')
if path is not None:
content = requests.get(path).content
st.write("Predicted Class :")
with st.spinner('classifying.....'):
label =np.argmax(model.predict(decode_img(content)),axis=1)
st.write(classes[label[0]])
st.write("")
image = Image.open(BytesIO(content))
st.image(image, caption='Classifying Cat Family', use_column_width=True)