dataset train metas: 27097 dataset test metas: 7546 loading model True Traceback (most recent call last): File "/root/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 308, in _check_seekable f.seek(f.tell()) AttributeError: 'bool' object has no attribute 'seek' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "train.py", line 105, in <module> state_dict = torch.load(args.loadckpt) File "/root/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 579, in load with _open_file_like(f, 'rb') as opened_file: File "/root/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 235, in _open_file_like return _open_buffer_reader(name_or_buffer) File "/root/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 220, in __init__ _check_seekable(buffer) File "/root/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 311, in _check_seekable raise_err_msg(["seek", "tell"], e) File "/root/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 304, in raise_err_msg raise type(e)(msg) AttributeError: 'bool' 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.
时间: 2024-01-03 21:03:14 浏览: 349
这个错误信息表明在尝试加载模型检查点时出现了问题。具体来说,`torch.load` 方法无法从指定的文件中加载数据,因为该文件不是一个可寻址的文件对象。
根据错误信息,“'bool' object has no attribute 'seek'”这句话提示了问题的关键。这个错误通常是由于传递给 `torch.load` 方法的参数不是一个有效的文件名或文件对象。在这种情况下,`args.loadckpt` 参数的值可能是一个布尔值,而不是一个有效的文件对象。
为了解决这个问题,可以尝试使用 `io.BytesIO` 类将数据加载到内存缓冲区中,并从缓冲区中加载数据,而不是直接从文件中加载数据。具体来说,可以使用以下代码替换加载模型检查点的代码:
```
import io
if args.loadckpt:
with open(args.loadckpt, 'rb') as f:
buffer = io.BytesIO(f.read())
state_dict = torch.load(buffer)
else:
state_dict = None
```
这将打开指定的文件,将其内容读取到内存缓冲区中,并从缓冲区中加载数据。这样就可以避免由于文件不可寻址而导致的错误。
阅读全文