|
|
|
|
|
"""
|
|
|
Created on Sun Feb 15 16:14:13 2026
|
|
|
|
|
|
@author: ottav
|
|
|
"""
|
|
|
|
|
|
import tensorflow as tf
|
|
|
import numpy as np
|
|
|
import gradio as gr
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
model = tf.keras.models.load_model('modello_guida_autonoma_cifar10.h5')
|
|
|
|
|
|
|
|
|
def classifica_immagine(img):
|
|
|
|
|
|
|
|
|
|
|
|
img = img.resize((32, 32))
|
|
|
|
|
|
|
|
|
img_array = np.array(img).astype('float32') / 255.0
|
|
|
|
|
|
|
|
|
img_array = np.expand_dims(img_array, axis=0)
|
|
|
|
|
|
|
|
|
prediction = model.predict(img_array)[0]
|
|
|
|
|
|
|
|
|
return {
|
|
|
"Veicolo": float(prediction[0]),
|
|
|
"Animale": float(prediction[1])
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface = gr.Interface(
|
|
|
fn=classifica_immagine,
|
|
|
inputs=gr.Image(type="pil", label="Carica un'immagine"),
|
|
|
outputs=gr.Label(num_top_classes=2),
|
|
|
title="Autonomous Driving Recognition",
|
|
|
description="Carica una foto (o prendila da Google). La rete neurale deciderà se è un **Veicolo** o un **Animale**.",
|
|
|
|
|
|
examples=[["camion.jpg"], ["gatto.jpg"]]
|
|
|
)
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
interface.launch() |