TypeError: Model.forward() missing 1 required positional argument: ‘x‘解决方法

  File "/python3.10/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
TypeError: Model.forward() missing 1 required positional argument: 'x'

网上搜索都是说减少gpu个数,试了1个gpu可以运行,多个的时候就不能运行,但这并没有解决问题。
排查代码:

if opt.teacher_weights and RANK in [-1, 0]:
    dump_image = torch.zeros((1, 3, imgsz, imgsz), device=device)   ##本行报错。分析是只有1个gpu获得了数据。改成dump_image = torch.zeros((2, 3, imgsz, imgsz), device=device)就能用2个gpu了。
    targets = torch.Tensor([[0, 0, 0, 0, 0, 0]]).to(device)
    _, features = model(dump_image, extra_features = student_kd_layers)  # forward
    _, teacher_features = teacher_model(dump_image,
                                           extra_features=teacher_kd_layers)

分析是只有1个gpu获得了数据。改成dump_image = torch.zeros((2, 3, imgsz, imgsz), device=device)就能用2个gpu了。

你可能感兴趣的:(YOLO)