プリンキピア

第14章コンピュータビジョン

14.14.1. Obtaining and Organizing the Dataset14.14.1 データセットの取得と整理

The competition dataset is divided into a training set and a test set, which contain 10222 and 10357 JPEG images of three RGB (color) channels, respectively. Among the training dataset, there are 120 breeds of dogs such as Labradors, Poodles, Dachshunds, Samoyeds, Huskies, Chihuahuas, and Yorkshire Terriers.
英語のヒント
コンペティションのデータセットは訓練集合とテスト集合に分かれており、それぞれ三つのRGB(カラー)チャネルの10222枚と10357枚のJPEG画像を含む。訓練データセットには、ラブラドール、プードル、ダックスフント、サモエド、ハスキー、チワワ、ヨークシャー・テリアのような120種類の犬種がある。

14.14.1.1. Downloading the Dataset14.14.1.1 データセットをダウンロードする

After logging into Kaggle, you can click on the “Data” tab on the competition webpage shown in Fig. 14.14.1 and download the dataset by clicking the “Download All” button. After unzipping the downloaded file in ../data, you will find the entire dataset in the following paths:
英語のヒント
Kaggleにログインした後、図14.14.1に示したコンペティションのウェブページで「Data」タブをクリックし、「Download All」ボタンをクリックしてデータセットをダウンロードできる。ダウンロードしたファイルを../dataで解凍すると、次のパスにデータセット全体が見つかる。
  • ../data/dog-breed-identification/labels.csv
    英語のヒント
    ../data/dog-breed-identification/labels.csv
  • ../data/dog-breed-identification/sample_submission.csv
    英語のヒント
    ../data/dog-breed-identification/sample_submission.csv
  • ../data/dog-breed-identification/train
    英語のヒント
    ../data/dog-breed-identification/train
  • ../data/dog-breed-identification/test
    英語のヒント
    ../data/dog-breed-identification/test
You may have noticed that the above structure is similar to that of the CIFAR-10 competition in Section 14.13, where folders train/ and test/ contain training and testing dog images, respectively, and labels.csv contains the labels for the training images. Similarly, to make it easier to get started, we provide a small sample of the dataset mentioned above: train_valid_test_tiny.zip. If you are going to use the full dataset for the Kaggle competition, you need to change the demo variable below to False.
英語のヒント
上の構造は14.13節のCIFAR-10のコンペティションのものと似ていることに気づいたかもしれない。そこでは、フォルダtrain/とtest/にそれぞれ訓練用とテスト用の犬の画像が入り、labels.csvには訓練画像のラベルが入っている。同じように、始めやすくするため、上で述べたデータセットの小さな見本train_valid_test_tiny.zipを用意した。Kaggleのコンペティションに完全なデータセットを使うなら、下の変数demoをFalseに変える必要がある。
#@save
d2l.DATA_HUB['dog_tiny'] = (d2l.DATA_URL + 'kaggle_dog_tiny.zip',
                            '0cb91d09b814ecdc07b50f31f8dcad3e81d6a86d')

# If you use the full dataset downloaded for the Kaggle competition, change
# the variable below to `False`
demo = True
if demo:
    data_dir = d2l.download_extract('dog_tiny')
else:
    data_dir = os.path.join('..', 'data', 'dog-breed-identification')
Downloading ../data/kaggle_dog_tiny.zip from http://d2l-data.s3-accelerate.amazonaws.com/kaggle_dog_tiny.zip...

14.14.1.2. Organizing the Dataset14.14.1.2 データセットを整理する

We can organize the dataset similarly to what we did in Section 14.13, namely splitting out a validation set from the original training set, and moving images into subfolders grouped by labels.
英語のヒント
14.13節でしたのと同じように、データセットを整理できる。つまり、元の訓練集合から検証集合を分け、画像をラベルごとにまとめたサブフォルダに移す。
The reorg_dog_data function below reads the training data labels, splits out the validation set, and organizes the training set.
英語のヒント
下のreorg_dog_data関数は、訓練データのラベルを読み、検証集合を分け、訓練集合を整理する。
def reorg_dog_data(data_dir, valid_ratio):
    labels = d2l.read_csv_labels(os.path.join(data_dir, 'labels.csv'))
    d2l.reorg_train_valid(data_dir, labels, valid_ratio)
    d2l.reorg_test(data_dir)


batch_size = 32 if demo else 128
valid_ratio = 0.1
reorg_dog_data(data_dir, valid_ratio)