File size: 1,903 Bytes
7e0a485
 
a1f4f7b
7e0a485
a1f4f7b
7e0a485
 
a1f4f7b
7e0a485
a1f4f7b
7e0a485
 
a1f4f7b
 
 
 
 
 
 
 
7e0a485
a1f4f7b
7e0a485
a1f4f7b
7e0a485
 
a1f4f7b
7e0a485
a1f4f7b
7e0a485
 
a1f4f7b
 
 
 
 
 
7e0a485
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import torch  # Import PyTorch for tensor operations
import numpy as np  # Import NumPy for array handling

# Function to detect faults in solar panels
def detect_faults_solar(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

    results = model.predict(img_tensor, verbose=False)  # Perform inference

    faults = []  # List to store detected faults
    for detection in results[0].boxes:  # Iterate over detected objects
        class_id = int(detection.cls)
        if class_id == 0:
            faults.append({"type": "Crack", "location": (detection.xyxy[0][0].item(), detection.xyxy[0][1].item())})
        elif class_id == 1:
            faults.append({"type": "Damage", "location": (detection.xyxy[0][0].item(), detection.xyxy[0][1].item())})
        elif class_id == 4:
            faults.append({"type": "Hotspot", "location": (detection.xyxy[0][0].item(), detection.xyxy[0][1].item())})

    return faults  # Return list of faults

# Function to detect faults in windmills
def detect_faults_windmill(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

    results = model.predict(img_tensor, verbose=False)  # Perform inference

    faults = []  # List to store detected faults
    for detection in results[0].boxes:  # Iterate over detected objects
        class_id = int(detection.cls)
        if class_id == 2:
            faults.append({"type": "Blade Damage", "location": (detection.xyxy[0][0].item(), detection.xyxy[0][1].item())})
        elif class_id == 3:
            faults.append({"type": "Motor Fault", "location": (detection.xyxy[0][0].item(), detection.xyxy[0][1].item())})

    return faults  # Return list of faults