-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (31 loc) · 1.24 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
import streamlit as st
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
from PIL import Image
def main():
st.title('Cifar10 Web Classifier')
st.write('Upload an image that you think fits into one of the classes and see if the prediction is correct')
file = st.file_uploader('Please upload an image', type=['jpg','png'])
if file:
image = Image.open(file)
st.image(image, use_column_width=True)
resized_image = image.resize((32,32))
img_array = np.array(resized_image)/255
img_array = img_array.reshape((1,32,32,3))
model = tf.keras.models.load_model('cifar10_model.h5')
predictions = model.predict(img_array)
cifar10_classes = ['airplane','automobile','bird','cat','deer','dog','people','horse', 'ship','truck']
fig, ax = plt.subplots()
y_pos = np.arange(len(cifar10_classes))
ax.barh(y_pos, predictions[0], align='center')
ax.set_yticks(y_pos)
ax.set_yticklabels(cifar10_classes)
ax.invert_yaxis()
ax.set_xlabel('Probability')
ax.set_title("CIFAR10 Predictions")
st.pyplot(fig)
else:
st.text("You have not uploaded an image yet")
if __name__ =='__main__':
main()