image 1/2 /home/yuhang/yolov5/inference/images/bus.jpg: Traceback (most recent call last): File "detect.py", line 172, in <module> detect() File "detect.py", line 73, in detect pred = model(img, augment=opt.augment)[0] File "/home/yuhang/.conda/envs/pytorch/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "/home/yuhang/yolov5/models/yolo.py", line 116, in forward return self.forward_once(x, profile) # single-scale inference, train File "/home/yuhang/yolov5/models/yolo.py", line 136, in forward_once x = m(x) # run File "/home/yuhang/.conda/envs/pytorch/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "/home/yuhang/.conda/envs/pytorch/lib/python3.8/site-packages/torch/nn/modules/upsampling.py", line 157, in forward recompute_scale_factor=self.recompute_scale_factor) File "/home/yuhang/.conda/envs/pytorch/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1614, in __getattr__ raise AttributeError("'{}' object has no attribute '{}'".format( AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
时间: 2023-08-18 07:09:03 浏览: 139
根据你提供的错误信息,看起来是在运行`detect.py`时出现了一个错误。具体来说,`Upsample`对象没有`recompute_scale_factor`属性,导致了`AttributeError`异常。
这个问题可能是由于使用的`torch.nn.Upsample`版本不兼容造成的。新版本的PyTorch中已经将`recompute_scale_factor`属性删除,并且使用了`torch.nn.functional.interpolate`函数来进行上采样操作。
要解决这个问题,你可以尝试更新代码中的`Upsample`为`torch.nn.functional.interpolate`,并相应地调整参数。你可以将以下代码段:
```python
x = m(x)
```
替换为:
```python
x = torch.nn.functional.interpolate(x, scale_factor=2, mode='nearest')
```
这将使用最近邻插值方法对`x`进行上采样。
请注意,这只是一个示例解决方案,具体取决于你的代码实现和需求。你可能需要根据你的情况进行适当的调整。