一,问题描述:

        Pytorch框架,使用lmdb格式的数据集进行训练时,报错

lmdb.InvalidParameterError: Caught InvalidParameterError in DataLoader worker process 0.

二,报错详细信息:

Traceback (most recent call last):File "/home/xxxx/PycharmProjects/xxxx/utils/data_v2_squence_lstm_lmdb.py", line 453, in <module>test_dataset()File "/home/xxxx/PycharmProjects/xxxx/utils/data_v2_squence_lstm_lmdb.py", line 390, in test_datasetfor d, t in train_loader:File "/home/xxxx/miniconda3/envs/pytorch-1.7/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 435, in __next__data = self._next_data()File "/home/xxxx/miniconda3/envs/pytorch-1.7/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 1065, in _next_datareturn self._process_data(data)File "/home/xxxx/miniconda3/envs/pytorch-1.7/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_datadata.reraise()File "/home/xxxx/miniconda3/envs/pytorch-1.7/lib/python3.6/site-packages/torch/_utils.py", line 428, in reraiseraise self.exc_type(msg)
lmdb.InvalidParameterError: Caught InvalidParameterError in DataLoader worker process 0.
Original Traceback (most recent call last):File "/home/xxxx/miniconda3/envs/pytorch-1.7/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loopdata = fetcher.fetch(index)File "/home/xxxx/miniconda3/envs/pytorch-1.7/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetchdata = [self.dataset[idx] for idx in possibly_batched_index]File "/home/xxxx/miniconda3/envs/pytorch-1.7/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>data = [self.dataset[idx] for idx in possibly_batched_index]File "/home/xxxx/PycharmProjects/xxxx/utils/data_v2_squence_lstm_lmdb.py", line 293, in __getitem__img = self.query_by_key(query_key, lmdb_dir)File "/home/xxxx/PycharmProjects/xxxx/utils/data_v2_squence_lstm_lmdb.py", line 137, in query_by_keydb = lmdb.open(lmdb_path, subdir=os.path.isdir(lmdb_path), readonly=True)
lmdb.InvalidParameterError: mdb_txn_begin: Invalid argument

三,原因分析:

1,报错分析

可以看到报错信息是在打开lmdb文件时发生了错误。

db = lmdb.open(lmdb_path, subdir=os.path.isdir(lmdb_path), readonly=True)

2,问题参考

这个 问答 提到

LMDB will keep separate processes from overwriting over each other. However, it can't distinguish between requests from the same process from different environment objects. This will lead to data corruption.

Each process should open its own environment object (pointing at the same path).


LMDB将防止独立进程相互覆盖。但是,它不能区分来自不同环境对象的相同进程的请求。这将导致数据损坏。

每个进程应该打开自己的环境对象(指向相同的路径)。

3,lmdb.open参数查看

open方法中有一个 lock 参数

文档中说明如下

`lock`:If ``False``, don't do any locking. If concurrent access isanticipated, the caller must manage all concurrency itself. Forproper operation the caller must enforce single-writer semantics,and must ensure that no readers are using old transactions while awriter is active. The simplest approach is to use an exclusive lockso that no readers may be active at all when a writer begins.

如果为' False ',则不进行任何锁定。如果并发访问是预期的,调用方必须管理所有并发性本身。对于正确的操作,调用者必须强制单single-writer语义,并且必须确保在写入器处于活动状态时没有任何reader在使用旧事务。最简单的方法是使用独占锁,这样当writer开始时,就没有任何readers是活动的。

所以为了保证数据安全性,默认lock是True的,此时不支持多reader访问,所以关闭此参数即可解决。

4,其他不好的解决方法

number_worker=0

这个 回答 中说到可以把number_worker设置为0,确实可以解决这个问题,但是肯定会导致速度变慢,不推荐使用。

四,解决方案:

读取lmdb文件时,lock设置为False


# lock设置为False
db = lmdb.open(lmdb_path, subdir=os.path.isdir(lmdb_path), readonly=True, lock=False)

五,引用:

lmdb.InvalidParameterError: mdb_txn_begin: Invalid argument · Issue #289 · jnwatson/py-lmdb · GitHubAffected Operating Systems Linux Affected py-lmdb Version '1.0.0' py-lmdb Installation Method pip install lmdb Using bundled or distribution-provided LMDB library? Bundled Distribution name and LMDB library version (0, 9, 24) Machine "fr...https://github.com/jnwatson/py-lmdb/issues/289

Python迭代DataLoader时出现TypeError: Caught TypeError in DataLoader worker process 0.错误。_小心丶的博客-CSDN博客_raise self.exc_type(msg)迭代DataLoader时出现TypeError: Caught TypeError in DataLoader worker process 0.错误。遇见一个难以解决的问题遇见一个难以解决的问题迭代 DataLoader时出现以下错误,暂时不知道怎么解决,向大家求救,是一个比较稀罕的错误,也分享给大家一个奇葩的问题一起讨论。Traceback (most recent call last...https://blog.csdn.net/weixin_45093926/article/details/103330105

python - lmdb.BadRslotError : mdb_txn_begin: MDB_BAD_RSLOT: Invalid reuse of reader locktable slot? - IT工具网https://www.coder.work/article/7789480

python - lmdb.BadRslotError: mdb_txn_begin: MDB_BAD_RSLOT: Invalid reuse of reader locktable slot? - Stack Overflowhttps://stackoverflow.com/questions/56905502/lmdb-badrsloterror-mdb-txn-begin-mdb-bad-rslot-invalid-reuse-of-reader-lockta

pytorch读取lmdb文件报错,lmdb.InvalidParameterError:解决相关推荐

  1. 已解决(Python读取xml文件报错)xmL.etree.ELementTree.ParseError:not well-formed (invalid token): Line

    已解决(Python读取xml文件报错)xmL.etree.ELementTree.ParseError:not well-formed (invalid token): Line 文章目录 报错信息 ...

  2. Python读取xls文件报错:raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+‘; not supported‘)

    Python读取xls文件报错:raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+': not supported') 只需要下载pyexce ...

  3. Python——CSV读取大文件报错_csv.Error: field larger than field limit

    Python--CSV读取大文件报错_csv.Error: field larger than field limit 使用Python读取较大的csv文件时,可能出现大字段,导致超过字段默认限制,从 ...

  4. 已解决Python pandas.read_excel读取Excel文件报错

    已解决(Python pandas.read_excel读取Excel文件报错)io = ExcelFile(io,storage_options=storage.options, engine=en ...

  5. python 读取xlsx文件报错,解决方法 ( xlrd 2.0.1 仅支持 .xls 文件)

    一.问题: python读取xlsx文件报错,报错信息如下: 为什么会报错?那是因为xlrd 2.0.1 仅支持 .xls 文件. 二.解决方法: 1.确认自己安装的xlrd版本: 可以先用以下命令看 ...

  6. eslint 验证vue文件 报错 unexpected token =解决方法

    eslint 验证vue文件 报错 unexpected token =解决方法 参考文章: (1)eslint 验证vue文件 报错 unexpected token =解决方法 (2)https: ...

  7. R文件报错原因及解决办法汇总

    1.如果是导入项目出现这个问题,一般是R文件没有更新造成(据说导入项目,R不会自动更新).可以Project--clean以下,R文件会重新生成. 2.选择工程,右键 Android Tools &g ...

  8. python读取中文文件报错-Python3 解决读取中文文件txt编码的问题

    问题描述 尝试用Python写一个Wordcloud的时候,出现了编码问题. 照着网上某些博客的说法添添改改后,结果是变成了"UnicodeDecodeError: "utf-8' ...

  9. Python-pydicom读取dcm文件报错-2021.6.5

    读取别的文件的时候都好好的,在读一个小文件的时候,报错. 具体报错如下: RuntimeError: The following handlers are available to decode th ...

  10. xarray+cfgrib读取grib文件——报错总结

    按照这个教程安装cfgrib和xarray后,遇到一系列问题,在此记录这些问题以及解决方案Windows下xarray+cfgrib读取grib文件_小朱小朱绝不服输的博客-CSDN博客_cfgrib ...

最新文章

  1. python代码大全表解释-python操作列表的函数使用代码详解
  2. selenium python 安装
  3. 局域网内访问mysql数据库
  4. seaborn 教程_使用Seaborn进行数据可视化教程
  5. linux分区转换gpt命令,Linux中磁盘如何转换GPT格式
  6. 华为云ROMA,联接企业应用的现在与未来
  7. poj[2230]Watchcow 深搜 欧拉回路
  8. 线性代数及其应用 知识整理
  9. c语言程序设计谭浩强题库,谭浩强c语言程序设计习题答案
  10. python 递归函数例子
  11. 校园网络登陆显示通信服务器异常,校园网络监控技术方案设计.docx
  12. VC6.0内存泄露检测工具
  13. 将word文档转换为图片格式的PDF
  14. Unity-汽车仿真-1.车库UI菜单滑动功能(利用iTween)
  15. 用c/c++和Java语言实现庞加莱回归
  16. 论文阅读笔记:Retinal blood vessel segmentation using fully convolutional network with transfer learning
  17. 南京大学iSE智能软件工程实验室
  18. 为什么 C++ 中成员函数指针是 16 字节?
  19. 大图算法——《Computing top-k temporal closeness in temporal networks》论文随记
  20. 信息度量(一):自信息、互信息与信息散度

热门文章

  1. 请启动windows零配置(wzc)服务
  2. 无线通信设备安装工程概预算编制_建筑安装工程,预算编制中易遗漏总结分享...
  3. 卸载IE8 恢复IE6 的两种方法
  4. 微信小程序地图导航实例讲解
  5. About Oracle TraceFile
  6. FileZilla客户端远程连接FTP中文出现乱码
  7. Firebug 入门指南
  8. 开源绘图工具drawio
  9. 读一本自己心爱的书,冒什么风险都是值得的
  10. linux CFI接口,Linux系统下的MTD/CFI驱动介绍