Spaces:
Runtime error
Runtime error
Delete services/thermal_service.py
Browse files- services/thermal_service.py +0 -23
services/thermal_service.py
DELETED
@@ -1,23 +0,0 @@
|
|
1 |
-
from transformers import DetrImageProcessor, DetrForObjectDetection
|
2 |
-
import torch
|
3 |
-
from PIL import Image
|
4 |
-
import cv2
|
5 |
-
|
6 |
-
# Load model
|
7 |
-
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
8 |
-
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
9 |
-
|
10 |
-
def detect_thermal_anomalies(frame):
|
11 |
-
image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
12 |
-
inputs = processor(images=image, return_tensors="pt")
|
13 |
-
outputs = model(**inputs)
|
14 |
-
|
15 |
-
target_sizes = torch.tensor([image.size[::-1]])
|
16 |
-
results = processor.post_process_object_detection(outputs, threshold=0.9, target_sizes=target_sizes)[0]
|
17 |
-
|
18 |
-
boxes = []
|
19 |
-
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
20 |
-
if score >= 0.9:
|
21 |
-
boxes.append(box.tolist())
|
22 |
-
|
23 |
-
return boxes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|