| import streamlit as st |
| from PIL import Image |
| import numpy as np |
| |
| from tensorflow import Graph as Graph |
| from tensorflow import import_graph_def |
| from tensorflow.compat.v1 import GraphDef as GraphDef |
| from tensorflow.compat.v1 import Session as Session |
| from tensorflow.io.gfile import GFile as GFile |
| from object_detection.utils import visualization_utils as vis_util |
| from object_detection.utils import label_map_util |
|
|
|
|
| |
| MODEL_NAME = 'E:\AIML-\Diabetic-Ratinopathy-master\optic_disc_macula_graph' |
|
|
| |
| |
| PATH_TO_CKPT = 'resnet-inference-graph.pb' |
| NUM_CLASSES = 2 |
|
|
| detection_graph = Graph() |
| with detection_graph.as_default(): |
| od_graph_def = GraphDef() |
| with GFile(PATH_TO_CKPT, 'rb') as fid: |
| serialized_graph = fid.read() |
| od_graph_def.ParseFromString(serialized_graph) |
| import_graph_def(od_graph_def, name='') |
|
|
|
|
| def load_image_into_numpy_array(image): |
| (im_width, im_height) = image.size |
| return np.array(image.getdata()).reshape( |
| (im_height, im_width, 3)).astype(np.uint8) |
|
|
|
|
| labelmap = {1: {'id': 1, 'name': 'optic_disease'}, 2: {'id': 2, 'name': 'macula'}} |
| dmp =[] |
|
|
| def pred(img): |
| with detection_graph.as_default(): |
| with Session(graph=detection_graph) as sess: |
| |
| image_tensor = detection_graph.get_tensor_by_name('image_tensor:0') |
| |
| detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0') |
| |
| |
| detection_scores = detection_graph.get_tensor_by_name('detection_scores:0') |
| detection_classes = detection_graph.get_tensor_by_name('detection_classes:0') |
| num_detections = detection_graph.get_tensor_by_name('num_detections:0') |
| |
| |
| |
| |
| image_np = load_image_into_numpy_array(img) |
| |
| image_np_expanded = np.expand_dims(image_np, axis=0) |
| |
| (boxes, scores, classes, num) = sess.run( |
| [detection_boxes, detection_scores, detection_classes, num_detections], |
| feed_dict={image_tensor: image_np_expanded}) |
| dmp.append([boxes, scores, classes, num]) |
| |
| vis_util.visualize_boxes_and_labels_on_image_array( |
| image_np, |
| np.squeeze(boxes), |
| np.squeeze(classes).astype(np.int32), |
| np.squeeze(scores), |
| |
| labelmap, |
| use_normalized_coordinates=True, |
| line_thickness=40) |
| |
| |
| |
| |
| |
| |
| |
| return(image_np,scores[0][0]*100,scores[0][1]*100) |
|
|
|
|
|
|
| |
|
|
| uploaded_file = st.file_uploader("", type=['jpg','png','jpeg']) |
|
|
| pred_flag = False |
| def main(): |
| st.label_visibility='collapse' |
| st.title("Diabetic Retinopathy Prediction") |
| if uploaded_file is not None: |
| image = Image.open(uploaded_file) |
| st.markdown('<p style="text-align: center;"><label>Image : </label></p>',unsafe_allow_html=True) |
| st.image(image,width=500) |
| if st.button("Predict"): |
| x,optic,macula = pred(image) |
| st.markdown('<p style="text-align: center;"><label>Prediction : </label></p>',unsafe_allow_html=True) |
| st.image(x,width=900) |
| st.write('Optic Disease Score',optic) |
| st.write('Macula Score',macula) |
| |
| |
| if __name__ == '__main__': |
| main() |
|
|
|
|