π Initial upload of my app
Browse files- .gitattributes +2 -0
- __pycache__/ui.cpython-311.pyc +0 -0
- __pycache__/utils.cpython-311.pyc +0 -0
- app.py +29 -0
- demo/demo.mp4 +3 -0
- demo/demo.png +3 -0
- garbage-classifier-f1-score-94.ipynb +0 -0
- models/model.pth +3 -0
- ui.py +10 -0
- utils.py +35 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
demo/demo.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
demo/demo.png filter=lfs diff=lfs merge=lfs -text
|
__pycache__/ui.cpython-311.pyc
ADDED
|
Binary file (680 Bytes). View file
|
|
|
__pycache__/utils.cpython-311.pyc
ADDED
|
Binary file (1.89 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import torch
|
| 6 |
+
from utils import load_model, predict_image
|
| 7 |
+
from ui import render_ui
|
| 8 |
+
|
| 9 |
+
# Set device
|
| 10 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 11 |
+
|
| 12 |
+
# Load model
|
| 13 |
+
@st.cache_resource
|
| 14 |
+
def load():
|
| 15 |
+
return load_model("./models/model.pth", device)
|
| 16 |
+
|
| 17 |
+
model = load()
|
| 18 |
+
|
| 19 |
+
# Render UI and handle prediction
|
| 20 |
+
uploaded_file = render_ui()
|
| 21 |
+
|
| 22 |
+
if uploaded_file:
|
| 23 |
+
image = Image.open(uploaded_file)
|
| 24 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 25 |
+
|
| 26 |
+
with st.spinner("Classifying..."):
|
| 27 |
+
prediction = predict_image(model, image, device)
|
| 28 |
+
|
| 29 |
+
st.success(f"π Predicted Class: **{prediction}**")
|
demo/demo.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:36de6774a567fa088c53675ee9cb72b86ea888df51fcfc13eee3ff0e568dce4d
|
| 3 |
+
size 1390824
|
demo/demo.png
ADDED
|
Git LFS Details
|
garbage-classifier-f1-score-94.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
models/model.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:81d25a97a2a404cde92fdbdcf99e51764875356538a46d1460a087cf0809db65
|
| 3 |
+
size 98577378
|
ui.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ui.py
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
def render_ui():
|
| 6 |
+
st.title("ποΈ Garbage Classifier")
|
| 7 |
+
st.subheader("Upload an image to classify it into one of 10 garbage types.")
|
| 8 |
+
|
| 9 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 10 |
+
return uploaded_file
|
utils.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# utils.py
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
from torchvision import transforms
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
IMG_SIZE = 224 # Or your desired size
|
| 8 |
+
|
| 9 |
+
class_names = ['battery', 'biological', 'cardboard', 'clothes', 'glass',
|
| 10 |
+
'metal', 'paper', 'platic', 'shoes', 'trash']
|
| 11 |
+
|
| 12 |
+
# Transformation same as your test transform
|
| 13 |
+
test_transform = transforms.Compose([
|
| 14 |
+
transforms.Resize((IMG_SIZE, IMG_SIZE)),
|
| 15 |
+
transforms.ToTensor(),
|
| 16 |
+
])
|
| 17 |
+
|
| 18 |
+
def load_model(weights_path, device):
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
model = torch.load(weights_path, map_location=device, weights_only=False)
|
| 23 |
+
model.to(device)
|
| 24 |
+
model.eval()
|
| 25 |
+
return model
|
| 26 |
+
|
| 27 |
+
def predict_image(model, image, device):
|
| 28 |
+
image = image.convert("RGB")
|
| 29 |
+
input_tensor = test_transform(image).unsqueeze(0).to(device)
|
| 30 |
+
|
| 31 |
+
with torch.no_grad():
|
| 32 |
+
outputs = model(input_tensor)
|
| 33 |
+
_, predicted = torch.max(outputs, 1)
|
| 34 |
+
class_index = predicted.item()
|
| 35 |
+
return class_names[class_index]
|