File size: 1,938 Bytes
7041965
 
 
 
 
 
 
 
d8175f2
7041965
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b81cc70
7041965
 
 
 
 
 
 
 
91b8a68
 
2edbeeb
 
 
 
 
 
 
 
 
 
c9ea3ea
7041965
 
 
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
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):
    # Preprocess image
    print(type(image))
    image = Image.fromarray(image.astype('uint8'))  # Convert numpy array to PIL image
    image = image.resize((150, 150))  # Resize the image to 150x150 pixels
    image = np.array(image)
    image = np.expand_dims(image, axis=0)  # Add batch dimension

    # Predict
    prediction = model.predict(image)
    # Convert the probabilities to rounded values
    prediction = np.round(prediction, 2)

    # Make sure the indices are correct according to your model's training
    p_schorf        = prediction[0][0]   # Probability for "Schorf"
    p_schwarzfaeule = prediction[0][1]   # Probability for "Schwarzfaeule"
    p_zederapfel    = prediction[0][2]   # Probability for "Zederapfel"
    p_gesund        = prediction[0][3]   # Probability for "Gesund"    

    return {'Gesund': p_gesund, 'Schorf': p_schorf, 'Schwarzfaeule': p_schwarzfaeule, 'Zederapfel': p_zederapfel}
 
 
# Create the Gradio interface
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()