Safety helmet detection using hailo-rpi

Hello,

I am trying out the below tutorial by @shahizat for safety helmet detection. I got upto the point of installing yolo and converting PASCAL VOC format to the format required by YOLOv8.

Now I am stuck at the point of running yolo detect task as there is no mention of the contents of data.yaml.

Please help.

Detection task is up and running with batch size of 12 and epoch of 100. Looks like each epoch takes about 3.5 hours. So, will take about 15 days to complete.

Any thoughts about speeding this up? is it using GPU at all?

Hey @ngr,

Could you please provide a log for us to review?
It should be using the GPU. Also, keep in mind that not all epochs take the same amount of time.

Please find the logs below. It is up to epoch 13 in ~2 days.

Thanks for looking into this.

yolo task=detect mode=train model=yolov8n.pt data=dataset.yaml epochs=100 imgsz=640 batch=12

New ultralytics · PyPI available Update with ‘pip install -U ultralytics’
Ultralytics YOLOv8.2.79 Python-3.11.2 torch-2.4.0 CPU (Cortex-A76)
engine/trainer: task=detect, mode=train, model=yolov8n.pt, data=dataset.yaml, epochs=100, time=None, patience=100, batch=12, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=train10, exist_ok=False, pretrained=True, optimizer=auto, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, amp=True, fraction=1.0, profile=False, freeze=None, multi_scale=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, vid_stride=1, stream_buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, show_boxes=True, line_width=None, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, bgr=0.0, mosaic=1.0, mixup=0.0, copy_paste=0.0, auto_augment=randaugment, erasing=0.4, crop_fraction=1.0, cfg=None, tracker=botsort.yaml, save_dir=runs/detect/train10
Overriding model.yaml nc=80 with nc=3

               from  n    params  module                                       arguments                     

0 -1 1 464 ultralytics.nn.modules.conv.Conv [3, 16, 3, 2]
1 -1 1 4672 ultralytics.nn.modules.conv.Conv [16, 32, 3, 2]
2 -1 1 7360 ultralytics.nn.modules.block.C2f [32, 32, 1, True]
3 -1 1 18560 ultralytics.nn.modules.conv.Conv [32, 64, 3, 2]
4 -1 2 49664 ultralytics.nn.modules.block.C2f [64, 64, 2, True]
5 -1 1 73984 ultralytics.nn.modules.conv.Conv [64, 128, 3, 2]
6 -1 2 197632 ultralytics.nn.modules.block.C2f [128, 128, 2, True]
7 -1 1 295424 ultralytics.nn.modules.conv.Conv [128, 256, 3, 2]
8 -1 1 460288 ultralytics.nn.modules.block.C2f [256, 256, 1, True]
9 -1 1 164608 ultralytics.nn.modules.block.SPPF [256, 256, 5]
10 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, ‘nearest’]
11 [-1, 6] 1 0 ultralytics.nn.modules.conv.Concat [1]
12 -1 1 148224 ultralytics.nn.modules.block.C2f [384, 128, 1]
13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, ‘nearest’]
14 [-1, 4] 1 0 ultralytics.nn.modules.conv.Concat [1]
15 -1 1 37248 ultralytics.nn.modules.block.C2f [192, 64, 1]
16 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2]
17 [-1, 12] 1 0 ultralytics.nn.modules.conv.Concat [1]
18 -1 1 123648 ultralytics.nn.modules.block.C2f [192, 128, 1]
19 -1 1 147712 ultralytics.nn.modules.conv.Conv [128, 128, 3, 2]
20 [-1, 9] 1 0 ultralytics.nn.modules.conv.Concat [1]
21 -1 1 493056 ultralytics.nn.modules.block.C2f [384, 256, 1]
22 [15, 18, 21] 1 751897 ultralytics.nn.modules.head.Detect [3, [64, 128, 256]]
Model summary: 225 layers, 3,011,433 parameters, 3,011,417 gradients, 8.2 GFLOPs

Transferred 319/355 items from pretrained weights
Freezing layer ‘model.22.dfl.conv.weight’
/home/rpi/work/helmet/lib/python3.11/site-packages/ultralytics/engine/trainer.py:271: FutureWarning: torch.cuda.amp.GradScaler(args...) is deprecated. Please use torch.amp.GradScaler('cuda', args...) instead.
self.scaler = torch.cuda.amp.GradScaler(enabled=self.amp)
train: Scanning /home/rpi/work/helmet/datasets/dataset/labels.cache… 5000 images, 0 backgrounds, 0 corrupt: 100%|██████████| 5000/5000 [00:00<?, ?it/s]
val: Scanning /home/rpi/work/helmet/datasets/dataset/labels.cache… 5000 images, 0 backgrounds, 0 corrupt: 100%|██████████| 5000/5000 [00:00<?, ?it/s]
Plotting labels to runs/detect/train10/labels.jpg…
optimizer: ‘optimizer=auto’ found, ignoring ‘lr0=0.01’ and ‘momentum=0.937’ and determining best ‘optimizer’, ‘lr0’ and ‘momentum’ automatically…
optimizer: AdamW(lr=0.001429, momentum=0.9) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.00046875), 63 bias(decay=0.0)
Image sizes 640 train, 640 val
Using 0 dataloader workers
Logging results to runs/detect/train10
Starting training for 100 epochs…

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
  1/100         0G       1.52      1.688      1.216         48        640: 100%|██████████| 417/417 [2:32:25<00:00, 21.93s/it]  
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 209/209 [1:08:35<00:00, 19.69s/it]
               all       5000      25502      0.912      0.496      0.558      0.328

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
  2/100         0G      1.448      1.164      1.186         70        640: 100%|██████████| 417/417 [2:45:06<00:00, 23.76s/it]  
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 209/209 [1:06:52<00:00, 19.20s/it]
               all       5000      25502      0.897      0.517      0.575      0.334

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
  3/100         0G      1.433      1.061      1.181         82        640: 100%|██████████| 417/417 [2:47:54<00:00, 24.16s/it]  
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 209/209 [1:10:39<00:00, 20.28s/it]
               all       5000      25502      0.902      0.493      0.557        0.3

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
  4/100         0G      1.418      1.011      1.178         59        640: 100%|██████████| 417/417 [2:36:40<00:00, 22.54s/it]  
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 209/209 [1:09:09<00:00, 19.86s/it]
               all       5000      25502      0.919      0.528      0.589      0.359

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
  5/100         0G      1.395     0.9661      1.174         88        640: 100%|██████████| 417/417 [2:40:22<00:00, 23.08s/it]  
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 209/209 [1:09:17<00:00, 19.89s/it]
               all       5000      25502       0.93      0.551      0.606      0.373

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
  6/100         0G      1.374     0.9265      1.163         68        640: 100%|██████████| 417/417 [2:39:58<00:00, 23.02s/it]  
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 209/209 [1:11:39<00:00, 20.57s/it]      	
               all       5000      25502      0.934       0.55      0.605      0.373

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
  7/100         0G      1.362     0.9035      1.156         91        640: 100%|██████████| 417/417 [2:54:14<00:00, 25.07s/it]  
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 209/209 [1:13:28<00:00, 21.09s/it]
               all       5000      25502      0.928      0.562       0.61      0.386

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
  8/100         0G      1.362     0.8804      1.147         67        640: 100%|██████████| 417/417 [2:55:44<00:00, 25.29s/it]  
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 209/209 [1:12:19<00:00, 20.76s/it]
               all       5000      25502      0.933      0.564      0.612      0.385

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
  9/100         0G      1.342     0.8569      1.148         40        640: 100%|██████████| 417/417 [3:00:41<00:00, 26.00s/it]  
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 209/209 [1:11:05<00:00, 20.41s/it]
               all       5000      25502      0.941      0.561      0.618      0.387

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
 10/100         0G      1.338     0.8457      1.139         33        640: 100%|██████████| 417/417 [2:46:12<00:00, 23.92s/it]  
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 209/209 [1:12:17<00:00, 20.75s/it]
               all       5000      25502      0.939      0.573      0.621      0.399

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
 11/100         0G      1.316     0.8324      1.133         42        640: 100%|██████████| 417/417 [2:52:32<00:00, 24.83s/it]  
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 209/209 [1:12:30<00:00, 20.82s/it]
               all       5000      25502      0.942      0.573      0.624      0.393

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
 12/100         0G      1.327     0.8214       1.14         49        640: 100%|██████████| 417/417 [3:05:05<00:00, 26.63s/it]  
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 209/209 [1:11:21<00:00, 20.49s/it]
               all       5000      25502      0.939      0.567      0.624      0.389

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
 13/100         0G      1.325     0.8227       1.13         70        640:  61%|██████    | 253/417 [2:03:43<2:26:17, 53.52s/it]

Finally the model is ready. However it wont run on rpi/hailo because it was compiled using 3.28 :person_facepalming:

have to re-do the hef part.

Got the model working. however it is only detecting person. No helmet and head detection.

What could be wrong??