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 10:07:11 浏览: 217
这是一个 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 是你要加载的模型参数数据。
相关问题
Traceback (most recent call last): File "/home/bingxing2/home/scx6281/segmentanything/SAM-Adapter-PyTorch/train.py", line 271, in <module> main(config, save_path, args=args) File "/home/bingxing2/home/scx6281/segmentanything/SAM-Adapter-PyTorch/train.py", line 206, in main result1, result2, result3, result4, metric1, metric2, metric3, metric4 = eval_psnr(val_loader, model, File "/home/bingxing2/home/scx6281/segmentanything/SAM-Adapter-PyTorch/train.py", line 91, in eval_psnr result1, result2, result3, result4 = metric_fn(pred_list, gt_list) UnboundLocalError: local variable 'metric_fn' referenced before assignment ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 1) local_rank: 0 (pid: 3699190) of binary: /home/bingxing2/home/scx6281/.conda/envs/seggg/bin/python Traceback (most recent call last): File "/home/bingxing2/home/scx6281/.conda/envs/seggg/lib/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/home/bingxing2/home/scx6281/.conda/envs/seggg/lib/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/home/bingxing2/home/scx6281/.conda/envs/seggg/lib/python3.9/site-packages/torch/distributed/launch.py", line 195, in <module> main() File "/home/bingxing2/home/scx6281/.conda/envs/seggg/lib/python3.9/site-packages/torch/distributed/launch.py", line 191, in main launch(args) File "/home/bingxing2/home/scx6281/.conda/envs/seggg/lib/python3.9/site-packages/torch/distributed/launch.py", line 176, in launch run(args) File "/home/bingxing2/home/scx6281/.conda/envs/seggg/lib/python3.9/site-packages/torch/distributed/run.py", line 753, in run elastic_launch( File "/home/bingxing2/home/scx6281/.conda/envs/seggg/lib/python3.9/site-packages/torch/distributed/launcher/api.py", line 132, in __call__ return launch_agent(self._config, self._entrypoint, list(args)) File "/home/bingxing2/home/scx6281/.conda/envs/seggg/lib/python3.9/site-packages/torch/distributed/launcher/api.py", line 246, in launch_agent raise ChildFailedError( torch.distributed.elastic.multiprocessing.errors.ChildFailedError:
这个错误信息显示在运行train.py过程中出现了一个UnboundLocalError,即引用了一个未定义的变量。具体来说,是metric_fn这个变量在被引用之前没有被赋值。这可能是由于代码中的某个逻辑错误导致的。建议检查一下代码中metric_fn的定义和赋值部分,看看是否有逻辑错误或者变量名写错等问题。另外,也可以尝试在出错的地方添加一些打印语句,以便更好地定位问题所在。
Exception in thread Thread-1: Traceback (most recent call last): File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dataloader/dataloader_iter.py", line 213, in _thread_loop self._thread_done_event) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dataloader/fetcher.py", line 121, in fetch data.append(self.dataset[idx]) File "PMRID_train_dehaze_230215.py", line 76, in __getitem__ haze=Image.open(path) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/PIL/Image.py", line 2912, in open fp = builtins.open(filename, "rb") IsADirectoryError: [Errno 21] Is a directory: '/home/aistudio/hazy/.ipynb_checkpoints'
这段错误信息显示了在一个名为Thread-1的线程中发生了异常,异常的类型是IsADirectoryError,错误信息为"[Errno 21] Is a directory: '/home/aistudio/hazy/.ipynb_checkpoints'"。具体来说,是在一个名为"/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dataloader/fetcher.py"的文件的第121行代码中,调用了一个名为PMRID_train_dehaze_230215.py的文件中的__getitem__方法(即索引操作),并且在其中调用了PIL库中的Image.open方法打开一个文件,但是这个文件的路径指向的实际上是一个文件夹(目录),而不是一个文件,因此引发了异常。
阅读全文