プリンキピア

第20章敵対的生成ネットワーク

20.2.1. The Pokemon Dataset20.2.1 ポケモンのデータセット

The dataset we will use is a collection of Pokemon sprites obtained from pokemondb. First download, extract and load this dataset.
英語のヒント
使うデータセットは、pokemondbから得たポケモンのスプライトを集めたものである。まず、このデータセットをダウンロードし、展開して読み込む。
#@save
d2l.DATA_HUB['pokemon'] = (d2l.DATA_URL + 'pokemon.zip',
                           'c065c0e2593b8b161a2d7873e42418bf6a21106c')

data_dir = d2l.download_extract('pokemon')
pokemon = torchvision.datasets.ImageFolder(data_dir)
Downloading ../data/pokemon.zip from http://d2l-data.s3-accelerate.amazonaws.com/pokemon.zip...
We resize each image into 64×64. The ToTensor transformation will project the pixel value into [0,1], while our generator will use the tanh function to obtain outputs in [−1,1]. Therefore we normalize the data with 0.5 mean and 0.5 standard deviation to match the value range.
英語のヒント
各画像を64×64に大きさを変える。ToTensorの変換は画素の値を[0,1]に射影するが、生成器はtanh関数を使って[−1,1]の出力を得る。したがって、値の範囲を合わせるため、平均0.5、標準偏差0.5でデータを正規化する。
batch_size = 256
transformer = torchvision.transforms.Compose([
    torchvision.transforms.Resize((64, 64)),
    torchvision.transforms.ToTensor(),
    torchvision.transforms.Normalize(0.5, 0.5)
])
pokemon.transform = transformer
data_iter = torch.utils.data.DataLoader(
    pokemon, batch_size=batch_size,
    shuffle=True, num_workers=d2l.get_dataloader_workers())
Let’s visualize the first 20 images.
英語のヒント
最初の20枚の画像を可視化しよう。
warnings.filterwarnings('ignore')
d2l.set_figsize((4, 4))
for X, y in data_iter:
    imgs = X[:20,:,:,:].permute(0, 2, 3, 1)/2+0.5
    d2l.show_images(imgs, num_rows=4, num_cols=5)
    break