-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
67 lines (49 loc) · 1.87 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import numpy as np
import streamlit as st
import keras
from keras.preprocessing import image
import io
st.title('Modelo de Classificação de Comidas')
# Input type - File
uploaded_file = st.file_uploader('File Uploader', type=["png", "jpg", "jpeg"])
# Input type - Image
img_file_buffer = st.camera_input('Camera')
st.header('Resultados')
# Model
def load_model():
model = keras.models.load_model("final-food-model.h5")
return model
modelPrediction = load_model()
# Classes
specific_classes = ['baby_back_ribs','baklava','beef_carpaccio','bruschetta',\
'beet_salad','beignets','breakfast_burrito','donuts','churros','fried_rice']
# Prediction for upload file
if uploaded_file is not None:
# Pre processamento
img = image.load_img(io.BytesIO(uploaded_file.read()), target_size=(256, 256))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = img_array / 255.0
# Showing image that was upload
st.image(img, caption="Uploaded Image", use_column_width=True)
# Prediction
predictions = modelPrediction.predict(img_array)
# Label
predicted_class_index = np.argmax(predictions, axis=1)[0]
predicted_class = specific_classes[predicted_class_index]
# Print
st.write("Predicted class:", predicted_class)
#Prediction for image from camera
if img_file_buffer is not None:
# Pre processamento
img = image.load_img(io.BytesIO(img_file_buffer.read()), target_size=(256, 256))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = img_array / 255.0
# Prediction
predictions = modelPrediction.predict(img_array)
# Label
predicted_class_index = np.argmax(predictions, axis=1)[0]
predicted_class = specific_classes[predicted_class_index]
# Print
st.write("Predicted class:", predicted_class)