File size: 1,205 Bytes
ab185b1
 
fae3cf9
ab185b1
 
 
e4f64d1
ab185b1
 
 
 
 
 
 
 
 
 
fae3cf9
ab185b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import tensorflow as tf
import numpy as npv
from PIL import Image

# Load the model
model = tf.keras.models.load_model("cifar10_cnn_model.h5")

# CIFAR-10 class names
class_names = [
    "Airplane", "Automobile", "Bird", "Cat", "Deer",
    "Dog", "Frog", "Horse", "Ship", "Truck"
]

# Streamlit app layout
st.title("CIFAR-10 Image Classifier")
st.write("Upload an image to classify it into one of the CIFAR-10 categories.")
 
# File uploader
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])

if uploaded_file:
    # Preprocess the uploaded image
    image = Image.open(uploaded_file).resize((32, 32))
    st.image(image, caption="Uploaded Image", use_column_width=True)

    # Convert image to array
    img_array = np.array(image) / 255.0  # Normalize
    img_array = np.expand_dims(img_array, axis=0)  # Add batch dimension

    # Predict
    with st.spinner("Classifying..."):
        predictions = model.predict(img_array)
        predicted_class = class_names[np.argmax(predictions)]
        confidence = np.max(predictions)

    # Display results
    st.success(f"Prediction: {predicted_class}")
    st.info(f"Confidence: {confidence:.2f}")