Spaces:
Sleeping
Sleeping
File size: 2,909 Bytes
1eebc45 6ea82b1 1eebc45 a8b4012 1eebc45 f62790a 12a3d1b 1eebc45 28fb1f0 249c24f 12a3d1b 5dba2ed 249c24f 75eae57 12a3d1b 249c24f 75eae57 249c24f bcaa4d3 249c24f 2c6e3b0 249c24f f1bad2e d7fd16e 9833133 249c24f f1bad2e d7fd16e 249c24f 9833133 249c24f f9ec56b 5c82271 f9ec56b |
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 |
# -*- coding: utf-8 -*-
# %%capture
# #Use capture to not show the output of installing the libraries!
#model_multi = tf.keras.models.load_model("densenet")
# define the labels for the multi-label classification model
#labels_multi = {0: 'healthy', 1: 'mild', 2: 'moderate'}
#model = tf.keras.models.load_model('/content/drive/MyDrive/project_image_2023_NO/saved_models/saved_model/densenet')
#labels = ['Healthy', 'Patient']
#labels = {0: 'healthy', 1: 'patient'}
import gradio as gr
import requests
import torch
import torch.nn as nn
from PIL import Image
from torchvision.models import resnet50
from torchvision.transforms import functional as F
import numpy as np
import tensorflow as tf
from transformers import pipeline
from tensorflow.keras.preprocessing import image as image_utils
from tensorflow.keras.applications import densenet, efficientnet
import tensorflow as tf
import gradio as gr
# load the CNN binary classification model
model_cnn = tf.keras.models.load_model("CNN_binary")
# define the labels for the binary classification model
labels_cnn = {0: 'healthy', 1: 'Patients'}
# load the EfficientNet binary classification model
model_efn = tf.keras.models.load_model("efficientNet_binary")
# define the labels for the binary classification model
labels_efn = {0: 'healthy', 1: 'Patients'}
def classify_cnn(inp):
inp = inp.reshape((-1, 224, 224, 3))
inp = tf.keras.applications.densenet.preprocess_input(inp)
prediction = model_cnn.predict(inp)
confidences = {labels_cnn[i]: float(prediction[0][i]) for i in range(2)}
return confidences
def classify_efn(inp):
inp = inp.reshape((-1, 224, 224, 3))
inp = tf.keras.applications.efficientnet.preprocess_input(inp)
prediction = model_efn.predict(inp)
confidences = {labels_efn[i]: float(prediction[0][i]) for i in range(2)}
return confidences
binary_interface_cnn = gr.Interface(fn=classify_cnn,
inputs=gr.Image(shape=(224, 224)),
outputs=gr.Label(num_top_classes=2),
title="Binary Image Classification",
description="Classify an image as healthy or patient using custom CNN.",
examples=[['300104.png'],['371129.png']]
)
binary_interface_efn = gr.Interface(fn=classify_efn,
inputs=gr.Image(shape=(224, 224)),
outputs=gr.Label(num_top_classes=2),
title="Binary Image Classification",
description="Classify an image as healthy or patient using EfficientNet.",
examples=[['300104.png'],['371129.png']]
)
demo = gr.TabbedInterface([binary_interface_cnn, binary_interface_efn], ["Custom CNN", "CNNs"])
demo.launch() |