File size: 3,704 Bytes
c4db958
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import gradio as gr
import matplotlib.pyplot as plt
import numpy as np
import PIL
import tensorflow as tf


model = tf.keras.models.load_model('model.h5')
class_name_list = ['Edible', 'Inedible', 'Poisonous']
                                   
def predict_image(img):
    # Reescalamos la imagen en 4 dimensiones
    img_4d = img.reshape(-1,224,224,3)
    # Predicción del modelo
    prediction = model.predict(img_4d)[0]
    # Diccionario con todas las clases y las probabilidades correspondientes
    return {class_name_list[i]: float(prediction[i]) for i in range(3)}
image = gr.inputs.Image(shape=(224,224))
label = gr.outputs.Label(num_top_classes=3)
title = 'Mushroom Edibility Classifier'
description = 'Get the edibility classification for the input mushroom image'
examples=[['app_interface/Boletus edulis 15 wf.jpg'],
          ['app_interface/Cantharelluscibarius5 mw.jpg'],
          ['app_interface/Agaricus augustus 2 wf.jpg'],
          ['app_interface/Coprinellus micaceus 8 wf.jpg'],
          ['app_interface/Clavulinopsis fusiformis 2 fp.jpg'],
          ['app_interface/Amanita torrendii 8 fp.jpg'],
          ['app_interface/Russula sanguinea 5 fp.jpg'],
          ['app_interface/Caloceraviscosa1 mw.jpg'],
          ['app_interface/Amanita muscaria 1 wf.jpg'],
          ['app_interface/Amanita pantherina 11 wf.jpg'],
          ['app_interface/Lactarius torminosus 6 fp.jpg'],
          ['app_interface/Amanitaphalloides1 mw.jpg']]
thumbnail = 'app_interface/thumbnail.png'
article = '''
<!DOCTYPE html>
<html>
<body>
<p>The Mushroom Edibility Classifier is an MVP for CNN multiclass classification model.<br>
It has been trained after gathering <b>5500 mushroom images</b> through Web Scraping techniques from the following web sites:</p>
<br>
<p>
<a href="https://www.mushroom.world/">- Mushroom World</a><br>
<a href="https://www.wildfooduk.com/mushroom-guide/">- Wild Food UK</a> <br>
<a href="https://www.fungipedia.org/hongos">- Fungipedia</a> 
</p>
<br>
<p style="color:Orange;">Note: <i>model created solely and exclusively for academic purposes. The results provided by the model should never be considered definitive as the accuracy of the model is not guaranteed.</i></p>

<br>
<p><b>MODEL METRICS:</b></p>  
<table>
  <tr>
    <th> </th>
    <th>precision</th>
    <th>recall</th>
    <th>f1-score</th>
    <th>support</th>
  </tr>
  <tr>
    <th>Edible</th>
    <th>0.61</th>
    <th>0.70</th>
    <th>0.65</th>
    <th>481</th>
  </tr>
  <tr>
    <th>Inedible</th>
    <th>0.67</th>
    <th>0.69</th>
    <th>0.68</th>
    <th>439</th>
  </tr>
  <tr>
    <th>Poisonous</th>
    <th>0.52</th>
    <th>0.28</th>
    <th>0.36</th>
    <th>192</th>
  </tr>
  <tr>
  <th></th>
  </tr>
  <tr>
    <th>Global Accuracy</th>
    <th></th>
    <th></th>
    <th>0.63</th>
    <th>1112</th>
  </tr>
  <tr>
    <th>Macro Average</th>
    <th>0.60</th>
    <th>0.56</th>
    <th>0.57</th>
    <th>1112</th>
  </tr>
  <tr>
    <th>Weighted Average</th>
    <th>0.62</th>
    <th>0.63</th>
    <th>0.61</th>
    <th>1112</th>
  </tr>
</table>
<br>
<p><i>Author: Íñigo Sarralde Alzórriz</i></p> 
</body>
</html>
'''

iface = gr.Interface(fn=predict_image, 
                     inputs=image, 
                     outputs=label,
                     interpretation='default',
                     title = title,
                     description = description,
                     theme = 'darkpeach',
                     examples = examples,
                     thumbnail = thumbnail,
                     article = article,
                     allow_flagging = False,
                     allow_screenshot = False,                     
                    )
iface.launch()