saritha5 commited on
Commit
9b05335
1 Parent(s): 19e87a2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ plt. figure(figsize=(10,9))
33
+ def occ_predict(img_content):
34
+ im = []
35
+ image=cv2.imread(img_content)
36
+ print(type(image))
37
+ imgplot = plt.imshow(image)
38
+ plt.show()
39
+ img = Image.fromarray(image, 'RGB')
40
+ resize_image = img.resize((50, 50))
41
+ im.append(np.array(resize_image))
42
+ fv = np.array(im)
43
+ np_array_img = fv.astype('float32') / 255
44
+ model_gcs = h5py.File(model_file_path, 'r')
45
+ print(model_file_path)
46
+ myModel = load_model(model_gcs)
47
+ prediction = myModel.predict(np_array_img)
48
+ score = prediction[0][0].item()
49
+ thresh = 0.5
50
+ if score > thresh:
51
+ return "The Image is "+"Not Occluded "+"with a Score of "+str(round(score,2))
52
+ else:
53
+ return "The Image is "+"Occluded "+"with a Score of "+str(round(score,2))
54
+
55
+ #predicted_label, score = occ_predict("img1.jpg")
56
+ inputs = gr.inputs.Image(type = 'filepath')
57
+ #label = gr.outputs.Label(num_top_classes=2)
58
+ EXAMPLES = ["img1.png","img2.png","img3.png","img4.png","img7.png","img8.png","img9.png"]
59
+
60
+
61
+ demo_app = gr.Interface(
62
+ fn=occ_predict,
63
+ inputs=inputs,
64
+ outputs= "text",
65
+ title = "Prediction of Occulded or not Occulded Image",
66
+ examples = EXAMPLES,
67
+ cache_example = True,
68
+ live = True,
69
+ theme = 'huggingface'
70
+ )
71
+ demo_app.launch(debug=True, enable_queue = True)