saritha commited on
Commit
db1120e
·
1 Parent(s): e6dad10

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from tensorflow.keras.models import load_model
3
+ import numpy as np # linear algebra
4
+ import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
5
+ from sklearn.metrics import roc_curve,auc,classification_report,confusion_matrix
6
+ import matplotlib.pyplot as plt
7
+ import matplotlib.image as mpimg
8
+ from PIL import Image
9
+ import cv2
10
+ import keras
11
+ from keras.utils import np_utils
12
+ from tensorflow.keras.models import Sequential
13
+ from tensorflow.keras.layers import Conv2D,MaxPooling2D,Dense,Flatten,Dropout
14
+ from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint,ReduceLROnPlateau
15
+ from tensorflow.keras.models import Model
16
+ from tensorflow.keras.optimizers import Adam,SGD,RMSprop,Adamax
17
+ from tensorflow.keras.models import Model, Sequential
18
+ from tensorflow.keras.callbacks import ReduceLROnPlateau
19
+ from sklearn.model_selection import StratifiedKFold
20
+ from tensorflow.keras.applications import MobileNetV2
21
+ from random import shuffle
22
+ from tqdm import tqdm
23
+ import scipy
24
+ import skimage
25
+ from skimage.transform import resize
26
+ import random
27
+ import os
28
+ from io import BytesIO
29
+ import h5py
30
+ model_file_path = "mobile_net_occ.h5"
31
+
32
+
33
+ options = gr.radio(["Prediction of Blurr or Not Blurr","Prediction of ","Prediction of Occluded or Non Occluded"])
34
+ plt. figure(figsize=(10,9))
35
+ def occ_predict(img_content):
36
+ im = []
37
+ image=cv2.imread(img_content)
38
+ print(type(image))
39
+ imgplot = plt.imshow(image)
40
+ plt.show()
41
+ img = Image.fromarray(image, 'RGB')
42
+ resize_image = img.resize((50, 50))
43
+ im.append(np.array(resize_image))
44
+ fv = np.array(im)
45
+ np_array_img = fv.astype('float32') / 255
46
+ model_gcs = h5py.File(model_file_path, 'r')
47
+ print(model_file_path)
48
+ myModel = load_model(model_gcs)
49
+ prediction = myModel.predict(np_array_img)
50
+ score = prediction[0][0].item()
51
+ thresh = 0.5
52
+ if score > thresh:
53
+ return "The Image is "+"Not Occluded "+"with a Score of "+str(round(score,2))
54
+ else:
55
+ return "The Image is "+"Occluded "+"with a Score of "+str(round(score,2))
56
+
57
+ #predicted_label, score = occ_predict("img1.jpg")
58
+ inputs = gr.inputs.Image(type = 'filepath')
59
+ #label = gr.outputs.Label(num_top_classes=2)
60
+ EXAMPLES = ["img1.png","img2.png","img3.png","img4.png"]
61
+
62
+
63
+ demo_app = gr.Interface(
64
+ fn=occ_predict,
65
+ inputs=inputs,
66
+ outputs= "text",
67
+ title = "Prediction of Occulded or not Occulded Image",
68
+ examples = EXAMPLES,
69
+ cache_example = True,
70
+ live = True,
71
+ theme = 'huggingface'
72
+ )
73
+ demo_app.launch(debug=True, enable_queue = True)