File size: 1,352 Bytes
d102da9
cbd1d98
186bc30
 
 
d102da9
536d3da
186bc30
 
536d3da
f6b0099
536d3da
 
 
 
 
186bc30
 
536d3da
 
 
 
 
 
 
 
 
 
 
186bc30
 
 
536d3da
186bc30
536d3da
186bc30
 
536d3da
 
 
 
 
 
186bc30
 
 
536d3da
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
import streamlit as st
import tensorflow as tf
from tensorflow.keras.models import load_model
from PIL import Image
import numpy as np

# Load model safely (TF 2.15+)
@st.cache_resource
def load_my_model():
    return tf.keras.models.load_model(
        "src/cactus1.keras",
        compile=False,
        safe_mode=False
    )

model = load_my_model()

def process_image(img):
    img = img.resize((64, 64))
    img = np.array(img)

    # Ensure 3 channels (RGB)
    if img.ndim == 2:  
        img = np.stack([img] * 3, axis=-1)
    elif img.shape[-1] == 4:  # RGBA โ†’ RGB
        img = img[:, :, :3]

    img = img / 255.0
    img = np.expand_dims(img, axis=0)  # (1, 64, 64, 3)
    return img

st.title("๐ŸŒต Aerial Cactus Identifier")
st.write("This application detects whether an aerial image contains cactus using a Fine-Tuned ResNet50 model.")

file = st.file_uploader("Upload an aerial image", type=["jpg", "jpeg", "png"])

if file is not None:
    img = Image.open(file).convert("RGB")  # Always RGB
    st.image(img, caption="Uploaded Image", use_container_width=True)

    image_tensor = process_image(img)
    prediction = model.predict(image_tensor)[0][0]

    if prediction > 0.5:
        st.success(f"Has Cactus ๐ŸŒต (Confidence: {prediction:.2%})")
    else:
        st.error(f"No Cactus ๐Ÿœ๏ธ (Confidence: {(1 - prediction):.2%})")