Traceback (most recent call last): File "/home/orionzj/.conda/envs/YOLOP/lib/python3.10/site-packages/torch/serialization.py", line 354, in _check_seekable f.seek(f.tell()) AttributeError: 'list' object has no attribute 'seek' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/media/orionzj/Data/PycharmProjects/YOLODS/tools/test.py", line 153, in <module> main() File "/media/orionzj/Data/PycharmProjects/YOLODS/tools/test.py", line 86, in main checkpoint = torch.load(checkpoint_file) File "/home/orionzj/.conda/envs/YOLOP/lib/python3.10/site-packages/torch/serialization.py", line 791, in load with _open_file_like(f, 'rb') as opened_file: File "/home/orionzj/.conda/envs/YOLOP/lib/python3.10/site-packages/torch/serialization.py", line 276, in _open_file_like return _open_buffer_reader(name_or_buffer) File "/home/orionzj/.conda/envs/YOLOP/lib/python3.10/site-packages/torch/serialization.py", line 261, in __init__ _check_seekable(buffer) File "/home/orionzj/.conda/envs/YOLOP/lib/python3.10/site-packages/torch/serialization.py", line 357, in _check_seekable raise_err_msg(["seek", "tell"], e) File "/home/orionzj/.conda/envs/YOLOP/lib/python3.10/site-packages/torch/serialization.py", line 350, in raise_err_msg raise type(e)(msg) AttributeError: 'list' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.
时间: 2023-08-15 08:07:11 浏览: 223
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这是一个 Python 的错误提示,看起来你在调用 torch.load() 加载模型参数时,传入的文件不是一个可以 seek 的文件对象,而是一个 list 对象。为了解决这个问题,你可以将数据提前加载到一个可 seek 的 buffer 对象中,例如 io.BytesIO,然后再调用 torch.load() 加载模型参数。你可以参考以下代码:
```
import io
import torch
# 将数据加载到一个 buffer 对象中
buffer = io.BytesIO()
torch.save(data, buffer)
# 将 buffer 对象的指针移到开头
buffer.seek(0)
# 从 buffer 对象中加载数据
data = torch.load(buffer)
```
其中,data 是你要加载的模型参数数据。
阅读全文