在Jetson TX2 NX板子上使用YOLOv5-5.0训练YOLO模型出现进程直接被killed的情况

在Jetson TX2 NX板子上使用YOLOv5-5.0训练YOLO模型出现进程直接被killed的情况,这是怎么回事啊,batch-size尝试调整过,调整为1依然被killed

(yolo) hnjd@ubuntu:~/yolov5-5.0$ python train.py --weights yolov5s.pt --cfg models/yolov5s.yaml --data data/testdata.yaml --epochs 100 --batch-size 4
github: skipping check (not a git repository)
YOLOv5 🚀 2021-4-11 torch 1.8.0 CUDA:0 (NVIDIA Tegra X2, 3823.265625MB)

Namespace(adam=False, artifact_alias='latest', batch_size=4, bbox_interval=-1, bucket='', cache_images=False, cfg='models/yolov5s.yaml', data='data/testdata.yaml', device='', entity=None, epochs=100, evolve=False, exist_ok=False, global_rank=-1, hyp='data/hyp.scratch.yaml', image_weights=False, img_size=[640, 640], label_smoothing=0.0, linear_lr=False, local_rank=-1, multi_scale=False, name='exp', noautoanchor=False, nosave=False, notest=False, project='runs/train', quad=False, rect=False, resume=False, save_dir='runs/train/exp3', save_period=-1, single_cls=False, sync_bn=False, total_batch_size=4, upload_dataset=False, weights='yolov5s.pt', workers=0, world_size=1)
tensorboard: Start with 'tensorboard --logdir runs/train', view at http://localhost:6006/
hyperparameters: lr0=0.01, lrf=0.2, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, 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, mosaic=1.0, mixup=0.0
wandb: Install Weights & Biases for YOLOv5 logging with 'pip install wandb' (recommended)

                 from  n    params  module                                  arguments                     
  0                -1  1      3520  models.common.Focus                     [3, 32, 3]                    
  1                -1  1     18560  models.common.Conv                      [32, 64, 3, 2]                
  2                -1  1     18816  models.common.C3                        [64, 64, 1]                   
  3                -1  1     73984  models.common.Conv                      [64, 128, 3, 2]               
  4                -1  1    156928  models.common.C3                        [128, 128, 3]                 
  5                -1  1    295424  models.common.Conv                      [128, 256, 3, 2]              
  6                -1  1    625152  models.common.C3                        [256, 256, 3]                 
  7                -1  1   1180672  models.common.Conv                      [256, 512, 3, 2]              
  8                -1  1    656896  models.common.SPP                       [512, 512, [5, 9, 13]]        
  9                -1  1   1182720  models.common.C3                        [512, 512, 1, False]          
 10                -1  1    131584  models.common.Conv                      [512, 256, 1, 1]              
 11                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 12           [-1, 6]  1         0  models.common.Concat                    [1]                           
 13                -1  1    361984  models.common.C3                        [512, 256, 1, False]          
 14                -1  1     33024  models.common.Conv                      [256, 128, 1, 1]              
 15                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 16           [-1, 4]  1         0  models.common.Concat                    [1]                           
 17                -1  1     90880  models.common.C3                        [256, 128, 1, False]          
 18                -1  1    147712  models.common.Conv                      [128, 128, 3, 2]              
 19          [-1, 14]  1         0  models.common.Concat                    [1]                           
 20                -1  1    296448  models.common.C3                        [256, 256, 1, False]          
 21                -1  1    590336  models.common.Conv                      [256, 256, 3, 2]              
 22          [-1, 10]  1         0  models.common.Concat                    [1]                           
 23                -1  1   1182720  models.common.C3                        [512, 512, 1, False]          
 24      [17, 20, 23]  1     18879  models.yolo.Detect                      [2, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]]
Model Summary: 283 layers, 7066239 parameters, 7066239 gradients, 16.5 GFLOPS

Transferred 354/362 items from yolov5s.pt
Scaled weight_decay = 0.0005
Optimizer groups: 62 .bias, 62 conv.weight, 59 other
train: Scanning 'testdata/labels/train.cache' images and labels... 74 found, 0 missing, 0 empty, 0 corrupted: 100%|█| 74/74 [00:
val: Scanning 'testdata/labels/train.cache' images and labels... 74 found, 0 missing, 0 empty, 0 corrupted: 100%|█| 74/74 [00:00
Plotting labels... 

autoanchor: Analyzing anchors... anchors/target = 6.80, Best Possible Recall (BPR) = 1.0000
Image sizes 640 train, 640 test
Using 0 dataloader workers
Logging results to runs/train/exp3
Starting training for 100 epochs...

     Epoch   gpu_mem       box       obj       cls     total    labels  img_size
  0%|                                                                                                    | 0/19 [00:00<?, ?it/s]
Killed
(yolo) hnjd@ubuntu:~/yolov5-5.0$ sudo dmesg | tail -7
[ 1458.779068] 0 pages HighMem/MovableOnly
[ 1458.779069] 25273 pages reserved
[ 1458.779070] 188416 pages cma reserved
[ 1458.779074] SLUB: Unable to allocate memory on node -1, gfp=0x2080020(GFP_ATOMIC)
[ 1458.786545]   cache: kmalloc-256, object size: 256, buffer size: 256, default order: 0, min order: 0
[ 1458.795659]   node 0: slabs: 842, objs: 13472, free: 0
[ 1459.304455] oom_reaper: reaped process 10964 (python), now anon-rss:0kB, file-rss:490192kB, shmem-rss:4kB
(yolo) hnjd@ubuntu:~/yolov5-5.0$ 

基于Monster 组和GPT的调写:
在Jetson TX2 NX板子上出现进程被 "killed" 的情况通常是由于内存不足导致的。在训练YOLOv5模型时,模型的大小和批处理大小都会对内存需求产生影响。即使将批处理大小设置为1,仍然会出现内存不足的情况。

Jetson TX2 NX是一款嵌入式设备,其内存资源相对较有限。在训练大型模型时,可能需要考虑以下几点:

  1. 减小模型大小:可以尝试使用更小的YOLOv5模型(例如yolov5s、yolov5x)来减小模型的内存占用。

  2. 减小图像大小:可以尝试减小输入图像的分辨率(img_size),例如将其设置为更小的值,例如416x416或320x320,以减少内存需求。

  3. 减小批处理大小:已经尝试过将批处理大小设置为1,但仍然出现内存不足的问题。在这种情况下,可以进一步减小批处理大小,例如将其设置为更小的值,例如2或甚至更低,以减少内存使用量。

  4. 使用更小的训练集:如果训练集非常大,也可能会导致内存不足。可以考虑使用更小的训练集来减少内存需求。

请注意,以上措施都是为了减少内存使用量,但可能会对训练结果产生一定的影响。因此,您需要权衡内存限制和训练结果之间的平衡,并根据具体情况进行调整。

另外,还可以尝试使用其他优化策略,例如使用混合精度训练(Mixed Precision Training)来减少内存占用。这种方法可以利用半精度浮点数(FP16)进行训练,从而减少内存需求。但请注意,这需要确保您的硬件和软件支持混合精度训练。

最后,确保Jetson TX2 NX板子上已经安装了最新的驱动程序和软件更新,以确保系统的稳定性和性能。

请注意,YOLOv5的训练过程对硬件资源要求较高,特别是对于内存和计算能力的要求比较高。在资源有限的嵌入式设备上训练大型模型可能会面临一些挑战。如果应用场景允许,可以考虑在更强大的计算机或云端进行训练,然后将训练好的模型部署到Jetson TX2 NX进行推理。