-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
57 lines (46 loc) · 1.77 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
import streamlit as st
from PIL import Image
import matplotlib.pyplot as plt
import tensorflow_hub as hub
import tensorflow as tf
import numpy as np
from tensorflow import keras
from tensorflow.keras.models import load_model
from tensorflow.keras import preprocessing
import time
fig = plt.figure()
with open("app.css") as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
st.title("Cat Vs Dog With Data Augmentation")
st.write("You can upload the image to check whether It is Cat or Dog using Pre-trained model")
def main():
file_uploaded = st.file_uploader("Choose File", type=["png","jpg","jpeg"])
class_btn = st.button("Classify")
if file_uploaded is not None:
image = Image.open(file_uploaded)
st.image(image, caption='Uploaded Image', use_column_width=True)
if class_btn:
if file_uploaded is None:
st.write("Invalid command, please upload an image")
else:
with st.spinner('Model working....'):
plt.axis("off")
predictions = predict(image)
time.sleep(1)
st.success('Classified')
st.balloons()
if predictions > 0.5:
st.write("Dog")
else:
st.write("Cat")
def predict(image):
classifier_model = "Cat_dog_transfer.h5"
IMAGE_SHAPE = (255, 255,3)
model = load_model(classifier_model, compile=False, custom_objects={'KerasLayer': hub.KerasLayer})
test_image = image.resize((150,150))
test_image = preprocessing.image.img_to_array(test_image)
test_image = test_image / 255.0
test_image = np.expand_dims(test_image, axis=0)
classes = model.predict(test_image, batch_size=10)
return classes
main()