第3章回帰のための線形ニューラルネットワーク
3.2.3. Data3.2.3 データ
The
DataModule class is the base class for data. Quite frequently the __init__ method is used to prepare the data. This includes downloading and preprocessing if needed. The train_dataloader returns the data loader for the training dataset. A data loader is a (Python) generator that yields a data batch each time it is used. This batch is then fed into the training_step method of Module to compute the loss. There is an optional val_dataloader to return the validation dataset loader. It behaves in the same manner, except that it yields data batches for the validation_step method in Module.英語のヒント
DataModuleクラスは、データのための基底クラスである。__init__メソッドは、データの準備に使われることがとても多い。これには、必要ならダウンロードや前処理も含まれる。train_dataloaderは訓練データセットのデータローダーを返す。データローダーとは、使われるたびにデータのバッチを生み出す(Pythonの)ジェネレータである。このバッチはその後、Moduleのtraining_stepメソッドに与えられ、損失が計算される。検証データセットのローダーを返す、省略可能なval_dataloaderもある。これも同じように振る舞うが、Moduleのvalidation_stepメソッドのためのデータのバッチを生み出す点だけが違う。class DataModule(d2l.HyperParameters): #@save
"""The base class of data."""
def __init__(self, root='../data', num_workers=4):
self.save_hyperparameters()
def get_dataloader(self, train):
raise NotImplementedError
def train_dataloader(self):
return self.get_dataloader(train=True)
def val_dataloader(self):
return self.get_dataloader(train=False)