การรวบรวมส่วนขยายและโหลดข้อมูลสำหรับการเรียนรู้ไม่กี่นัดและการเรียนรู้เมตาดาต้าใน Pytorch Torchmeta มีเกณฑ์มาตรฐานการเรียนรู้ meta-learning ยอดนิยมเข้ากันได้อย่างเต็มที่กับ DataLoader ของ torchvision และ Pytorch
Module ของ Pytorch ที่เรียกว่า MetaModule ซึ่งทำให้การสร้างแบบจำลองการเรียนรู้ meta บางอย่างง่ายขึ้น (เช่นวิธีการเรียนรู้เมตาเรียนรู้จากการไล่ระดับสี) ดูตัวอย่าง MAML สำหรับตัวอย่างโดยใช้ MetaModule คุณสามารถติดตั้ง Torchmeta ได้ทั้งการใช้ PARGAN PACKANCE MANAGER PIP ของ Python หรือจากแหล่งที่มา เพื่อหลีกเลี่ยงความขัดแย้งใด ๆ กับการตั้งค่า 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ตัวอย่างน้อยที่สุดด้านล่างนี้แสดงวิธีสร้าง Dataloader สำหรับชุดข้อมูล Omniglot 5-shot 5-way กับ Torchmeta Dataloader โหลดชุดของงานที่สร้างขึ้นแบบสุ่มและตัวอย่างทั้งหมดจะถูกรวมเข้ากับเทนเซอร์เดียว สำหรับตัวอย่างเพิ่มเติมตรวจสอบโฟลเดอร์ตัวอย่าง
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 )โปรดทราบว่า dataloader ที่ได้รับชุดข้อมูลยังคงเหมือนเดิม
Tristan Deleu, Tobias Würfl, Mandana Samiei, Joseph Paul Cohen และ Yoshua Bengio Torchmeta: A Meta-Learning Library สำหรับ 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}
}