I want to use albumentations library to perform some augmentations on predefined CIFAR10 dataset from torchvision. This is my code for writing the dataloaders
import torch
import torchvision
import torchvision.transforms as transforms
# Albumentations for augmentations
import albumentations as A
from albumentations.pytorch import ToTensorV2
train_transforms = A.Compose(
[
A.HorizontalFlip(p=0.5),
A.ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.1, rotate_limit=45, p=0.5),
A.CoarseDropout(max_holes = 1, max_height=16, max_width=16, min_holes = 1, min_height=16, min_width=16,
fill_value=0.4734),
A.Normalize(
mean = (0.4914, 0.4822, 0.4465),
std = (0.2470, 0.2435, 0.2616),
p =1.0
),
ToTensorV2()
],
p=1.0
)
test_transforms = A.Compose(
[
A.Normalize(
mean = (0.4914, 0.4822, 0.4465),
std = (0.2470, 0.2435, 0.2616),
p =1.0
),
ToTensorV2()
]
)
torch.manual_seed(2)
use_cuda = torch.cuda.is_available()
device = torch.device("cuda" if use_cuda else "cpu")
class args():
def __init__(self,device = 'cpu' ,use_cude = False) -> None:
self.batch_size = 128
self.device = device
self.kwargs = {'num_workers': 1, 'pin_memory': True} if use_cuda else {}
# transform = transforms.Compose(
# [transforms.ToTensor(),
# transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2470, 0.2435, 0.2616))])
trainset = torchvision.datasets.CIFAR10(root='./data', train=True,
download=True, transform=train_transforms)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=args().batch_size,
shuffle=True, **args().kwargs)
testset = torchvision.datasets.CIFAR10(root='./data', train=False,
download=True, transform=test_transforms)
testloader = torch.utils.data.DataLoader(testset, batch_size=args().batch_size,
shuffle=False, **args().kwargs)
When I run the following code
tr = next(iter(trainloader))
print(len(tr))
It gives the following error -
AssertionError: force_apply must have bool or int type
Currenty running this on colab
Can I not use albumentations for the predefined datasets on Torchvision ? Will I have to write a custom dataset for CIfar10 so that I can use albumentations for augmentations?