Spaces:
Runtime error
Runtime error
File size: 2,896 Bytes
9b05335 73980b5 9b05335 73980b5 9b05335 9d19246 d459273 9b05335 a63b05d 6b37fa9 9b05335 3fe7e14 9b05335 3fe7e14 |
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 72 73 74 75 76 |
import gradio as gr
from tensorflow.keras.models import load_model
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
from sklearn.metrics import roc_curve,auc,classification_report,confusion_matrix
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from PIL import Image
import cv2
import keras
from keras.utils import np_utils
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D,MaxPooling2D,Dense,Flatten,Dropout
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint,ReduceLROnPlateau
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import Adam,SGD,RMSprop,Adamax
from tensorflow.keras.models import Model, Sequential
from tensorflow.keras.callbacks import ReduceLROnPlateau
from sklearn.model_selection import StratifiedKFold
from tensorflow.keras.applications import MobileNetV2
from random import shuffle
from tqdm import tqdm
import scipy
import skimage
from skimage.transform import resize
import random
import os
from io import BytesIO
import h5py
model_file_path = "mobile_net_occ.h5"
plt. figure(figsize=(10,9))
def occ_predict(img_content):
im = []
image=cv2.imread(img_content)
print(type(image))
imgplot = plt.imshow(image)
plt.show()
img = Image.fromarray(image, 'RGB')
resize_image = img.resize((50, 50))
im.append(np.array(resize_image))
fv = np.array(im)
np_array_img = fv.astype('float32') / 255
model_gcs = h5py.File(model_file_path, 'r')
print(model_file_path)
myModel = load_model(model_gcs)
prediction = myModel.predict(np_array_img)
score = prediction[0][0].item()
thresh = 0.5
if score > thresh:
return "The house is "+"Not Occluded "+" and the occlusion Score is "+str(round(score,2))
else:
return "The house is "+"Occluded "+"and the occlusion Score is "+str(round(score,2))
#predicted_label, score = occ_predict("img1.jpg")
inputs = gr.inputs.Image(type = 'filepath')
#label = gr.outputs.Label(num_top_classes=2)
EXAMPLES = ["img1.png","img2.png","img3.png","img15.png","img11.png","img12.png","img18.png","img20.png"]
DESCRIPTION = """An image is occluded if the image is blocked by any object.
For example if an electric pole is filled with bushes,the image is occluded since it is not clear and blocked.
Mobil-net is used to train a model with occluded and non occluded images, so that it can correctly classify the images.
Occlusion detection can be used to filter unclear images and take safety measures."""
demo_app = gr.Interface(
fn=occ_predict,
inputs=inputs,
outputs= "text",
title = "Prediction of Occluded or not Occluded Image",
description = DESCRIPTION,
examples = EXAMPLES,
#cache_example = True,
#live = True,
theme = 'huggingface'
)
demo_app.launch() |