saritha5 commited on
Commit
1f3ee52
·
1 Parent(s): 14d5391

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -95
app.py CHANGED
@@ -33,117 +33,61 @@ import h5py
33
  model_file_path = "mobile_net_occ.h5"
34
 
35
 
36
- page_names = ["Blurred or Not Blurred Prediction","Occluded or Not Occluded Prediction"]
37
  page = st.sidebar.radio('Navigation',page_names)
38
  #st.write("Welcome to the Project")
39
 
40
- if page == "Blurred or Not Blurred Prediction":
41
- st.title("""
42
  Image Blurriness Occluded
43
  """)
44
- st.subheader("Prediction of Blur or NotBlur Image")
45
- #images = ["blur1.png","blurimg2.png","blurimg3.png","images_11.jpeg"]
46
- #with st.sidebar:
47
- # st.write("choose an image")
48
- # st.image(images)
49
- #model_file_path = "mobile_net_occ.h5"
50
 
51
  ##Blurriness Features
52
 
53
- plt. figure(figsize=(10,9))
54
- def variance_of_laplacian(image):
55
- return cv2.Laplacian(image, cv2.CV_64F).var()
56
 
57
- def threshold(value, thresh):
58
- if value > thresh:
59
- return "Not Blur"
60
- else:
61
- return "Blur"
62
- def blurr_predict(img_iter):
63
-
64
- def make_prediction(img_content):
65
- pil_image = Image.open(img_content)
66
- imgplot = plt.imshow(pil_image)
67
- #st.image(pil_image)
68
- plt.show()
69
- gray_cvimage = cv2.cvtColor(np.array(pil_image), cv2.COLOR_RGB2GRAY)
70
  #print(gray_cvimage)
71
- variance_laplacian = variance_of_laplacian(gray_cvimage)
72
  #print(variance_laplacian)
73
- return variance_laplacian
74
 
75
- variance_score = make_prediction(img_iter)
76
- thresh = 2000
77
- variance_score = variance_score/thresh
78
- predicted_label = threshold(variance_score, 1)
79
- return predicted_label,variance_score
80
 
81
  #image_path = "images_11.jpeg"
82
- file = st.file_uploader('Upload an Image',type=(["jpeg","jpg","png"]))
83
 
84
- if file is None:
85
- st.write("Please upload an image file")
86
- else:
87
- image= Image.open(file)
88
- st.image(image,use_column_width = True)
89
- predicted_label,variance_score = blurr_predict(file)
90
- #st.header(predicted_label)
91
- #st.header(str(round(variance_score,2)))
92
- string = "The image is," + str(predicted_label) + " with the score value of " + str(round(variance_score,2))
93
- st.subheader(string)
94
  else:
95
- st.title("Prediction of Occluded or not Occluded ")
96
- #plt. figure(figsize=(10,9))
97
- def occ_predict(img_content):
98
- im = []
99
- image = cv2.imread(img_content)
100
- imgplot = plt.show(image)
101
-
102
- #st.write(img_content)
103
- #st.write(type(img_content))
104
-
105
- img = Image.fromarray(image, 'RGB')
106
- #st.write(type(image1))
107
- resize_image = img.resize((50, 50))
108
- im.append(np.array(resize_image))
109
- fv = np.array(im)
110
- np_array_img = fv.astype('float32') / 255
111
- model_gcs = h5py.File(model_file_path, 'r')
112
- myModel = load_model(model_gcs)
113
- prediction = myModel.predict(np_array_img)
114
- score = prediction[0][0].item()
115
-
116
- thresh = 0.5
117
- if score > thresh:
118
- return "Not Occluded",score
119
- else:
120
- return "Occluded",score
121
-
122
- f = st.file_uploader('Upload an Image',type=(["jpeg","jpg","png"]))
123
- st.write(f)
124
- #st.subheader("Prediction of Occluded or Not Occluded")
125
- #images1 = ["img1.png","img2.png","img3.png","img4.png"]
126
- # with st.sidebar:
127
- #st.write("choose an image")
128
- #st.image(images1)
129
-
130
- if f is None:
131
- st.write("Please upload an image file")
132
- else:
133
- #stringio = StringIO(f.getvalue())
134
- #f = stringio.read()
135
- image1= Image.open(f)
136
- #st.write(type(f.name))
137
- st.image(image1,use_column_width = True)
138
- #image_path = Path(f.name)
139
- #st.write(image_path)
140
-
141
-
142
- predicted_label,variance_score = occ_predict(f)
143
  #st.header(predicted_label)
144
  #st.header(str(round(variance_score,2)))
145
- string1 = "The image is," + predicted_label + " with the score value of " + str(round(variance_score,2))
146
- st.subheader(string1)
147
 
148
- #predicted_label, score = occ_predict("/content/drive/MyDrive/Occulded.jpg")
149
- #print("The image is", '\033[1m' + predicted_label1 + '\033[0m', "with the score value of" ,round(score,2))
 
33
  model_file_path = "mobile_net_occ.h5"
34
 
35
 
36
+ #page_names = ["Blurred or Not Blurred Prediction","Occluded or Not Occluded Prediction"]
37
  page = st.sidebar.radio('Navigation',page_names)
38
  #st.write("Welcome to the Project")
39
 
40
+
41
+ st.title("""
42
  Image Blurriness Occluded
43
  """)
44
+ st.subheader("Prediction of Blur or NotBlur Image")
45
+ images = ["blur1.png","blurimg2.png","blurimg3.png","images_11.jpeg"]
46
+ with st.sidebar:
47
+ st.write("choose an image")
48
+ st.image(images)
49
+ #model_file_path = "mobile_net_occ.h5"
50
 
51
  ##Blurriness Features
52
 
53
+ plt. figure(figsize=(10,9))
54
+ def variance_of_laplacian(image):
55
+ return cv2.Laplacian(image, cv2.CV_64F).var()
56
 
57
+ def threshold(value, thresh):
58
+ if value > thresh:
59
+ return "Not Blur"
60
+ else:
61
+ return "Blur"
62
+ def blurr_predict(img_iter):
63
+ def make_prediction(img_content):
64
+ pil_image = Image.open(img_content)
65
+ imgplot = plt.imshow(pil_image)
66
+ #st.image(pil_image)
67
+ plt.show()
68
+ gray_cvimage = cv2.cvtColor(np.array(pil_image), cv2.COLOR_RGB2GRAY)
 
69
  #print(gray_cvimage)
70
+ variance_laplacian = variance_of_laplacian(gray_cvimage)
71
  #print(variance_laplacian)
72
+ return variance_laplacian
73
 
74
+ variance_score = make_prediction(img_iter)
75
+ thresh = 2000
76
+ variance_score = variance_score/thresh
77
+ predicted_label = threshold(variance_score, 1)
78
+ return predicted_label,variance_score
79
 
80
  #image_path = "images_11.jpeg"
81
+ file = st.file_uploader('Upload an Image',type=(["jpeg","jpg","png"]))
82
 
83
+ if file is None:
84
+ st.write("Please upload an image file")
 
 
 
 
 
 
 
 
85
  else:
86
+ image= Image.open(file)
87
+ st.image(image,use_column_width = True)
88
+ predicted_label,variance_score = blurr_predict(file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  #st.header(predicted_label)
90
  #st.header(str(round(variance_score,2)))
91
+ string = "The image is," + str(predicted_label) + " with the score value of " + str(round(variance_score,2))
92
+ st.subheader(string)
93