File size: 1,210 Bytes
d602b25
 
 
 
 
 
a3b8388
d602b25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3b8388
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
import torch
from torchvision import models, transforms
from PIL import Image
import numpy as np

# Load a pretrained ResNet50 model for thermal anomaly detection
model = models.resnet50(weights='ResNet50_Weights.IMAGENET1K_V1')  # Updated to use weights instead of pretrained
model.eval()

def detect_thermal_anomalies(image_path):
    """
    Detect thermal anomalies in solar panels using thermal images.
    Args:
    - image_path (str): Path to the thermal image file

    Returns:
    - anomaly (str): Description of the detected thermal anomaly
    """
    # Image preprocessing for ResNet
    transform = transforms.Compose([
        transforms.Resize(256),
        transforms.CenterCrop(224),
        transforms.ToTensor(),
        transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
    ])
    image = Image.open(image_path)
    image_tensor = transform(image).unsqueeze(0)

    with torch.no_grad():
        output = model(image_tensor)
        _, predicted_class = torch.max(output, 1)

    # Simulate anomaly detection (you can replace this with actual anomaly labels)
    anomaly = "Overheating detected" if predicted_class == 0 else "Normal condition"
    return anomaly