-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebimgconverter.py
40 lines (32 loc) · 1.33 KB
/
webimgconverter.py
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
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("Bean Image 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('/app/models/')
return model
with st.spinner('Loading Model Into Memory....'):
model = load_model()
classes=['angular_leaf_spot','bean_rust','healthy']
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://beanipm.pbgworks.org/sites/pbg-beanipm7/files/styles/picture_custom_user_wide_1x/public/AngularLeafSpotFig1a.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 Bean Image', use_column_width=True)