File size: 5,200 Bytes
bc69be5
e1a012f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c34ee0e
9deebe5
934f938
e1a012f
bc69be5
001ecc6
 
ca63cea
dd539b9
6514c32
9deebe5
dd539b9
0d68ac6
dd539b9
1859f7d
 
dd539b9
6c49060
 
 
 
 
7f80112
dd539b9
7f80112
dd539b9
 
 
7f80112
dd539b9
 
 
 
 
 
7f80112
dd539b9
 
 
 
 
 
 
 
 
 
7f80112
dd539b9
 
 
 
 
7f80112
dd539b9
 
3f605a0
dd539b9
 
3f605a0
dd539b9
 
 
 
 
 
 
 
 
9deebe5
b708d34
dd539b9
de27e44
6ff04d9
b708d34
 
6ff04d9
 
b708d34
dd539b9
 
 
 
 
 
 
 
6ff04d9
dd539b9
 
 
 
 
3f605a0
dd539b9
3c59dd4
be724bd
bc3dd53
 
 
 
3f605a0
dd539b9
 
3c59dd4
033809f
 
bc3dd53
474b8af
dd539b9
033809f
458f51b
 
eb485ea
30134ef
dd539b9
 
be724bd
dd539b9
3f605a0
 
 
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import streamlit as st 
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
import io
from io import BytesIO,StringIO
from pathlib import Path
import h5py

model_file_path = "mobile_net_occ.h5"


page_names = ["Blurred or Not Blurred Prediction","Occluded or Not Occluded Prediction"]
page = st.sidebar.radio('Navigation',page_names)
#st.write("Welcome to the Project")

if page == "Blurred or Not Blurred Prediction":
    st.title("""
         Image Blurriness Occluded
         """)
    st.subheader("Prediction of Blur or NotBlur Image")
    #images = ["blur1.png","blurimg2.png","blurimg3.png","images_11.jpeg"]
    #with st.sidebar:
     #  st.write("choose an image")
      # st.image(images)
    #model_file_path = "mobile_net_occ.h5"

    ##Blurriness Features

    plt. figure(figsize=(10,9))
    def variance_of_laplacian(image):
        return cv2.Laplacian(image, cv2.CV_64F).var()

    def threshold(value, thresh):
        if value > thresh:
            return "Not Blur"
        else:
            return "Blur"  
    def blurr_predict(img_iter):
  
      def make_prediction(img_content):
        pil_image = Image.open(img_content)
        imgplot = plt.imshow(pil_image)
        #st.image(pil_image)
        plt.show()
        gray_cvimage = cv2.cvtColor(np.array(pil_image), cv2.COLOR_RGB2GRAY)
        #print(gray_cvimage)
        variance_laplacian = variance_of_laplacian(gray_cvimage)
        #print(variance_laplacian)
        return variance_laplacian

      variance_score = make_prediction(img_iter)
      thresh = 2000
      variance_score = variance_score/thresh
      predicted_label = threshold(variance_score, 1)
      return predicted_label,variance_score

    #image_path = "images_11.jpeg"
    file = st.file_uploader('Upload an Image',type=(["jpeg","jpg","png"]))

    if file is None:
        st.write("Please upload an image file")
    else:
        image= Image.open(file)
        st.image(image,use_column_width = True)
        predicted_label,variance_score = blurr_predict(file)
        #st.header(predicted_label)
        #st.header(str(round(variance_score,2)))
        string = "The image is," + str(predicted_label) + " with the score value of  " + str(round(variance_score,2))
        st.subheader(string)
else:
    st.title("Prediction of Occluded or not Occluded ")
    #plt. figure(figsize=(10,9))
    def occ_predict(img_content):
        im = []
        image1 = plt.imread(img_content)

        #st.write(img_content)
        #st.write(type(img_content))

        img = Image.fromarray(image1, 'RGB') 
        #st.write(type(image1))
        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')
        myModel = load_model(model_gcs)
        prediction = myModel.predict(np_array_img)
        score = prediction[0][0].item()
        
        thresh = 0.5
        if score > thresh:
            return "Not Occluded",score
        else:
            return "Occluded",score

    f = st.file_uploader('Upload an Image',type=(["jpeg","jpg","png"]))
    st.write(f)
    #st.subheader("Prediction of Occluded or Not Occluded")
    #images1 = ["img1.png","img2.png","img3.png","img4.png"]
   # with st.sidebar:
        #st.write("choose an image")
        #st.image(images1)

    if f is None:
        st.write("Please upload an image file")
    else:        
        #stringio = StringIO(f.getvalue())
        #f = stringio.read()
        image1= Image.open(f)
        #st.write(type(f.name))
        st.image(image1,use_column_width = True)
        #image_path = Path(f.name)
        #st.write(image_path)
        
        
        predicted_label,variance_score = occ_predict(f)
        #st.header(predicted_label)
        #st.header(str(round(variance_score,2)))
        string1 = "The image is," + predicted_label + " with the score value of  " + str(round(variance_score,2))
        st.subheader(string1)

#predicted_label, score = occ_predict("/content/drive/MyDrive/Occulded.jpg")
#print("The image is", '\033[1m' + predicted_label1 + '\033[0m', "with the score value of" ,round(score,2))