From e92ef050d1e1d48210ba5cd84473cc17b2d77114 Mon Sep 17 00:00:00 2001 From: Golden-Pigeon Date: Thu, 24 Jul 2025 22:23:15 +0800 Subject: [PATCH] fix bugs for dataset initialization. --- basicsr/data/ffhq_blind_dataset.py | 14 +++++++++----- basicsr/data/ffhq_blind_joint_dataset.py | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/basicsr/data/ffhq_blind_dataset.py b/basicsr/data/ffhq_blind_dataset.py index 9f900606..e4bc6fa4 100755 --- a/basicsr/data/ffhq_blind_dataset.py +++ b/basicsr/data/ffhq_blind_dataset.py @@ -46,11 +46,7 @@ def __init__(self, opt): else: self.crop_components = False - if self.latent_gt_path is not None: - self.load_latent_gt = True - self.latent_gt_dict = torch.load(self.latent_gt_path) - else: - self.load_latent_gt = False + self.latent_gt_dict = None if self.io_backend_opt['type'] == 'lmdb': self.io_backend_opt['db_paths'] = self.gt_folder @@ -177,6 +173,14 @@ def get_component_locations(self, name, status): def __getitem__(self, index): + + if self.latent_gt_path is not None: + self.load_latent_gt = True + if self.latent_gt_dict is None: + self.latent_gt_dict = torch.load(self.latent_gt_path) + else: + self.load_latent_gt = False + if self.file_client is None: self.file_client = FileClient(self.io_backend_opt.pop('type'), **self.io_backend_opt) diff --git a/basicsr/data/ffhq_blind_joint_dataset.py b/basicsr/data/ffhq_blind_joint_dataset.py index 0dc845f7..0bd00be6 100755 --- a/basicsr/data/ffhq_blind_joint_dataset.py +++ b/basicsr/data/ffhq_blind_joint_dataset.py @@ -45,11 +45,7 @@ def __init__(self, opt): else: self.crop_components = False - if self.latent_gt_path is not None: - self.load_latent_gt = True - self.latent_gt_dict = torch.load(self.latent_gt_path) - else: - self.load_latent_gt = False + self.latent_gt_dict = None if self.io_backend_opt['type'] == 'lmdb': self.io_backend_opt['db_paths'] = self.gt_folder @@ -169,6 +165,14 @@ def get_component_locations(self, name, status): def __getitem__(self, index): + + if self.latent_gt_path is not None: + self.load_latent_gt = True + if self.latent_gt_dict is None: + self.latent_gt_dict = torch.load(self.latent_gt_path) + else: + self.load_latent_gt = False + if self.file_client is None: self.file_client = FileClient(self.io_backend_opt.pop('type'), **self.io_backend_opt)