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