Spaces:
Build error
Build error
# 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) | |