你可以事先旋转所有第一个形状为384的图像(反之亦然,没有什么不同).
此脚本可旋转您的图像并将其全部保存在新文件夹中:
import imageio
import numpy as np
import os
import ndimage
outPath = "rotated_images/"
path = "images/"
# iterate through the names of contents of the folder
for image_path in os.listdir(path):
# create the full input path and read the file
input_path = os.path.join(path, image_path)
image_to_rotate = imageio.imread(input_path)
# rotating all images with first shape 384
if image_to_rotate.shape[0] == 384:
# rotate the image
rotated = ndimage.rotate(image_to_rotate, 90)
else:
rotated = image_to_rotate
fullpath = os.path.join(outPath, image_path)
imageio.imsave(fullpath, rotated)
在那之后,你可以在outPath
文件夹上随意拨打image_dataset_from_directory
.
类似的东西可以在here个地方找到.