<jupyter_start><jupyter_text>DAM<jupyter_code>from fastai.vision.all import *
import pandas as pd
import cam
import util
base_model_name = 'densenet121-chexpert-final'

dls, labels = util.chexpert_data_loader(bs=16)
# Load the base model
model_base = cnn_learner(dls, densenet121, n_out=len(labels), path=Path('../saves/'), y_range=(0,1))
model_base.load(base_model_name)

# Set all parameters to require grad
for param in model_base.parameters():
    param.requires_grad = True
    
# Initialize DAM learner
dam_learner = util.DAM(model_base, dls, folder=Path('../saves/densenet121-dam'), lr=0.04)
print(f'Initial AUC score: {dam_learner.eval()}')
dam_learner.train(max_epoch=3, lr_div=1.25)<jupyter_output>epoch: 0, train_loss: -0.016421, train_auc:0.762398, test_auc:0.813186, lr:0.040000
Update Regularizer @ T=11182!
epoch: 1, train_loss: -0.004450, train_auc:0.749058, test_auc:0.817175, lr:0.032000
Update Regularizer @ T=11182!<jupyter_text>Get the categorywise AUC scores of the best model.<jupyter_code>dam_learner.load('m-epoch 2-2021_May_10-02_19_17.pth.tar')
categorywise_auc_scores = dam_learner.eval(average=None)
print(categorywise_auc_scores)
idx_5_labels = (2, 5, 6, 8, 10)
avg_auc = 0
for i in idx_5_labels:
    avg_auc += categorywise_auc_scores[i]
avg_auc /= len(idx_5_labels)
print(avg_auc)<jupyter_output>0.795076755911267
{'fraction_non_alphanumeric': 0.12713754646840147, 'fraction_numerical': 0.09442379182156134, 'mean_word_length': 6.735632183908046, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '188192', 'license': 'Apache-2.0', 'n_tokens_mistral': 625, 'n_tokens_neox': 550, 'n_words': 101, 'path': 'models/densenet121_256_32_hlcp_data_mod_w_img_aug_w_dam_3.ipynb', 'repo_name': 'pujandave25/chexpert', 'size': '1345'}