from PIL import Imageimg_path ='./images/call-hand-gesture.png'# Open the associated image file as a RGB imagesample_img = Image.open(img_path).convert('RGB')# Print the dimensions of the imageprint(f"Image Dims: {sample_img.size}")# Show the imagesample_img
print(f"Resized tensor: {resized_tensor.shape}")# Create a `PadSquare` objectpad_square = PadSquare(shift=True)# Pad the tensorpadded_tensor = pad_square(resized_tensor)print(f"Padded tensor: {padded_tensor.shape}")# Display the updated imagestack_imgs([tensor_to_pil(pad_square(resized_tensor)) for i inrange(3)])
num_bins =31custom_augmentation_space = {# Identity operation doesn't change the image"Identity": (torch.tensor(0.0), False),# Distort the image along the x or y axis, respectively."ShearX": (torch.linspace(0.0, 0.25, num_bins), True),"ShearY": (torch.linspace(0.0, 0.25, num_bins), True),# Move the image along the x or y axis, respectively."TranslateX": (torch.linspace(0.0, 32.0, num_bins), True),"TranslateY": (torch.linspace(0.0, 32.0, num_bins), True),# Rotate operation: rotates the image."Rotate": (torch.linspace(0.0, 45.0, num_bins), True),# Adjust brightness, color, contrast,and sharpness respectively."Brightness": (torch.linspace(0.0, 0.75, num_bins), True),"Color": (torch.linspace(0.0, 0.99, num_bins), True),"Contrast": (torch.linspace(0.0, 0.99, num_bins), True),"Sharpness": (torch.linspace(0.0, 0.99, num_bins), True),# Reduce the number of bits used to express the color in each channel of the image."Posterize": (8- (torch.arange(num_bins) / ((num_bins -1) /6)).round().int(), False),# Invert all pixel values above a threshold."Solarize": (torch.linspace(255.0, 0.0, num_bins), False),# Maximize the image contrast by setting the darkest color to black and the lightest to white."AutoContrast": (torch.tensor(0.0), False),# Equalize the image histogram to improve its contrast."Equalize": (torch.tensor(0.0), False),}# Create a `CustomTrivialAugmentWide` objecttrivial_aug = CustomTrivialAugmentWide(op_meta=custom_augmentation_space)# Pad the tensoraug_tensor = trivial_aug(resized_tensor)print(f"Augmented tensor: {aug_tensor.shape}")# Display the updated imagestack_imgs([tensor_to_pil(trivial_aug(resized_tensor)) for i inrange(3)])