没有层的张量流多图像增强



我使用

train_data_gen = tf.keras.utils.image_dataset_from_directory(...)
AUTOTUNE = tf.data.AUTOTUNE
train_data_gen = train_data_gen.cache().prefetch(buffer_size=AUTOTUNE)

我想应用多个图像变换,就像它在Pytorch中完成的那样:

# Define the transformation pipeline
transform = torchvision.transforms.Compose([
torchvision.transforms.ToTensor(),  # Convert the image to a PyTorch tensor
Resize((256, 256)),  # Resize the images to a target size while keeping the aspect ratio intact
torchvision.transforms.Pad(padding=0, fill=0.5, padding_mode='constant'),  # Add padding with the average color of the ImageNet dataset
torchvision.transforms.RandomRotation(degrees=(-15, 15)),  # Randomly rotate the image between -15 and 15 degrees
torchvision.transforms.RandomCrop(224),  # Randomly crop and resize the image to the target input size
torchvision.transforms.RandomHorizontalFlip(),  # Flip the image horizontally with a probability of 50%
torchvision.transforms.ColorJitter(brightness=0.1, contrast=0.1, saturation=0.1, hue=0.1),  # Randomly change the brightness, contrast, saturation, and hue
torchvision.transforms.RandomGrayscale(p=0.2),  # Convert the image to grayscale with a probability of 20%
torchvision.transforms.RandomErasing(p=0.2, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0.5),  # Randomly erase a rectangular region of the image
Resize((256, 256)),  # Resize the images to a target size while keeping the aspect ratio intact
torchvision.transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))  # Normalize the image according to the ImageNet dataset
])

我该怎么做呢?你能最好用一个代码例子告诉我怎么做吗?

嘿,你知道配置!!

algentation library通过不同的处理方式或多重处理的组合,如随机旋转、移位、剪切、翻转等,人为地生成训练图像。

您可以参考代码链接,

https://albumentations.ai/

蛋白沉降教程链接

最新更新