Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +10 -8
src/streamlit_app.py
CHANGED
|
@@ -5,7 +5,7 @@ import numpy as np
|
|
| 5 |
import tempfile
|
| 6 |
import torch
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
-
from transformers import AutoImageProcessor
|
| 9 |
from PIL import Image, ImageDraw
|
| 10 |
|
| 11 |
# Fix cache permission issue
|
|
@@ -15,11 +15,11 @@ model_id = "NaveenKumar5/Solar_panel_fault_detection"
|
|
| 15 |
|
| 16 |
@st.cache_resource
|
| 17 |
def load_model():
|
| 18 |
-
|
| 19 |
model = AutoModelForObjectDetection.from_pretrained(model_id)
|
| 20 |
-
return
|
| 21 |
|
| 22 |
-
|
| 23 |
model.eval()
|
| 24 |
|
| 25 |
st.title("🔍 Solar Panel Fault Detection")
|
|
@@ -45,15 +45,16 @@ def generate_heatmap(image, boxes):
|
|
| 45 |
if uploaded_file is not None:
|
| 46 |
if uploaded_file.type.startswith("image"):
|
| 47 |
image = Image.open(uploaded_file).convert("RGB")
|
| 48 |
-
inputs =
|
|
|
|
| 49 |
with torch.no_grad():
|
| 50 |
outputs = model(**inputs)
|
| 51 |
|
| 52 |
-
scores = outputs
|
| 53 |
keep = scores > 0.5
|
| 54 |
|
| 55 |
-
boxes = outputs
|
| 56 |
-
labels = outputs
|
| 57 |
scores = scores[keep].cpu().numpy()
|
| 58 |
|
| 59 |
image_np = np.array(image)
|
|
@@ -81,3 +82,4 @@ if uploaded_file is not None:
|
|
| 81 |
|
| 82 |
elif uploaded_file.type.startswith("video"):
|
| 83 |
st.warning("Video support coming soon. For now, please upload an image.")
|
|
|
|
|
|
| 5 |
import tempfile
|
| 6 |
import torch
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
+
from transformers import AutoImageProcessor, AutoModelForObjectDetection
|
| 9 |
from PIL import Image, ImageDraw
|
| 10 |
|
| 11 |
# Fix cache permission issue
|
|
|
|
| 15 |
|
| 16 |
@st.cache_resource
|
| 17 |
def load_model():
|
| 18 |
+
processor = AutoImageProcessor.from_pretrained(model_id)
|
| 19 |
model = AutoModelForObjectDetection.from_pretrained(model_id)
|
| 20 |
+
return processor, model
|
| 21 |
|
| 22 |
+
processor, model = load_model()
|
| 23 |
model.eval()
|
| 24 |
|
| 25 |
st.title("🔍 Solar Panel Fault Detection")
|
|
|
|
| 45 |
if uploaded_file is not None:
|
| 46 |
if uploaded_file.type.startswith("image"):
|
| 47 |
image = Image.open(uploaded_file).convert("RGB")
|
| 48 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 49 |
+
|
| 50 |
with torch.no_grad():
|
| 51 |
outputs = model(**inputs)
|
| 52 |
|
| 53 |
+
scores = outputs.logits.softmax(-1)[0].max(-1).values
|
| 54 |
keep = scores > 0.5
|
| 55 |
|
| 56 |
+
boxes = outputs.pred_boxes[0][keep].cpu().numpy()
|
| 57 |
+
labels = outputs.logits.argmax(-1)[0][keep].cpu().numpy()
|
| 58 |
scores = scores[keep].cpu().numpy()
|
| 59 |
|
| 60 |
image_np = np.array(image)
|
|
|
|
| 82 |
|
| 83 |
elif uploaded_file.type.startswith("video"):
|
| 84 |
st.warning("Video support coming soon. For now, please upload an image.")
|
| 85 |
+
|