-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
67 lines (44 loc) · 1.43 KB
/
app.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 streamlit as st
import numpy as np
import pandas as pd
import tensorflow as tf
from PIL import Image, ImageOps
@st.cache_resource()
def ob():
interpreter = tf.lite.Interpreter(model_path='quantized_model.tflite')
return interpreter
interpreter=ob()
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
st.title("Car Vs Dog Prediction")
uploaded_files = st.file_uploader("Upload Image",type=["jpeg","jpg","png","txt"])
st.write(uploaded_files)
def prediction(img,interpreter):
size=(256,256)
image=ImageOps.fit(img,size,Image.ANTIALIAS)
image=np.asarray(image)
img_reshape=image[np.newaxis,...]
#img_sh=cv2.resize(img,(256,256), interpolation=cv2.INTER_AREA)
#test_img=img_sh.reshape((1,256,256,3))
try:
image = np.array(img_reshape, dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], image)
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
ot=int(output_data[0][0])
if ot==1:
return "Dog"
else:
return "Cat"
except:
return "This is not cat or dog."
if uploaded_files == None:
st.write("Please upload Image")
else:
image=Image.open(uploaded_files)
st.image(image)
if st.button("Predict"):
result=''
result=prediction(image,interpreter)
st.success(result)