text_plain_output_5.png text_plain_output_4.png text_plain_output_6.png text_plain_output_3.png text_plain_output_7.png text_plain_output_8.png text_plain_output_2.png text_plain_output_1.png
from transformers import ViTImageProcessor

from transformers import ViTImageProcessor
processor = ViTImageProcessor.from_pretrained('google/vit-base-patch16-224-in21k')

from torchvision.transforms import CenterCrop, Compose, Normalize, RandomHorizontalFlip, RandomResizedCrop, Resize, ToTensor
image_mean, image_std = (processor.image_mean, processor.image_std)
size = processor.size['height']
print('Size: ', size)
normalize = Normalize(mean=image_mean, std=image_std)
_train_transforms = Compose([Resize((size, size)), RandomHorizontalFlip(), ToTensor(), normalize])
_val_transforms = Compose([Resize((size, size)), ToTensor(), normalize])
def train_transforms(examples):
    examples['pixel_values'] = [_train_transforms(image.convert('RGB')) for image in examples['image']]
    return examples
def val_transforms(examples):
    examples['pixel_values'] = [_val_transforms(image.convert('RGB')) for image in examples['image']]
    return examples