<jupyter_start><jupyter_text>ModellingI use a model pre-trained on imagenet, and throw the spectrograms at it. Not the most elegant approach, but it will do for now!<jupyter_code>from fastai.vision import *
np.random.seed(42)

# tfms = get_transforms()
tfms=[]
data = (ImageList.from_df(train, path='../', cols=2)
      .split_by_rand_pct(.3, seed=42)
      .label_from_df(cols=1)
      .transform(tfms, size=224)
      .databunch(bs=32)
      .normalize(imagenet_stats)
     )
learn = cnn_learner(data, models.densenet201, metrics=[error_rate, accuracy, top_k_accuracy]).to_fp16().mixup()
# Train the head of the model
lr = 4e-3
learn.fit_one_cycle(3, lr)
# Not doing very well yet. Let's train the inner layers
learn.unfreeze()
learn.fit_one_cycle(20, slice(6e-5, 6e-4))
learn.save('densenet201-mixup-stg1')
np.random.seed(42)

# tfms = get_transforms()
tfms=[]
data = (ImageList.from_df(train, path='../', cols=2)
      .split_by_rand_pct(.3, seed=42)
      .label_from_df(cols=1)
      .transform(tfms, size=512)
      .databunch(bs=12)
      .normalize(imagenet_stats)
     )
learn = cnn_learner(data, models.densenet201, metrics=[error_rate, accuracy, top_k_accuracy]).to_fp16().mixup()
learn.load('densenet201-mixup-stg1')
lr = 4e-4
learn.fit_one_cycle(4, lr)
learn.save('densenet201-mixup-stg2')
learn.unfreeze()
learn.fit_one_cycle(40, slice(3e-6, 3e-5))
learn.save('densenet201-mixup-stg2b')
interp = ClassificationInterpretation.from_learner(learn)
interp.plot_confusion_matrix(figsize=(12,12), dpi=60)
interp.most_confused(min_val=2)<jupyter_output><empty_output><jupyter_text>Making a submissionSave the model's predicted probabilities to a file following the sample submission format. This can be submitted on Zindi.<jupyter_code>src = (ImageList.from_folder('../test'))
# Add the test data as a test set for the model
learn.data.add_test(src)
# Get predictions
preds, y = learn.get_preds(DatasetType.Test)
test.head()
# Add preds to test
test = test.copy()
for b in birds:
  test[b] = preds[:,learn.data.classes.index(b)]
test.head()
# Merge back into submission DF, adding a low prob prediction for rows where we had no image generated
cols = ['ID']
for b in birds:
  cols.append(b)
ss = pd.merge(sub['ID'], test[cols], on='ID', how='left' )
ss = ss.fillna(1/40) # For those with NaNs (if you only generated spectrograms for a subset of the test mp3s)
ss.head()
# Check shape
ss.shape
# Save 
ss.to_csv('./submissions/submission_starter_notebook_densenet201_mixup_142_666_20ep.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1357733175914994, 'fraction_numerical': 0.03541912632821724, 'mean_word_length': 5.169902912621359, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '364569', 'license': 'MIT', 'n_tokens_mistral': 1013, 'n_tokens_neox': 956, 'n_words': 216, 'path': 'Competition-Solutions/Audio/Fowl Escapades/Solution 3/StarterNotebook Mixup - Densenet 201.ipynb', 'repo_name': 'ZindiAfrica/Natural-Language-Processing-NLP-', 'size': '2541'}