-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (35 loc) · 1.27 KB
/
main.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
41
42
43
44
45
46
47
48
49
import streamlit as st
from PIL import Image, ImageFilter
import numpy as np
import PIL
import tensorflow as tf
from tensorflow import keras
class_names = ['Bicycle', 'Boat', 'Cat', 'Motorbike', 'People', 'Table']
img_height = 180
img_width = 180
st.write('''<style>
body{
text-align:center;
background-color:#ACDDDE;
}
</style>''', unsafe_allow_html=True)
st.title('Image Classifier')
#loading model
model = keras.models.load_model('./models/model/')
file_type = 'jpg'
st.text("The app can classify images among the 6 classes:\nBicycle, Boat, Cat, Motorbike, People, Table")
uploaded_file = st.file_uploader("Choose a file",type = file_type)
if uploaded_file != None:
image = Image.open(uploaded_file)
image = image.filter(ImageFilter.MedianFilter)
print(image.size)
image = image.resize((180, 180))
st.image(image)
img_array = keras.preprocessing.image.img_to_array(image)
print(img_array.shape)
np.reshape(img_array,(180,180,3))
img_array = tf.expand_dims(img_array, 0)
predictions = model.predict(img_array)
score = tf.nn.softmax(predictions[0])
st.text("Class: {} with a {:.2f} percent confidence."
.format(class_names[np.argmax(score)], 100 * np.max(score)))