|
import gradio as gr |
|
import tensorflow as tf |
|
print(tf.__version__) |
|
import numpy as np |
|
from PIL import Image |
|
|
|
import os |
|
|
|
model_path = "apple_model_transferlearning.keras" |
|
model = tf.keras.models.load_model(model_path) |
|
|
|
def predict_apple(image): |
|
|
|
print(type(image)) |
|
image = Image.fromarray(image.astype('uint8')) |
|
image = image.resize((150, 150)) |
|
image = np.array(image) |
|
image = np.expand_dims(image, axis=0) |
|
|
|
|
|
prediction = model.predict(image) |
|
|
|
prediction = np.round(prediction, 2) |
|
|
|
|
|
p_schorf = prediction[0][0] |
|
p_schwarzfaeule = prediction[0][1] |
|
p_zederapfel = prediction[0][2] |
|
p_gesund = prediction[0][3] |
|
|
|
return {'Gesund': p_gesund, 'Schorf': p_schorf, 'Schwarzfaeule': p_schwarzfaeule, 'Zederapfel': p_zederapfel} |
|
|
|
|
|
|
|
input_image = gr.Image() |
|
iface = gr.Interface( |
|
fn=predict_apple, |
|
inputs=input_image, |
|
outputs=gr.Label(), |
|
examples=["images/Gesund1.JPG", |
|
"images/Gesund2.JPG", |
|
"images/Gesund3.JPG", |
|
"images/Schorf1.JPG", |
|
"images/Schorf2.JPG", |
|
"images/Schorf3.JPG", |
|
"images/Schwarzfaeule1.JPG", |
|
"images/Schwarzfaeule2.JPG", |
|
"images/Schwarzfaeule3.JPG", |
|
"images/Zederapfel1.JPG", |
|
"images/Zederapfel2.JPG", |
|
"images/Zederapfel3.JPG"], |
|
description="Applikation zur Überwachung der Gesundheit von Apfelbäumen") |
|
|
|
iface.launch() |
|
|