Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
# DOGS VS CATS DATASET PREDICTION
|
4 |
+
|
5 |
+
## LOADING MODULES
|
6 |
+
|
7 |
+
|
8 |
+
# Commented out IPython magic to ensure Python compatibility.
|
9 |
+
# %%capture
|
10 |
+
# !pip install tensorflow-addons
|
11 |
+
# !pip install gradio
|
12 |
+
|
13 |
+
|
14 |
+
import tensorflow_addons as tfa
|
15 |
+
import gradio as gr
|
16 |
+
import cv2
|
17 |
+
import tensorflow as tf
|
18 |
+
import numpy as np
|
19 |
+
from tensorflow.keras.models import load_model
|
20 |
+
from google_drive_downloader import GoogleDriveDownloader as gdd
|
21 |
+
# from tensorflow.keras import *
|
22 |
+
# import tensorflow_datasets as tfds
|
23 |
+
# import matplotlib.pyplot as plt
|
24 |
+
# import time
|
25 |
+
|
26 |
+
|
27 |
+
def getData(flid,path,unzp=False):
|
28 |
+
return gdd.download_file_from_google_drive(file_id=flid,
|
29 |
+
dest_path=path,
|
30 |
+
unzip=unzp)
|
31 |
+
|
32 |
+
|
33 |
+
"""##LOADING SAVED MODEL"""
|
34 |
+
|
35 |
+
model1='1TNF6uZBvcIfEUwzIR8t4L1kuImxb6PES'
|
36 |
+
model2='1cK1cIYdczAoEPkiNZUqx2r1UqF2idcay'
|
37 |
+
model3='1ldVcjryLk-YFfLRyNYdut5WeLLNxJ8ab'
|
38 |
+
model = model1 #@param ["model1", "model2","model3"] {type:"raw"}
|
39 |
+
PATH='/saved_model/best_model.h5'
|
40 |
+
getData(flid=model,path=PATH)
|
41 |
+
|
42 |
+
# For example images
|
43 |
+
# gdd.download_file_from_google_drive(file_id='1LdB6ZE9vxPi4HNN2emqJSoP0ig9DiG10',
|
44 |
+
# dest_path='/content/examples.zip',
|
45 |
+
# unzip=True)
|
46 |
+
|
47 |
+
|
48 |
+
model=load_model('./saved_model/best_model.h5')
|
49 |
+
# model=load_model("/content/saved_model/content/saved/saved_model")
|
50 |
+
|
51 |
+
labels=['Cat','Dog']
|
52 |
+
NUM_CLASSES=2
|
53 |
+
IMG_SIZE=224
|
54 |
+
# ex=[['/content/dogs-cat-examples/cat2.jpg'],
|
55 |
+
# ['/content/dogs-cat-examples/cat3.jpg'],
|
56 |
+
# ['/content/dogs-cat-examples/dog2.jpeg'],
|
57 |
+
# ['/content/dogs-cat-examples/dog.jpeg']]
|
58 |
+
|
59 |
+
"""
|
60 |
+
## RUNNING WEB UI"""
|
61 |
+
|
62 |
+
def classify_image(inp):
|
63 |
+
inp = inp.reshape((-1, IMG_SIZE, IMG_SIZE, 3))
|
64 |
+
inp = tf.keras.applications.vgg16.preprocess_input(inp)
|
65 |
+
prediction = model.predict(inp).flatten()
|
66 |
+
return {labels[i]: float(prediction[i]) for i in range(NUM_CLASSES)}
|
67 |
+
|
68 |
+
image = gr.inputs.Image(shape=(IMG_SIZE, IMG_SIZE))
|
69 |
+
label = gr.outputs.Label(num_top_classes=2)
|
70 |
+
|
71 |
+
gr.Interface(fn=classify_image, inputs=image, outputs=label, title='Cats Vs Dogs',height=600, width=1200).launch()
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
|