<jupyter_start><jupyter_text>TTA for the lazy, like me<jupyter_code>batch_size=1
preds = []

for i in range(10):
    test_data_loader = torch.utils.data.DataLoader(test_dataset, batch_size=batch_size, shuffle=False, num_workers=4)
    test_preds = np.zeros((len(test_dataset), 1))
    tk0 = tqdm(test_data_loader)
    for i, x_batch in enumerate(tk0):
        x_batch = x_batch["image"]
        pred = model(x_batch.to(device))
        test_preds[i * batch_size:(i + 1) * batch_size] = pred.detach().cpu().squeeze().numpy().ravel().reshape(-1, 1)
        
    preds = preds + [test_preds]
test_preds = preds[0]
for test_pred in preds[1:]:
    test_preds = test_preds + test_pred
test_preds = test_preds / 10
coef = [0.5, 1.5, 2.5, 3.5]

for i, pred in enumerate(test_preds):
    if pred < coef[0]:
        test_preds[i] = 0
    elif pred >= coef[0] and pred < coef[1]:
        test_preds[i] = 1
    elif pred >= coef[1] and pred < coef[2]:
        test_preds[i] = 2
    elif pred >= coef[2] and pred < coef[3]:
        test_preds[i] = 3
    else:
        test_preds[i] = 4


sample = pd.read_csv("/storage/aptos2019-blindness-detection/sample_submission.csv")
sample.diagnosis = test_preds.astype(int)
sample.to_csv("submission.csv", index=False)
sample<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14341387373343725, 'fraction_numerical': 0.029618082618862042, 'mean_word_length': 3.5531914893617023, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '526090', 'license': 'MIT', 'n_tokens_mistral': 536, 'n_tokens_neox': 508, 'n_words': 100, 'path': 'testing.ipynb', 'repo_name': 'MichelML/ml-aptos', 'size': '1283'}