Views
No views yet
1import torch
2import torch.nn as nn
3
4# Define model architecture
5class AnomalyDetectionModel(nn.Module):
6 def __init__(self, input_dim=10):
7 super(AnomalyDetectionModel, self).__init__()
8 self.fc = nn.Sequential(
9 nn.Linear(input_dim, 128),
10 nn.ReLU(),
11 nn.Linear(128, 1),
12 nn.Sigmoid()
13 )
14
15 def forward(self, x):
16 return self.fc(x)
17
18# Load the model
19model = AnomalyDetectionModel()
20model.load_state_dict(torch.load("anomaly_detection_model.pth"))
21model.eval()1# Dummy input sample (10 features)
2input_data = torch.rand(1, 10)
3prediction = model(input_data).item()
4
5if prediction > 0.5:
6 print("Anomaly detected!")
7else:
8 print("No anomaly detected.")