How can I train YOLO v7 using only the CPU?

122 views Asked by At

I am trying to train the YOLO v7 on a custom dataset on my Mac.

I'm new to Python and have some issues. I've created the virtualenv in the project directory with Python 3.7 and prepared my dataset all like in the instructions.

After running a command python train.py --workers 1 --device cpu --batch-size 1 --epochs 20 --img 640 640 --data data/custom_data.yaml --hyp data/hyp.scratch.custom.yaml --cfg cfg/training/yolov7-custom.yaml --name yolov7-custom --weights yolov7.pt

I have an error on 73% progress.

/Users/username/Documents/PROJECT DIR/env/lib/python3.7/site-packages/torch/autocast_mode.py:162: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling
  warnings.warn('User provided device_type of \'cuda\', but CUDA is not available. Disabling')


  0/19        0G   0.03661   0.02227         0   0.05888         3       640:  73%|███████████████████       | 38/52 [04:50<01:47,  7.65s/it]


Traceback (most recent call last):
  File "train.py", line 616, in <module>
    train(hyp, opt, device, tb_writer)
  File "train.py", line 363, in train
    loss, loss_items = compute_loss_ota(pred, targets.to(device), imgs)  # loss scaled by batch_size
  File "/Users/username/Documents/PROJECT DIR/yolov7/utils/loss.py", line 585, in __call__
    bs, as_, gjs, gis, targets, anchors = self.build_targets(p, targets, imgs)
  File "/Users/username/Documents/PROJECT DIR/yolov7/utils/loss.py", line 786, in build_targets
    matching_bs[i] = torch.tensor([], device='cuda:0', dtype=torch.int64)
  File "/Users/username/Documents/PROJECT DIR/env/lib/python3.7/site-packages/torch/cuda/__init__.py", line 210, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

How can I properly resolve this? I understand some libraries in project or venv still trying to use CUDA. How can I solve it using only the CPU?

I've already tried to manually set the device as the CPU in file yolov7/utils/torch_utils.py, but nothing changed.

0

There are 0 answers