File size: 1,770 Bytes
69dc109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ade0bca
69dc109
 
 
 
edea0d6
69dc109
 
 
 
 
 
 
 
 
4908658
c45291f
69dc109
 
07c344b
69dc109
 
 
 
c45291f
69dc109
 
 
 
 
d124d9f
 
61c64a0
 
69dc109
 
 
 
 
 
 
 
 
 
 
 
 
01e162c
69dc109
 
 
 
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
68
69
70
71


# DOGS VS CATS DATASET PREDICTION

## LOADING MODULES


# Commented out IPython magic to ensure Python compatibility.
# %%capture
# !pip install tensorflow-addons
# !pip install gradio


import tensorflow_addons as tfa
import gradio as gr
import tensorflow as tf
import numpy as np
from tensorflow.keras.models import load_model
#from google_drive_downloader import GoogleDriveDownloader as gdd
# from tensorflow.keras import *
# import tensorflow_datasets as tfds
# import matplotlib.pyplot as plt
# import time




"""##LOADING SAVED MODEL"""

model1='1TNF6uZBvcIfEUwzIR8t4L1kuImxb6PES'
model2='1cK1cIYdczAoEPkiNZUqx2r1UqF2idcay'
model3='1ldVcjryLk-YFfLRyNYdut5WeLLNxJ8ab'
model = model1 #@param ["model1", "model2","model3"] {type:"raw"}
PATH='best_model.h5'
#getData(flid=model,path=PATH)

# For example images
# gdd.download_file_from_google_drive(file_id='1LdB6ZE9vxPi4HNN2emqJSoP0ig9DiG10',
#                                     dest_path='/content/examples.zip',
#                                     unzip=True)


model=load_model(PATH)
# model=load_model("/content/saved_model/content/saved/saved_model")

labels=['Cat','Dog']
NUM_CLASSES=2
IMG_SIZE=224
ex=[['cat2.jpg'],
    ['dog2.jpeg'],  
     ['cat3.jpg'],
     ['dog.jpeg']]

"""
## RUNNING WEB UI"""

def classify_image(inp):
  inp = inp.reshape((-1, IMG_SIZE, IMG_SIZE, 3))
  inp = tf.keras.applications.vgg16.preprocess_input(inp)
  prediction = model.predict(inp).flatten()
  return {labels[i]: float(prediction[i]) for i in range(NUM_CLASSES)}

image = gr.inputs.Image(shape=(IMG_SIZE, IMG_SIZE))
label = gr.outputs.Label(num_top_classes=2)

gr.Interface(fn=classify_image, inputs=image, outputs=label, title='Cats Vs Dogs',height=600, width=1200,examples=ex,theme='peach').launch(debug=True)