DSatishchandra's picture
Update services/thermal_service.py
b6e0c17 verified
raw
history blame contribute delete
831 Bytes
import torch # Import PyTorch for tensor operations
import numpy as np # Import NumPy for array handling
# Function to detect hotspots (optional, for solar panels)
def detect_hotspots(model, image):
img_tensor = torch.from_numpy(image).permute(2, 0, 1).float() / 255.0 # Convert image to tensor
img_tensor = img_tensor.unsqueeze(0) # Add batch dimension
with torch.no_grad(): # Disable gradient tracking for inference
results = model(img_tensor)
hotspots = [] # List to store detected hotspots
for detection in results[0].boxes: # Iterate over detected objects
class_id = int(detection.cls)
if class_id == 4:
hotspots.append({"type": "Hotspot", "location": (detection.xyxy[0][0].item(), detection.xyxy[0][1].item())})
return hotspots # Return list of hotspots