Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the rfs transforms for cifarfs #303

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions learn2learn/vision/benchmarks/cifarfs_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,76 @@

from learn2learn.data.transforms import NWays, KShots, LoadData, RemapLabels, ConsecutiveLabels

from torchvision.transforms import Compose

def cifarfs_tasksets(
train_ways=5,
train_samples=10,
test_ways=5,
test_samples=10,
root='~/data',
data_augmentation=None,
device=None,
**kwargs,
):
"""Tasksets for CIFAR-FS benchmarks."""
data_transform = tv.transforms.ToTensor()
if data_augmentation is None:
train_data_transforms = tv.transforms.ToTensor()
test_data_transforms = tv.transforms.ToTensor()
elif data_augmentation == 'normalize':
train_data_transforms = Compose([
lambda x: x / 255.0,
])
test_data_transforms = train_data_transforms
elif data_augmentation == 'rfs2020':
"""
# original
if augment:
transform = transforms.Compose([
lambda x: Image.fromarray(x),
transforms.RandomCrop(32, padding=4),
transforms.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4),
transforms.RandomHorizontalFlip(),
lambda x: np.asarray(x),
transforms.ToTensor(),
normalize_cifar100
])
else:
transform = transforms.Compose([
lambda x: Image.fromarray(x),
transforms.ToTensor(),
normalize_cifar100
])
return transform
"""
brando90 marked this conversation as resolved.
Show resolved Hide resolved
mean = [0.5071, 0.4867, 0.4408]
std = [0.2675, 0.2565, 0.2761]
normalize = tv.transforms.Normalize(mean=mean, std=std)
train_data_transforms = Compose([
ToPILImage(),
RandomCrop(32, padding=4),
ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4),
RandomHorizontalFlip(),
ToTensor(),
brando90 marked this conversation as resolved.
Show resolved Hide resolved
normalize,
])
test_data_transforms = Compose([
ToTensor(),
normalize,
])
else:
raise('Invalid data_augmentation argument.')

train_dataset = l2l.vision.datasets.CIFARFS(root=root,
transform=data_transform,
transform=train_data_transforms,
mode='train',
download=True)
valid_dataset = l2l.vision.datasets.CIFARFS(root=root,
transform=data_transform,
transform=train_data_transforms,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be test_data_transforms, right?

mode='validation',
download=True)
test_dataset = l2l.vision.datasets.CIFARFS(root=root,
transform=data_transform,
transform=test_data_transforms,
mode='test',
download=True)
if device is not None:
Expand Down