A fine-tuned RT-DETRv2 (ResNet-50vd backbone) model for real-time Personal Protective Equipment (PPE) compliance monitoring from industrial CCTV footage. Trained for PT
Pertamina EP Cepu (PEPC) to detect PPE compliance across 11 classes simultaneously.
Evaluated on 964 held-out validation images using COCO evaluation protocol (pycocotools).
1from transformers import AutoImageProcessor, AutoModelForObjectDetection
2from huggingface_hub import hf_hub_download
3import torch
4from PIL import Image
5
6# Load processor — use_fast=False is REQUIRED, do not remove
7processor = AutoImageProcessor.from_pretrained(
8 "PekingU/rtdetr_v2_r50vd",
9 use_fast=False
10)
11
12# Load base architecture then apply fine-tuned weights
13model = AutoModelForObjectDetection.from_pretrained(
14 "PekingU/rtdetr_v2_r50vd",
15 num_labels=11,
16 ignore_mismatched_sizes=True
17)
18weights_path = hf_hub_download(
19 repo_id="abdullahzunorain/rt-detr-v2-fine-tuned-PPE-Det",
20 filename="best_model.pt"
21)
22model.load_state_dict(
23 torch.load(weights_path, map_location="cpu", weights_only=True),
24 strict=False
25)
26model.eval()
27
28id2label = {
29 0: "person", 1: "coverall_present", 2: "helmet_present",
30 3: "helmet_absent", 4: "boot_present", 5: "glove_absent",
31 6: "coverall_absent", 7: "eyewear_absent", 8: "boot_absent",
32 9: "eyewear_present", 10: "glove_present"
33}
34
35image = Image.open("image.jpg").convert("RGB")
36inputs = processor(images=image, return_tensors="pt")
37
38with torch.no_grad():
39 outputs = model(**inputs)
40
41results = processor.post_process_object_detection(
42 outputs,
43 threshold=0.3,
44 target_sizes=[image.size[::-1]]
45)[0]
46
47for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
48 print(f"{id2label[label.item()]}: {score:.2f} @ {[round(c,1) for c in box.tolist()]}")
1import cv2
2from transformers import AutoImageProcessor, AutoModelForObjectDetection
3from huggingface_hub import hf_hub_download
4import torch
5from PIL import Image
6
7processor = AutoImageProcessor.from_pretrained(
8 "PekingU/rtdetr_v2_r50vd", use_fast=False
9)
10model = AutoModelForObjectDetection.from_pretrained(
11 "PekingU/rtdetr_v2_r50vd",
12 num_labels=11,
13 ignore_mismatched_sizes=True
14)
15weights_path = hf_hub_download(
16 repo_id="abdullahzunorain/rt-detr-v2-fine-tuned-PPE-Det",
17 filename="best_model.pt"
18)
19model.load_state_dict(
20 torch.load(weights_path, map_location="cpu", weights_only=True),
21 strict=False
22)
23model.eval()
24
25cap = cv2.VideoCapture("video.mp4")
26while cap.isOpened():
27 ret, frame = cap.read()
28 if not ret:
29 break
30 image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
31 inputs = processor(images=image, return_tensors="pt")
32 with torch.no_grad():
33 outputs = model(**inputs)
34 results = processor.post_process_object_detection(
35 outputs, threshold=0.3, target_sizes=[image.size[::-1]]
36 )[0]
37 # draw boxes on frame here
38cap.release()
1@misc{zunorain2026rtdetrv2ppe,
2 author = {Abdullah Zunorain},
3 title = {RT-DETRv2 Fine-Tuned PPE Detection},
4 year = {2026},
5 url = {https://huggingface.co/abdullahzunorain/rt-detr-v2-fine-tuned-PPE-Det}
6}