<jupyter_start><jupyter_text>Tutorial: Use on tensors  1. Check if the operator is differentiable<jupyter_code>import beacon_aug as BA
BA.properties.isOpDifferentiable(op=BA.RandomCrop(library="torch"))<jupyter_output>********** torchvision : RandomCrop(size=(3, 3), padding=None)<jupyter_text>2.  Use the transformation operator as a layerAugmentation can also be used as network layer (e.g. [stylegan2-ada](https://github.com/NVlabs/stylegan2-ada-pytorch)) in limited data regimes<jupyter_code>import torch
import beacon_aug as BA

size= (2, 3, 8, 8)  # rgb image (8x8) batch size 2,
x = torch.rand(size, requires_grad=True, device="cpu")
y = BA.RandomCrop(library="torch",height=4,width=4).apply(x, library="torch",as_layer=True)
print(x.shape, y.shape)<jupyter_output>********** torchvision : RandomCrop(size=(4, 4), padding=None)
torch.Size([2, 3, 8, 8]) torch.Size([2, 3, 4, 4])<jupyter_text>3. Pytorch Data Loader Example<jupyter_code>from torchvision import transforms, datasets
import beacon_aug as BA


class TorchvisionAdapter:
    def __init__(self, transforms: BA.Compose):
        self.transforms = transforms

    def __call__(self, img, *args, **kwargs):
        return self.transforms(image=np.array(img))['image']


train_transform = TorchvisionAdapter(BA.Compose([
    BA.RandomResizedCrop(size=[224, 224], scale=(0.8, 1.2), library="torch"),
    BA.HorizontalFlip(library="torch"),
    BA.ColorJitter(p=0.8,library="torch"),
    BA.RandomGrayscale(p=0.2, library="torch"),
    BA.ToTensor(library="torch"),
]))

train_dataset = datasets.ImageFolder(root= "Your Data-Set-Folder",
                                     transform=train_transform)

import numpy as np
from PIL import Image

Image.fromarray(np.uint8(train_dataset[0][0]*255))<jupyter_output>********** torchvision : RandomResizedCrop(size=(224, 224), scale=(0.8, 1.2), ratio=(0.75, 1.3333), interpolation=bilinear)
********** torchvision : RandomHorizontalFlip(p=1)
********** torchvision : ColorJitter(brightness=[0.8, 1.2], contrast=[0.8, 1.2], saturation=[0.8, 1.2], hue=[-0.2, 0.2])
********** torchvision : ToTensor()
{'fraction_non_alphanumeric': 0.17356157869709937, 'fraction_numerical': 0.03851640513552068, 'mean_word_length': 5.7006369426751595, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '508871', 'license': 'MIT', 'n_tokens_mistral': 778, 'n_tokens_neox': 728, 'n_words': 150, 'path': 'ipynbs/tutorial_torch.ipynb', 'repo_name': 'adobe-research/beacon-aug', 'size': '2103'}