File size: 831 Bytes
b6e0c17
 
a06b7df
b6e0c17
a06b7df
b6e0c17
 
a06b7df
b6e0c17
a06b7df
 
b6e0c17
 
a06b7df
 
 
 
b6e0c17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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