File size: 2,056 Bytes
b7997c9
 
bf24ba2
b7997c9
 
 
 
 
 
891e0e9
8e9bd85
b7997c9
891e0e9
b7997c9
 
891e0e9
b7997c9
891e0e9
b7997c9
 
891e0e9
8e9bd85
b7997c9
891e0e9
b7997c9
 
891e0e9
b7997c9
 
891e0e9
b7997c9
 
891e0e9
b7997c9
bf24ba2
b7997c9
 
891e0e9
bf24ba2
 
 
891e0e9
 
 
bf24ba2
 
 
 
 
3d2f114
bf24ba2
891e0e9
bf24ba2
 
 
 
 
b7997c9
891e0e9
3d2f114
 
 
6022e1b
 
 
2aa7bb1
3d2f114
b7997c9
891e0e9
b7997c9
6022e1b
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
import gradio as gr
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import tensorflow as tf
from tensorflow.keras.preprocessing import image
from tensorflow.keras.models import load_model
from tensorflow.keras.applications.efficientnet import preprocess_input


model = load_model("efficent_netB7.h5")


waste_labels = {0: 'Fibres', 1: 'Nanowires', 2: 'Particles', 3: 'Powder'}


def classify_image(pil_image):
    
    img = image.img_to_array(pil_image)
    
 
    img = tf.image.resize(img, (600, 600))
    
    
    img = np.expand_dims(img, axis=0)
    
    
    img = preprocess_input(img)
    

    prediction = model.predict(img)
    
    
    predicted_class = np.argmax(prediction)
    predicted_class_name = waste_labels[predicted_class]
    confidence = prediction[0, np.argmax(prediction)]

    
    class_names = list(waste_labels.values())
    probabilities = prediction[0]

    print(class_names)
    print(probabilities)
   
    plt.bar(class_names, probabilities, color='blue')
    plt.xlabel('Waste Classes')
    plt.ylabel('Probability')
    plt.title('Prediction Probabilities')
    plt.savefig('prediction_plot.png')
    plt.close()

    
    output_text = f"Predicted Class: {predicted_class_name}, Confidence: {confidence:.4f}\n"
    for class_name, prob in zip(class_names, probabilities):
        output_text += f"{class_name}: {prob:.4f}\n"

    return output_text, 'prediction_plot.png'


iface = gr.Interface(fn=classify_image, 
                     inputs="image", 
                     outputs=["text", "image"],
                     examples=["L9_1b95a3808073c0edad3454d1dedf3dcc.jpg","L6_0a171beb21a6f4d6fef31f8ccb400eae.jpg","L2_00a6b5e9806a8b072b98fdeacb3f45b5.jpg","L4_0b02898e9d31954dd5378e0ffbdb9a41.jpg"],
                     title= "SEM IMAGES CLASSIFICATION",
                     description= "Fibres, Nanowires, Particles, Powder SEM görüntülerini sınıflandıran model arayüzü",
                     theme=gr.themes.Monochrome(),
                     live=True)


iface.launch()