Spaces:
Runtime error
Runtime error
File size: 2,029 Bytes
5b27df7 199a42a 5b27df7 199a42a 5b27df7 199a42a 5b27df7 199a42a 5b27df7 199a42a 5b27df7 199a42a 5b27df7 199a42a 5b27df7 199a42a |
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 |
import requests
import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential, load_model
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Activation, Dense, BatchNormalization, Conv2D, MaxPool2D, Dropout, Flatten
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.metrics import categorical_crossentropy
from tensorflow.keras.preprocessing.image import ImageDataGenerator, load_img, array_to_img, img_to_array
from tensorflow.keras import datasets, layers, models
import pandas as pd
import numpy as np
import gradio as gr
load_file = 'model_2.h5'
model=load_model(load_file)
img_resize = keras.Sequential(
[
layers.experimental.preprocessing.Resizing(256, 256, interpolation='bilinear')
]
)
def classify_image(inp):
inp = img_resize(inp)
img_array = keras.preprocessing.image.img_to_array(inp)
img_array = tf.expand_dims(img_array, 0)
prediction = model.predict(img_array).flatten()
return {'Probability of Diabetic Retinopathy:': float(np.exp(prediction)/(1+np.exp(prediction)))} #{labels[i]: float(prediction[i]) for i in range(1)}
content_image_input = gr.inputs.Image(label="Content Image")
style_image_input = gr.inputs.Image(shape=(256, 256), label="Style Image")
image = gr.inputs.Image(label = 'Image')
label = gr.outputs.Label(num_top_classes=3)
explanation = 'The first two sample images both have DR and the model confidently predicts it correctly. The next two images are examples without DR that the model confidently predicts correctly. The 5th image has DR, but the model guesses incorrectly. The 6th image does not have DR, but the model guesses incorrectly.'
gr.Interface(
fn=classify_image,
inputs= image,
title = 'Prediction of Diabetic Retinopathy (DR)',
description = 'Demo for predicting the probability of having Diabetic Retinopathy. This version is currently using a DenseNet Model.',
article = explanation,
outputs=label,
theme = "peach"
).launch() |