clean = load_img(self.clean_filenames[tar_index]) noisy = load_img(self.noisy_filenames[tar_index]) clean_filename = os.path.split(self.clean_filenames[tar_index])[-1] noisy_filename = os.path.split(self.noisy_filenames[tar_index])[-1] clean = clean.transpose([2,0,1]) noisy = noisy.transpose([2,0,1])
时间: 2023-03-06 18:55:34 浏览: 106
我已经加载了 clean_filenames 和 noisy_filenames 的图像,并将它们的文件名分别存储在 clean_filename 和 noisy_filename 中,并将 clean 和 noisy 的维度调换为 [2, 0, 1]。
相关问题
clean = load_img(self.clean_filenames[tar_index]) noisy = load_img(self.noisy_filenames[tar_index]) clean_filename = os.path.split(self.clean_filenames[tar_index])[-1] noisy_filename = os.path.split(self.noisy_filenames[tar_index])[-1]
我已成功加载clean_filename和noisy_filename,分别为:clean_filename:'{clean_filename}',noisy_filename:'{noisy_filename}'。
class TestDataset(Dataset): def __init__(self, folder_path, hr, lr): super(TestDataset, self).__init__() self.folder_path = folder_path self.hr = hr self.lr = lr self.hr_path = os.path.join(self.folder_path, self.hr) self.lr_path = os.path.join(self.folder_path, self.lr) self.hr_list = [entry.name for entry in os.scandir(self.hr_path) if entry.is_file()] self.lr_list = [entry.name for entry in os.scandir(self.lr_path) if entry.is_file()] self.filenames = self.hr_list self.transform = transforms.Compose([ transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) ]) def __getitem__(self, index): self.hr_name = self.hr_list[index] self.lr_name = self.lr_list[index] self.hr_item_path = os.path.join(self.hr_path, self.hr_name) self.lr_item_path = os.path.join(self.lr_path, self.lr_name) hr_img = Image.open(self.hr_item_path).convert("RGB") lr_img = Image.open(self.lr_item_path).convert("RGB") hr_img = self.transform(hr_img) lr_img = self.transform(lr_img) return lr_img, hr_img def __len__(self): return len(self.filenames)
这是一个 Python 代码段,用于定义一个名为 TestDataset 的数据集类。该类接受三个参数:文件夹路径、高分辨率图像文件夹名称和低分辨率图像文件夹名称。它通过扫描指定文件夹中的文件来获取高分辨率和低分辨率图像的文件名列表,并将其存储在 hr_list 和 lr_list 中。在 __getitem__ 方法中,它会打开指定文件夹中的图像文件,并将其转换为张量,并返回低分辨率和高分辨率图像的张量。在 __len__ 方法中,它返回文件名列表的长度。
阅读全文