【发布时间】:2022-11-05 04:59:01
【问题描述】:
我正在为超分辨率深度学习网络开发自定义图像数据集。我将图像保存到磁盘并可以创建 HDF5 数据集文件。这是我正在使用的代码:
import os, cv2, h5py, glob
import numpy as np
from glob import glob
# define the paths to the dataset
BASE_DATA_PATH = '/usr/local/home/.../esrgan_data'
HR_TRAIN_PATH = os.path.join(BASE_DATA_PATH, 'train_HR')
LR_TRAIN_PATH = os.path.join(BASE_DATA_PATH, 'train_LR')
# create LR and HR image lists
LR_images = glob(LR_TRAIN_PATH + '**/*.png')
HR_images = glob(HR_TRAIN_PATH + '**/*.png')
# sort the lists
LR_images.sort()
HR_images.sort()
# create an h5 file
with h5py.File('datasets/esrgan_trainDS.h5', 'w') as h5_file:
# create 2 datasets for LR and HR images in the h5 file
lr_ds = h5_file.create_dataset('trainLR', (len(LR_images), 150, 150, 3), dtype='f')
hr_ds = h5_file.create_dataset('trainHR', (len(HR_images), 600, 600, 3), dtype='f')
for i in range(len(LR_images)):
LR_image = cv2.imread(LR_images[i])
HR_image = cv2.imread(HR_images[i])
lr_trainDS[i] = LR_image
hr_trainDS[i] = HR_image
# load the h5 dataset
trainDS = h5py.File('datasets/esrgan_trainDS.h5', 'r')
print('Files in the training dataset: ', list(trainDS.keys()))
训练数据集中的文件:['trainER', 'trainOR']
LRset = trainDS['trainLR']
HRset = trainDS['trainHR']
print('LR dataset shape: ', LRset.shape)
print('HR dataset shape: ', HRset.shape)
LR 数据集形状:(450, 150, 150, 3) HR 数据集形状:(450, 600, 600, 3)
我的问题是,当我尝试从数据集中查看单个图像时,我看到一个黑框,告诉我图像没有保存或没有正确加载。
cv2_imshow('', HRset[100])
我基于此post 编写代码。代码运行没有错误——我可以编写 f5 文件,读取它们并打印文件属性。我只是看不到图像,而且没有错误消息,我不确定我哪里出错了。
我猜这是一个我没有看到的简单错误,但我很感激你能提供的任何帮助。谢谢!
【问题讨论】: