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