プリンキピア

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

14.14.7. Classifying the Testing Set and Submitting Results on Kaggle14.14.7 テスト集合を分類し、Kaggleに結果を提出する

Similar to the final step in Section 14.13, in the end all the labeled data (including the validation set) are used for training the model and classifying the testing set. We will use the trained custom output network for classification.
英語のヒント
14.13節の最後の手順と同じように、最後に、ラベルづけされたすべてのデータ(検証集合を含む)を使ってモデルを訓練し、テスト集合を分類する。分類には、訓練したカスタムの出力ネットワークを使う。
net = get_net(devices)
train(net, train_valid_iter, None, num_epochs, lr, wd, devices, lr_period,
      lr_decay)

preds = []
for data, label in test_iter:
    output = torch.nn.functional.softmax(net(data.to(devices[0])), dim=1)
    preds.extend(output.cpu().detach().numpy())
ids = sorted(os.listdir(
    os.path.join(data_dir, 'train_valid_test', 'test', 'unknown')))
with open('submission.csv', 'w') as f:
    f.write('id,' + ','.join(train_valid_ds.classes) + '\n')
    for i, output in zip(ids, preds):
        f.write(i.split('.')[0] + ',' + ','.join(
            [str(num) for num in output]) + '\n')
train loss 1.217
742.7 examples/sec on [device(type='cuda', index=0), device(type='cuda', index=1)]
The above code will generate a submission.csv file to be submitted to Kaggle in the same way described in Section 5.7.
英語のヒント
上のコードは、5.7節で説明したのと同じやり方でKaggleに提出するsubmission.csvファイルを生成する。