第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 . The
ToTensor transformation will project the pixel value into , while our generator will use the tanh function to obtain outputs in . Therefore we normalize the data with mean and standard deviation to match the value range.英語のヒント
各画像をに大きさを変える。
ToTensorの変換は画素の値をに射影するが、生成器はtanh関数を使っての出力を得る。したがって、値の範囲を合わせるため、平均、標準偏差でデータを正規化する。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