CoolFace
Apppublic

DataDoggo/Visionary

sourceHugging Faceupdated 4y agoView on Hugging Face
2likes
app.py53 linesDownload Raw Back to root
1import requests2import tensorflow as tf3from tensorflow import keras4from keras.models import Sequential, load_model5from tensorflow.keras.models import Sequential6from tensorflow.keras.layers import Activation, Dense, BatchNormalization, Conv2D, MaxPool2D, Dropout, Flatten7from tensorflow.keras.optimizers import Adam8from tensorflow.keras.metrics import categorical_crossentropy9from tensorflow.keras.preprocessing.image import ImageDataGenerator, load_img, array_to_img, img_to_array10from tensorflow.keras import datasets, layers, models11 12import pandas as pd13import numpy as np14 15import gradio as gr16 17load_file = 'densenet256x256_weighted_tuned.hdf5'18model=load_model(load_file)19 20 21img_resize = keras.Sequential(22    [23        layers.experimental.preprocessing.Resizing(256, 256, interpolation='bilinear')24    ]25)26 27def classify_image(inp):28    inp = img_resize(inp)29    img_array = keras.preprocessing.image.img_to_array(inp)30    img_array = tf.expand_dims(img_array, 0)31 32    prediction = model.predict(img_array).flatten()33    return {'Probability of Diabetic Retinopathy:': float(np.exp(prediction)/(1+np.exp(prediction)))} #{labels[i]: float(prediction[i]) for i in range(1)}34 35content_image_input = gr.inputs.Image(label="Content Image")36style_image_input = gr.inputs.Image(shape=(256, 256), label="Style Image")37 38image = gr.inputs.Image(label = 'Image')39label = gr.outputs.Label(num_top_classes=1)40 41explanation = 'Page 1 examples both have DR and the model confidently predicts it correctly. Page 2 images are examples without DR and the model confidently predicts correctly. Page 3 are the type of images the model predicts poorly on. The first image on Page 3 has DR, but the model guesses incorrectly. The 2nd image on Page 3 does not have DR, but the model guesses incorrectly.'42 43gr.Interface(44    fn=classify_image,45    inputs= image,46    title = 'Prediction of Diabetic Retinopathy (DR)', 47    examples_per_page = 2,48    examples = ['DR100.jpeg', 'DR95.jpeg', 'Norm5.jpeg', 'Norm16.jpeg', 'DR8.jpeg', 'Norm95.jpeg' ],49    description = 'Demo for predicting the probability of having Diabetic Retinopathy with DenseNet Model.',50    article = explanation,51    outputs=label,52    theme = "peach"53).launch()