File size: 1,620 Bytes
c8c5ca6 2b35299 c8c5ca6 96f138d 2b35299 96f138d c8c5ca6 96f138d 9e94818 96f138d 2b35299 96f138d 2b35299 96f138d 2b35299 96f138d c8c5ca6 96f138d 2b35299 96f138d c8c5ca6 96f138d 9e94818 96f138d 2b35299 96f138d 2b35299 96f138d c8c5ca6 2b35299 |
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 39 40 41 42 |
import torch
import numpy as np
def detect_faults_solar(model, image):
# Preprocess image
img_tensor = torch.from_numpy(image).permute(2, 0, 1).float() / 255.0
img_tensor = img_tensor.unsqueeze(0)
# Perform inference using ultralytics API
results = model.predict(img_tensor, verbose=False)
# Process results
faults = []
for detection in results[0].boxes: # ultralytics API
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
def detect_faults_windmill(model, image):
# Preprocess image
img_tensor = torch.from_numpy(image).permute(2, 0, 1).float() / 255.0
img_tensor = img_tensor.unsqueeze(0)
# Perform inference using ultralytics API
results = model.predict(img_tensor, verbose=False)
# Process results
faults = []
for detection in results[0].boxes:
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 |