1. 文件格式形式

2. 读取选取的文件夹
# 数据集的根目录
img_path_input = r'val\input'
img_path_ph_A = r'val\ph_A'
img_path_ph_B = r'val\ph_B'
# 遍历该目录下的所有图片文件
def read_directory(directory_name):
array_of_img = [] # this if for store all of the image data
for filename in os.listdir(directory_name):
img = cv2.imread(directory_name + '/' + filename)
####change to gray
# (下面第一行是将RGB转成单通道灰度图,第二步是将单通道灰度图转成3通道灰度图)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#image_np = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
array_of_img.append(img)
return array_of_img
image_input = read_directory(img_path_input)
image_ph_A = read_directory(img_path_ph_A)
image_ph_B = read_directory(img_path_ph_B)
3. 转为张量Tensor格式
image_input = torch.Tensor(np.array(image_input))
image_ph_A = torch.Tensor(np.array(image_ph_A))
image_ph_B = torch.Tensor(np.array(image_ph_B))