xinntao/Real-ESRGAN · error · ValueError
'dataroot_gt' should end with '.lmdb', but received {self.gt
Error message
'dataroot_gt' should end with '.lmdb', but received {self.gt_folder} What it means
Real-ESRGAN's RealESRGANDataset validates that when the io_backend is set to 'lmdb', the gt_folder (dataroot_gt option) must point to an LMDB database directory, which by convention has a '.lmdb' suffix. The check exists because the LMDB file client uses the folder path directly as the database path, and a non-LMDB path would cause confusing downstream failures when opening the database or reading meta_info.txt. It fails fast in __init__ to surface the config mismatch immediately.
Source
Thrown at realesrgan/data/realesrgan_dataset.py:47
io_backend (dict): IO backend type and other kwarg.
use_hflip (bool): Use horizontal flips.
use_rot (bool): Use rotation (use vertical flip and transposing h and w for implementation).
Please see more options in the codes.
"""
def __init__(self, opt):
super(RealESRGANDataset, self).__init__()
self.opt = opt
self.file_client = None
self.io_backend_opt = opt['io_backend']
self.gt_folder = opt['dataroot_gt']
# file client (lmdb io backend)
if self.io_backend_opt['type'] == 'lmdb':
self.io_backend_opt['db_paths'] = [self.gt_folder]
self.io_backend_opt['client_keys'] = ['gt']
if not self.gt_folder.endswith('.lmdb'):
raise ValueError(f"'dataroot_gt' should end with '.lmdb', but received {self.gt_folder}")
with open(osp.join(self.gt_folder, 'meta_info.txt')) as fin:
self.paths = [line.split('.')[0] for line in fin]
else:
# disk backend with meta_info
# Each line in the meta_info describes the relative path to an image
with open(self.opt['meta_info']) as fin:
paths = [line.strip().split(' ')[0] for line in fin]
self.paths = [os.path.join(self.gt_folder, v) for v in paths]
# blur settings for the first degradation
self.blur_kernel_size = opt['blur_kernel_size']
self.kernel_list = opt['kernel_list']
self.kernel_prob = opt['kernel_prob'] # a list for each kernel probability
self.blur_sigma = opt['blur_sigma']
self.betag_range = opt['betag_range'] # betag used in generalized Gaussian blur kernels
self.betap_range = opt['betap_range'] # betap used in plateau blur kernels
self.sinc_prob = opt['sinc_prob'] # the probability for sinc filters
View on GitHub (pinned to a4abfb2979)
Solutions
- Change dataroot_gt in your yml to the actual LMDB directory ending in .lmdb (e.g. datasets/DIV2K/DIV2K_train.lmdb), which must contain data.mdb, lock.mdb, and meta_info.txt
- If your data is plain images, switch io_backend.type from 'lmdb' to 'disk' in the yml so the disk+meta_info path is used
- If you have no LMDB yet, generate one with scripts/data_preparation/create_lmdb.py (python create_lmdb.py --dataset DIV2K) and point dataroot_gt at the produced .lmdb folder
- If the LMDB exists but was renamed, rename it back to end with .lmdb or symlink it: ln -s /path/to/db /path/to/db.lmdb
Example fix
# before (train.yml) io_backend: type: lmdb dataroot_gt: datasets/DIV2K/train/GT # after io_backend: type: lmdb dataroot_gt: datasets/DIV2K/DIV2K_train.lmdb
Defensive patterns
Strategy: validation
Validate before calling
import os
opt = cfg['datasets']['train']
gt = opt['dataroot_gt']
if opt['io_backend']['type'] == 'lmdb':
assert gt.endswith('.lmdb'), f'dataroot_gt must end with .lmdb, got {gt}'
assert os.path.isfile(os.path.join(gt, 'meta_info.txt')), 'meta_info.txt missing in LMDB dir'
assert os.path.isfile(os.path.join(gt, 'data.mdb')), 'data.mdb missing in LMDB dir' Try / catch
try:
dataset = RealESRGANDataset(opt)
except ValueError as e:
raise SystemExit(f'Config error: {e}. Check dataroot_gt vs io_backend.type in your yml.') from e Prevention
- Always name LMDB directories with the .lmdb suffix when generating them
- Keep io_backend.type and dataroot_gt in sync: lmdb <-> .lmdb folder, disk <-> image folder + meta_info
- Add a startup sanity check in your training script that asserts the backend/path pairing before building the dataset
When it happens
Trigger: Setting io_backend.type = 'lmdb' in the yml config while dataroot_gt points to a plain image folder (e.g. datasets/DIV2K/train/GT) or an LMDB dir without the '.lmdb' extension (e.g. datasets/DIV2K_gt). Constructing RealESRGANDataset or any train script (realesrgan/train.py) with such an opt dict triggers the ValueError during dataset init.
Common situations: Converting configs from disk backend to lmdb but forgetting to update dataroot_gt; renaming the LMDB folder without the .lmdb suffix; generating LMDB with create_lmdb.py which by default emits DIV2K_train.lmdb but the user points at the source image dir; copy-paste between experiments where one dataset is packed as LMDB and another is not.
Related errors
AI-assisted analysis of xinntao/Real-ESRGAN@a4abfb2979 (2026-08-27).
Data as JSON: /api/errors/4fafc58c5a2244b5.
Report an issue: GitHub.