第14章コンピュータビジョン
14.13.7. Classifying the Testing Set and Submitting Results on Kaggle14.13.7 テスト集合を分類し、Kaggleに結果を提出する
After obtaining a promising model with hyperparameters, we use all the labeled data (including the validation set) to retrain the model and classify the testing set.
英語のヒント
ハイパーパラメータで有望なモデルが得られたら、ラベルづけされたすべてのデータ(検証集合を含む)を使ってモデルを訓練し直し、テスト集合を分類する。
net, preds = get_net(), []
net(next(iter(train_valid_iter))[0])
train(net, train_valid_iter, None, num_epochs, lr, wd, devices, lr_period,
lr_decay)
for X, _ in test_iter:
y_hat = net(X.to(devices[0]))
preds.extend(y_hat.argmax(dim=1).type(torch.int32).cpu().numpy())
sorted_ids = list(range(1, len(test_ds) + 1))
sorted_ids.sort(key=lambda x: str(x))
df = pd.DataFrame({'id': sorted_ids, 'label': preds})
df['label'] = df['label'].apply(lambda x: train_valid_ds.classes[x])
df.to_csv('submission.csv', index=False)train loss 0.608, train acc 0.786
1040.8 examples/sec on [device(type='cuda', index=0), device(type='cuda', index=1)]The above code will generate a
submission.csv file, whose format meets the requirement of the Kaggle competition. The method for submitting results to Kaggle is similar to that in Section 5.7.英語のヒント
上のコードは
submission.csvファイルを生成し、その形式はKaggleのコンペティションの要件を満たす。Kaggleに結果を提出する方法は、5.7節のものと同じである。