trainigVVG16 / src /test_model.py
scontess
dopopull
f394b7f
import streamlit as st
import tensorflow as tf
import numpy as np
from tensorflow.keras.models import load_model
from PIL import Image
import matplotlib.pyplot as plt
# ๐Ÿ“Œ Carica il modello
MODEL_PATH = "Silva.h5"
if not MODEL_PATH:
st.error("โŒ Modello non trovato! Esegui prima il training.")
else:
model = load_model(MODEL_PATH)
st.write("โœ… Modello caricato correttamente!")
# ๐Ÿ“Œ Carica un'immagine per il test
uploaded_file = st.file_uploader("๐Ÿ“ค Carica un'immagine per testare il modello", type=["jpg", "png", "jpeg"])
if uploaded_file:
# Converti l'immagine in formato compatibile
image = Image.open(uploaded_file).convert("RGB")
image = image.resize((64, 64)) # ๐Ÿ“Œ Stessa dimensione usata nel training
image_array = np.array(image) / 255.0 # Normalizzazione
image_array = np.expand_dims(image_array, axis=0) # Aggiungi batch dimension
st.image(image, caption="๐Ÿ” Immagine di test", use_column_width=True)
# ๐Ÿ“Œ Esegui la previsione
prediction = model.predict(image_array)
predicted_class = np.argmax(prediction)
st.write(f"๐Ÿ”ฎ **Classe Predetta:** {predicted_class}")