Pytorch의 소수의 학습 및 메타 학습을위한 확장 및 데이터 로더 모음. Torchmeta에는 인기있는 메타 학습 벤치 마크가 포함되어 있으며 torchvision 및 Pytorch의 DataLoader 와 완전히 호환됩니다.
MetaModule 이라는 Pytorch Module 의 얇은 확장. MetaModule 사용한 예는 MAML 예제를 참조하십시오. Python의 패키지 관리자 Pip 또는 Source에서 Torchmeta를 설치할 수 있습니다. 기존 Python 설정과의 충돌을 피하기 위해 virtualenv 와 함께 가상 환경에서 작동하는 것이 좋습니다. virtualenv 설치하려면 :
pip install --upgrade virtualenv
virtualenv venv
source venv/bin/activate이것은 Torchmeta를 설치하는 권장 방법입니다.
pip install torchmeta소스에서 Torchmeta를 설치할 수도 있습니다. Torchmeta에 기여하려는 경우 권장됩니다.
git clone https://github.com/tristandeleu/pytorch-meta.git
cd pytorch-meta
python setup.py install아래 의이 최소 예는 Torchmeta와 함께 5-샷 5 웨이 Omniglot 데이터 세트의 데이터 로더를 만드는 방법을 보여줍니다. 데이터 로더는 무작위로 생성 된 작업의 배치를로드하고 모든 샘플은 단일 텐서로 연결됩니다. 더 많은 예를 보려면 예제 폴더를 확인하십시오.
from torchmeta . datasets . helpers import omniglot
from torchmeta . utils . data import BatchMetaDataLoader
dataset = omniglot ( "data" , ways = 5 , shots = 5 , test_shots = 15 , meta_train = True , download = True )
dataloader = BatchMetaDataLoader ( dataset , batch_size = 16 , num_workers = 4 )
for batch in dataloader :
train_inputs , train_targets = batch [ "train" ]
print ( 'Train inputs shape: {0}' . format ( train_inputs . shape )) # (16, 25, 1, 28, 28)
print ( 'Train targets shape: {0}' . format ( train_targets . shape )) # (16, 25)
test_inputs , test_targets = batch [ "test" ]
print ( 'Test inputs shape: {0}' . format ( test_inputs . shape )) # (16, 75, 1, 28, 28)
print ( 'Test targets shape: {0}' . format ( test_targets . shape )) # (16, 75) 헬퍼 기능은 사용 가능한 일부 데이터 세트에서만 사용할 수 있습니다. 그러나 Torchmeta가 제공하는 통합 인터페이스를 통해 모두 사용할 수 있습니다. 위에서 정의 된 변수 dataset 다음과 같습니다.
from torchmeta . datasets import Omniglot
from torchmeta . transforms import Categorical , ClassSplitter , Rotation
from torchvision . transforms import Compose , Resize , ToTensor
from torchmeta . utils . data import BatchMetaDataLoader
dataset = Omniglot ( "data" ,
# Number of ways
num_classes_per_task = 5 ,
# Resize the images to 28x28 and converts them to PyTorch tensors (from Torchvision)
transform = Compose ([ Resize ( 28 ), ToTensor ()]),
# Transform the labels to integers (e.g. ("Glagolitic/character01", "Sanskrit/character14", ...) to (0, 1, ...))
target_transform = Categorical ( num_classes = 5 ),
# Creates new virtual classes with rotated versions of the images (from Santoro et al., 2016)
class_augmentations = [ Rotation ([ 90 , 180 , 270 ])],
meta_train = True ,
download = True )
dataset = ClassSplitter ( dataset , shuffle = True , num_train_per_class = 5 , num_test_per_class = 15 )
dataloader = BatchMetaDataLoader ( dataset , batch_size = 16 , num_workers = 4 )데이터 세트를 수신하는 데이터 로더는 동일하게 유지됩니다.
Tristan Deleu, Tobias Würfl, Mandana Samiei, Joseph Paul Cohen 및 Yoshua Bengio. Torchmeta : Pytorch의 메타 학습 라이브러리, 2019 [Arxiv]
Torchmeta를 인용하려면 다음 Bibtex 항목을 사용하십시오.
@misc{deleu2019torchmeta,
title={{Torchmeta: A Meta-Learning library for PyTorch}},
author={Deleu, Tristan and W"urfl, Tobias and Samiei, Mandana and Cohen, Joseph Paul and Bengio, Yoshua},
year={2019},
url={https://arxiv.org/abs/1909.06576},
note={Available at: https://github.com/tristandeleu/pytorch-meta}
}