-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYes_No_Classifier.py
More file actions
58 lines (46 loc) 路 2.18 KB
/
Copy pathYes_No_Classifier.py
File metadata and controls
58 lines (46 loc) 路 2.18 KB
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
import streamlit as st
import numpy as np
from tensorflow.keras.models import load_model
from PIL import Image
# --- Page Setup ---
st.title("馃摳 Origami Binary Classifier")
st.write("""
Upload an image, and this app will predict whether it is **Origami** or **Not Origami**
using a Convolutional Neural Network (CNN) trained on origami datasets.
""")
# --- Load Binary Model ---
@st.cache_resource
def load_binary_model():
return load_model("origami_yesno_final.h5") # or origami_yesno_final.keras
model = load_binary_model()
# --- File Upload ---
uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Display uploaded image
image = Image.open(uploaded_file).convert("RGB").resize((224,224))
st.image(image, caption="Uploaded Image", use_container_width=True)
# Preprocess image
img_array = np.array(image)
img_array = np.expand_dims(img_array, axis=0) / 255.0
# Prediction
prediction = model.predict(img_array)
confidence = float(prediction[0][0])
label = "Origami" if confidence > 0.5 else "Not Origami"
# Show results
st.subheader("Prediction Results")
st.write(f"**Prediction:** {label}")
st.write(f"**Confidence:** {confidence:.4f}")
# Explain Binary Classification vs. SVC
st.markdown("""
---
### 馃攳 About the Model
- **Binary Classification**:
The model decides between two classes: **Origami** or **Not Origami**.
A threshold of 0.5 determines the class.
- **CNN vs. SVC**:
- This app uses a **Convolutional Neural Network (CNN)**, which automatically learns visual features such as folds, edges, and textures.
- A **Support Vector Classifier (SVC)**, often used in earlier origami classification research, works well with numerical features but typically requires handcrafted features from images (like edges or shape descriptors).
- CNNs generally outperform SVCs for complex image recognition tasks because they learn features directly from raw pixels.
- **Confidence Score**:
Indicates how certain the model is about its prediction.
""")