text_plain_output_1.png image_output_1.png
from sklearn.model_selection import StratifiedKFold, GroupKFold

import numpy as np

import os

import pandas as pd

SEED = 42
DATA_PATH = '../input/birdclef-2022/'
AUDIO_PATH = '../input/birdclef-2022/train_audio'
MEAN = np.array([0.485, 0.456, 0.406])
STD = np.array([0.229, 0.224, 0.225])
NUM_WORKERS = 4
CLASSES = sorted(os.listdir(AUDIO_PATH))
NUM_CLASSES = len(CLASSES)
class AudioParams:
    """
    Parameters used for the audio data
    """
    sr = 32000
    duration = 5
    n_mels = 224
    fmin = 20
    fmax = 16000
train = pd.read_csv('../input/birdclef-2022/train_metadata.csv')
train['file_path'] = AUDIO_PATH + '/' + train['filename']
paths = train['file_path'].values
Fold = StratifiedKFold(n_splits=5, shuffle=True, random_state=SEED)
for n, (trn_index, val_index) in enumerate(Fold.split(train, train['primary_label'])):
    train.loc[val_index, 'kfold'] = int(n)
train['kfold'] = train['kfold'].astype(int)
train.to_csv('train_folds.csv', index=False)
print(train.shape)
train.head()