Spaces:
Runtime error
Runtime error
Update services/thermal_service.py
Browse files
services/thermal_service.py
CHANGED
@@ -1,17 +1,18 @@
|
|
1 |
-
import torch
|
2 |
-
import numpy as np
|
3 |
|
|
|
4 |
def detect_hotspots(model, image):
|
5 |
-
img_tensor = torch.from_numpy(image).permute(2, 0, 1).float() / 255.0
|
6 |
-
img_tensor = img_tensor.unsqueeze(0)
|
7 |
|
8 |
-
with torch.no_grad():
|
9 |
results = model(img_tensor)
|
10 |
|
11 |
-
hotspots = []
|
12 |
-
for detection in results[0].boxes:
|
13 |
class_id = int(detection.cls)
|
14 |
if class_id == 4:
|
15 |
hotspots.append({"type": "Hotspot", "location": (detection.xyxy[0][0].item(), detection.xyxy[0][1].item())})
|
16 |
|
17 |
-
return hotspots
|
|
|
1 |
+
import torch # Import PyTorch for tensor operations
|
2 |
+
import numpy as np # Import NumPy for array handling
|
3 |
|
4 |
+
# Function to detect hotspots (optional, for solar panels)
|
5 |
def detect_hotspots(model, image):
|
6 |
+
img_tensor = torch.from_numpy(image).permute(2, 0, 1).float() / 255.0 # Convert image to tensor
|
7 |
+
img_tensor = img_tensor.unsqueeze(0) # Add batch dimension
|
8 |
|
9 |
+
with torch.no_grad(): # Disable gradient tracking for inference
|
10 |
results = model(img_tensor)
|
11 |
|
12 |
+
hotspots = [] # List to store detected hotspots
|
13 |
+
for detection in results[0].boxes: # Iterate over detected objects
|
14 |
class_id = int(detection.cls)
|
15 |
if class_id == 4:
|
16 |
hotspots.append({"type": "Hotspot", "location": (detection.xyxy[0][0].item(), detection.xyxy[0][1].item())})
|
17 |
|
18 |
+
return hotspots # Return list of hotspots
|