src/dopt_sensor_anomalies/detection.py aktualisiert

This commit is contained in:
frasu 2025-10-12 08:51:35 +00:00
parent cac37a3946
commit f2302dc90b

View File

@ -265,16 +265,12 @@ def infer_image(
torch_device = torch.device("cuda" if torch.cuda.is_available() else "cpu") torch_device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(torch_device) model.to(torch_device)
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # this is optional image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
pil_image = Image.fromarray(image_rgb) pil_image = Image.fromarray(image_rgb)
pil_image = pil_image.convert("RGB") pil_image = pil_image.convert("RGB")
input_tensor = ( image_np = np.array(pil_image).astype(np.float32) / 255.0
to_dtype(to_image(pil_image), torch.float32, scale=True) input_tensor = torch.from_numpy(image_np).permute(2, 0, 1)
if torch.as_tensor # ?? Question: Wie passt diese Funktion hier rein?
# ?? Konvertiert, aber wird zur Evaluation der Aussage genutzt (sollte immer wahr sein?)
else np.array(pil_image) / 255.0
)
# ?? Ist das immer ein Torch-Tensor? Falls nicht, müsste die Methode geändert werden
input_tensor = input_tensor.unsqueeze(0) input_tensor = input_tensor.unsqueeze(0)
input_tensor = input_tensor.to(torch_device) input_tensor = input_tensor.to(torch_device)