<jupyter_start><jupyter_text>Inference<jupyter_code>test_dataset = GraphemeDataset(images)
test_loader = torch.utils.data.DataLoader(test_dataset, batch_size=batch_size, shuffle=False)

for pre_model in pretrained_models:
    print('model : ', str(pre_model))
    model = EfficientNet.from_my_pretrained(model_name, pre_model, in_channels=1).to(device)
    model.eval()

    predictions = np.zeros((len(test_dataset), sum(nunique)), dtype = 'float32')

    cnt = 0

    with torch.no_grad():
        for idx, inputs in tqdm(enumerate(test_loader), total=len(test_loader)):
            inputs = inputs.float().to(device)
            outputs1, outputs2, outputs3 = model(inputs)
            predictions[cnt:cnt + inputs.size()[0], 0:nunique[0]] = outputs1.cpu().numpy()
            predictions[cnt:cnt + inputs.size()[0], nunique[0]:sum(nunique[:2])] = outputs2.cpu().numpy()
            predictions[cnt:cnt + inputs.size()[0], sum(nunique[:2]):sum(nunique[:3])] = outputs3.cpu().numpy()
            cnt += inputs.size()[0]
            
    predictions = np.split(predictions, np.cumsum(nunique), axis=1)
    recall1 = get_recall(labels[:, 0], predictions[0])
    recall2 = get_recall(labels[:, 1], predictions[1])
    recall3 = get_recall(labels[:, 2], predictions[2])
    recall = np.average([recall1, recall2, recall3], weights=[2, 1, 1])
    
    del model
    del predictions
    torch.cuda.empty_cache()
    gc.collect()

    print(f'recall_grapheme  : 1.0 * {recall1}')
    print(f'recall_vowel     : 0.5 * {recall2}')
    print(f'recall_consonant : 0.5 * {recall3}')
    print('-'*50)
    print(f'final recall     : {recall}')<jupyter_output>model :  20200313_pretrained_models\base.pth
Loaded pretrained weights for efficientnet-b3
{'fraction_non_alphanumeric': 0.15535097813578827, 'fraction_numerical': 0.03222094361334868, 'mean_word_length': 3.884831460674157, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '641867', 'license': 'MIT', 'n_tokens_mistral': 626, 'n_tokens_neox': 611, 'n_words': 100, 'path': '2019/bengaliai-cv19/20200314_calc_CV_score.ipynb', 'repo_name': 'kn25ha01/kaggle-competitions', 'size': '1738'}