Image Classification
Keras
English
solar-panel
defect-detection
computer-vision
deep-learning
tensorflow
transfer-learning
Instructions to use zaheerjk/Solar-Panel-Defect-Classification-Using-Deep-Learning with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zaheerjk/Solar-Panel-Defect-Classification-Using-Deep-Learning with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zaheerjk/Solar-Panel-Defect-Classification-Using-Deep-Learning") - Notebooks
- Google Colab
- Kaggle
File size: 3,290 Bytes
6ec01d0 | 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 | import streamlit as st
import tensorflow as tf
from tensorflow.keras.applications.efficientnet import preprocess_input
from PIL import Image
import numpy as np
# ------------------ Page Configuration ------------------ #
st.set_page_config(
page_title="Solar Panel Defect Classifier",
page_icon="βοΈ",
layout="centered"
)
# ------------------ Title ------------------ #
st.title("βοΈ Solar Panel Defect Classifier")
st.markdown(
"""
Upload a **Solar Panel Image** to automatically detect defects using a
fine-tuned **EfficientNet** model.
"""
)
# ------------------ Load Model ------------------ #
@st.cache_resource
def load_model():
model = tf.keras.models.load_model("Models/effnet_finetune.h5")
return model
with st.spinner("Loading AI Model..."):
model = load_model()
# ------------------ Class Names ------------------ #
CLASSES = [
"Bird-drop",
"Clean",
"Dusty",
"Electrical-damage",
"Physical-damage",
"Snow-Covered"
]
# ------------------ File Upload ------------------ #
uploaded_file = st.file_uploader(
"π€ Upload a Solar Panel Image",
type=["jpg", "jpeg", "png"]
)
# ------------------ Prediction ------------------ #
if uploaded_file is not None:
image = Image.open(uploaded_file).convert("RGB")
# Center Image
col1, col2, col3 = st.columns([1, 2, 1])
with col2:
st.image(image, width=300, caption="Uploaded Image")
st.write("")
if st.button("π Analyze Panel", type="primary", use_container_width=True):
img = image.resize((224, 224))
img_array = np.array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = preprocess_input(img_array.astype(np.float32))
with st.spinner("Analyzing the panel..."):
predictions = model.predict(img_array, verbose=0)
predicted_idx = np.argmax(predictions[0])
predicted_class = CLASSES[predicted_idx]
confidence = predictions[0][predicted_idx]
# ------------------ Result ------------------ #
st.success(f"### π Prediction: {predicted_class}")
st.info(f"**Confidence:** {confidence:.2%}")
if predicted_class == "Clean":
st.success("β
The solar panel appears to be clean and operating normally.")
else:
st.warning(
f"β οΈ Detected: **{predicted_class}**\n\nMaintenance or inspection is recommended."
)
st.divider()
# ------------------ Top 3 Predictions ------------------ #
st.subheader("π Top 3 Predictions")
top_indices = np.argsort(predictions[0])[-3:][::-1]
medals = ["π₯", "π₯", "π₯"]
for medal, idx in zip(medals, top_indices):
st.write(f"{medal} **{CLASSES[idx]}** β {predictions[0][idx]:.2%}")
st.divider()
# ------------------ Probability Chart ------------------ #
with st.expander("π View Class Probabilities"):
for cls, prob in zip(CLASSES, predictions[0]):
st.write(f"**{cls}**")
st.progress(float(prob))
st.caption(f"{prob:.2%}") |