{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.9","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":25954,"databundleVersionId":2091745,"sourceType":"competition"},{"sourceId":1297722,"sourceType":"datasetVersion","datasetId":750498},{"sourceId":2130303,"sourceType":"datasetVersion","datasetId":1278322}],"dockerImageVersionId":30086,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!nvidia-smi","metadata":{"id":"ikMF-nQSdTbF","outputId":"041c6767-86ab-46e4-9b22-a4840121ecca","papermill":{"duration":1.301859,"end_time":"2021-02-16T15:59:41.363841","exception":false,"start_time":"2021-02-16T15:59:40.061982","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-14T20:16:06.531897Z","iopub.execute_input":"2023-12-14T20:16:06.532324Z","iopub.status.idle":"2023-12-14T20:16:07.511647Z","shell.execute_reply.started":"2023-12-14T20:16:06.532237Z","shell.execute_reply":"2023-12-14T20:16:07.510741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n    import resnest\nexcept ModuleNotFoundError:\n    !pip install -q \"../input/resnest50-fast-package/resnest-0.0.6b20200701/resnest\"","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:16:07.513683Z","iopub.execute_input":"2023-12-14T20:16:07.513956Z","iopub.status.idle":"2023-12-14T20:16:37.581724Z","shell.execute_reply.started":"2023-12-14T20:16:07.513930Z","shell.execute_reply":"2023-12-14T20:16:37.580791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport librosa as lb\nimport soundfile as sf\nimport pandas as pd\nimport cv2\nfrom pathlib import Path\nimport re\n\nimport torch\nfrom torch import nn\nfrom  torch.utils.data import Dataset, DataLoader\n\nfrom tqdm.notebook import tqdm\n\nimport time\nfrom resnest.torch import resnest50","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","id":"kSCcqxf0c_O7","papermill":{"duration":4.153186,"end_time":"2021-02-16T15:59:57.894303","exception":false,"start_time":"2021-02-16T15:59:53.741117","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-14T20:16:37.583531Z","iopub.execute_input":"2023-12-14T20:16:37.583849Z","iopub.status.idle":"2023-12-14T20:16:41.307880Z","shell.execute_reply.started":"2023-12-14T20:16:37.583817Z","shell.execute_reply":"2023-12-14T20:16:41.307129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":0.046502,"end_time":"2021-02-16T15:59:59.284533","exception":false,"start_time":"2021-02-16T15:59:59.238031","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Configs","metadata":{"papermill":{"duration":0.046996,"end_time":"2021-02-16T15:59:59.377834","exception":false,"start_time":"2021-02-16T15:59:59.330838","status":"completed"},"tags":[]}},{"cell_type":"code","source":"NUM_CLASSES = 397\nSR = 32_000\nDURATION = 5\nTHRESH = 0.25\n\n\nDEVICE = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\nprint(\"DEVICE:\", DEVICE)\n\nTEST_AUDIO_ROOT = Path(\"../input/birdclef-2021/test_soundscapes\")\nSAMPLE_SUB_PATH = \"../input/birdclef-2021/sample_submission.csv\"\nTARGET_PATH = None\n    \nif not len(list(TEST_AUDIO_ROOT.glob(\"*.ogg\"))):\n    TEST_AUDIO_ROOT = Path(\"../input/birdclef-2021/train_soundscapes\")\n    SAMPLE_SUB_PATH = None\n    # SAMPLE_SUB_PATH = \"../input/birdclef-2021/sample_submission.csv\"\n    TARGET_PATH = Path(\"../input/birdclef-2021/train_soundscape_labels.csv\")","metadata":{"id":"rJhYZVIDc_O9","papermill":{"duration":0.440614,"end_time":"2021-02-16T15:59:59.86408","exception":false,"start_time":"2021-02-16T15:59:59.423466","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-14T20:16:41.309323Z","iopub.execute_input":"2023-12-14T20:16:41.309615Z","iopub.status.idle":"2023-12-14T20:16:41.385412Z","shell.execute_reply.started":"2023-12-14T20:16:41.309589Z","shell.execute_reply":"2023-12-14T20:16:41.384630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data","metadata":{"papermill":{"duration":0.046026,"end_time":"2021-02-16T16:00:00.054107","exception":false,"start_time":"2021-02-16T16:00:00.008081","status":"completed"},"tags":[]}},{"cell_type":"code","source":"class MelSpecComputer:\n    def __init__(self, sr, n_mels, fmin, fmax, **kwargs):\n        self.sr = sr\n        self.n_mels = n_mels\n        self.fmin = fmin\n        self.fmax = fmax\n        kwargs[\"n_fft\"] = kwargs.get(\"n_fft\", self.sr//10)\n        kwargs[\"hop_length\"] = kwargs.get(\"hop_length\", self.sr//(10*4))\n        self.kwargs = kwargs\n\n    def __call__(self, y):\n\n        melspec = lb.feature.melspectrogram(\n            y, sr=self.sr, n_mels=self.n_mels, fmin=self.fmin, fmax=self.fmax, **self.kwargs,\n        )\n\n        melspec = lb.power_to_db(melspec).astype(np.float32)\n        return melspec","metadata":{"id":"4fwNhdbJc_O-","papermill":{"duration":0.056975,"end_time":"2021-02-16T16:00:00.157168","exception":false,"start_time":"2021-02-16T16:00:00.100193","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-14T20:16:41.388758Z","iopub.execute_input":"2023-12-14T20:16:41.389024Z","iopub.status.idle":"2023-12-14T20:16:41.396304Z","shell.execute_reply.started":"2023-12-14T20:16:41.388999Z","shell.execute_reply":"2023-12-14T20:16:41.395566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def mono_to_color(X, eps=1e-6, mean=None, std=None):\n    mean = mean or X.mean()\n    std = std or X.std()\n    X = (X - mean) / (std + eps)\n    \n    _min, _max = X.min(), X.max()\n\n    if (_max - _min) > eps:\n        V = np.clip(X, _min, _max)\n        V = 255 * (V - _min) / (_max - _min)\n        V = V.astype(np.uint8)\n    else:\n        V = np.zeros_like(X, dtype=np.uint8)\n\n    return V\n\ndef crop_or_pad(y, length):\n    if len(y) < length:\n        y = np.concatenate([y, length - np.zeros(len(y))])\n    elif len(y) > length:\n        y = y[:length]\n    return y","metadata":{"id":"Nk0haSTIc_O_","papermill":{"duration":0.065406,"end_time":"2021-02-16T16:00:00.271104","exception":false,"start_time":"2021-02-16T16:00:00.205698","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-14T20:16:41.399003Z","iopub.execute_input":"2023-12-14T20:16:41.399279Z","iopub.status.idle":"2023-12-14T20:16:41.407270Z","shell.execute_reply.started":"2023-12-14T20:16:41.399252Z","shell.execute_reply":"2023-12-14T20:16:41.406502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class BirdCLEFDataset(Dataset):\n    def __init__(self, data, sr=SR, n_mels=128, fmin=0, fmax=None, duration=DURATION, step=None, res_type=\"kaiser_fast\", resample=True):\n        \n        self.data = data\n        \n        self.sr = sr\n        self.n_mels = n_mels\n        self.fmin = fmin\n        self.fmax = fmax or self.sr//2\n\n        self.duration = duration\n        self.audio_length = self.duration*self.sr\n        self.step = step or self.audio_length\n        \n        self.res_type = res_type\n        self.resample = resample\n\n        self.mel_spec_computer = MelSpecComputer(sr=self.sr, n_mels=self.n_mels, fmin=self.fmin,\n                                                 fmax=self.fmax)\n    def __len__(self):\n        return len(self.data)\n    \n    @staticmethod\n    def normalize(image):\n        image = image.astype(\"float32\", copy=False) / 255.0\n        image = np.stack([image, image, image])\n        return image\n    \n    def audio_to_image(self, audio):\n        melspec = self.mel_spec_computer(audio) \n        image = mono_to_color(melspec)\n        image = self.normalize(image)\n        return image\n\n    def read_file(self, filepath):\n        audio, orig_sr = sf.read(filepath, dtype=\"float32\")\n\n        if self.resample and orig_sr != self.sr:\n            audio = lb.resample(audio, orig_sr, self.sr, res_type=self.res_type)\n          \n        audios = []\n        for i in range(self.audio_length, len(audio) + self.step, self.step):\n            start = max(0, i - self.audio_length)\n            end = start + self.audio_length\n            audios.append(audio[start:end])\n            \n        if len(audios[-1]) < self.audio_length:\n            audios = audios[:-1]\n            \n        images = [self.audio_to_image(audio) for audio in audios]\n        images = np.stack(images)\n        \n        return images\n    \n        \n    def __getitem__(self, idx):\n        return self.read_file(self.data.loc[idx, \"filepath\"])","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:16:41.408635Z","iopub.execute_input":"2023-12-14T20:16:41.408994Z","iopub.status.idle":"2023-12-14T20:16:41.424318Z","shell.execute_reply.started":"2023-12-14T20:16:41.408958Z","shell.execute_reply":"2023-12-14T20:16:41.423614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.DataFrame(\n     [(path.stem, *path.stem.split(\"_\"), path) for path in Path(TEST_AUDIO_ROOT).glob(\"*.ogg\")],\n    columns = [\"filename\", \"id\", \"site\", \"date\", \"filepath\"]\n)\nprint(data.shape)\ndata.head()","metadata":{"id":"rVwlOrbxc_PD","outputId":"9b53ec99-634a-4b30-f9b5-75036184482b","papermill":{"duration":0.162256,"end_time":"2021-02-16T16:00:01.102152","exception":false,"start_time":"2021-02-16T16:00:00.939896","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-14T20:16:41.425288Z","iopub.execute_input":"2023-12-14T20:16:41.425569Z","iopub.status.idle":"2023-12-14T20:16:41.471626Z","shell.execute_reply.started":"2023-12-14T20:16:41.425542Z","shell.execute_reply":"2023-12-14T20:16:41.470870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv(\"../input/birdclef-2021/train_metadata.csv\")\n\nLABEL_IDS = {label: label_id for label_id,label in enumerate(sorted(df_train[\"primary_label\"].unique()))}\nINV_LABEL_IDS = {val: key for key,val in LABEL_IDS.items()}","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:16:41.472727Z","iopub.execute_input":"2023-12-14T20:16:41.472972Z","iopub.status.idle":"2023-12-14T20:16:41.926139Z","shell.execute_reply.started":"2023-12-14T20:16:41.472948Z","shell.execute_reply":"2023-12-14T20:16:41.925251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Inference","metadata":{"id":"BNsivZZZc_PG","papermill":{"duration":0.048675,"end_time":"2021-02-16T16:00:08.424781","exception":false,"start_time":"2021-02-16T16:00:08.376106","status":"completed"},"tags":[]}},{"cell_type":"code","source":"test_data = BirdCLEFDataset(data=data)\nlen(test_data), test_data[0].shape","metadata":{"id":"AzlOErOmc_PH","papermill":{"duration":0.058312,"end_time":"2021-02-16T16:00:08.531199","exception":false,"start_time":"2021-02-16T16:00:08.472887","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-14T20:16:41.927401Z","iopub.execute_input":"2023-12-14T20:16:41.927711Z","iopub.status.idle":"2023-12-14T20:16:45.260530Z","shell.execute_reply.started":"2023-12-14T20:16:41.927681Z","shell.execute_reply":"2023-12-14T20:16:45.259560Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":0.048931,"end_time":"2021-02-16T16:00:14.351476","exception":false,"start_time":"2021-02-16T16:00:14.302545","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_net(checkpoint_path, num_classes=NUM_CLASSES):\n    net = resnest50(pretrained=False)\n    net.fc = nn.Linear(net.fc.in_features, num_classes)\n    dummy_device = torch.device(\"cpu\")\n    d = torch.load(checkpoint_path, map_location=dummy_device)\n    for key in list(d.keys()):\n        d[key.replace(\"model.\", \"\")] = d.pop(key)\n    net.load_state_dict(d)\n    net = net.to(DEVICE)\n    net = net.eval()\n    return net","metadata":{"papermill":{"duration":0.05945,"end_time":"2021-02-16T16:00:14.565804","exception":false,"start_time":"2021-02-16T16:00:14.506354","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-14T20:16:45.261932Z","iopub.execute_input":"2023-12-14T20:16:45.262461Z","iopub.status.idle":"2023-12-14T20:16:45.272896Z","shell.execute_reply.started":"2023-12-14T20:16:45.262416Z","shell.execute_reply":"2023-12-14T20:16:45.271431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ncheckpoint_paths = [\n    Path(\"../input/kkiller-birdclef-models-public/birdclef_resnest50_fold0_epoch_10_f1_val_06471_20210417161101.pth\"),\n]\n\n\nnets = [\n        load_net(checkpoint_path.as_posix()) for checkpoint_path in checkpoint_paths\n]","metadata":{"id":"ayVLRTzLc_PI","papermill":{"duration":14.506299,"end_time":"2021-02-16T16:00:30.268614","exception":false,"start_time":"2021-02-16T16:00:15.762315","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-14T20:16:45.275072Z","iopub.execute_input":"2023-12-14T20:16:45.275867Z","iopub.status.idle":"2023-12-14T20:16:51.414939Z","shell.execute_reply.started":"2023-12-14T20:16:45.275812Z","shell.execute_reply":"2023-12-14T20:16:51.414108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":0.051509,"end_time":"2021-02-16T16:00:30.373444","exception":false,"start_time":"2021-02-16T16:00:30.321935","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"@torch.no_grad()\ndef get_thresh_preds(out, thresh=None):\n    thresh = thresh or THRESH\n    o = (-out).argsort(1)\n    npreds = (out > thresh).sum(1)\n    preds = []\n    for oo, npred in zip(o, npreds):\n        preds.append(oo[:npred].cpu().numpy().tolist())\n    return preds","metadata":{"papermill":{"duration":0.059925,"end_time":"2021-02-16T16:00:30.912547","exception":false,"start_time":"2021-02-16T16:00:30.852622","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-14T20:16:51.416108Z","iopub.execute_input":"2023-12-14T20:16:51.416406Z","iopub.status.idle":"2023-12-14T20:16:51.421498Z","shell.execute_reply.started":"2023-12-14T20:16:51.416379Z","shell.execute_reply":"2023-12-14T20:16:51.420759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_bird_names(preds):\n    bird_names = []\n    for pred in preds:\n        if not pred:\n            bird_names.append(\"nocall\")\n        else:\n            bird_names.append(\" \".join([INV_LABEL_IDS[bird_id] for bird_id in pred]))\n    return bird_names","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:16:51.422502Z","iopub.execute_input":"2023-12-14T20:16:51.422760Z","iopub.status.idle":"2023-12-14T20:16:51.437084Z","shell.execute_reply.started":"2023-12-14T20:16:51.422736Z","shell.execute_reply":"2023-12-14T20:16:51.436271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def predict(nets, test_data, names=True):\n    preds = []\n    with torch.no_grad():\n        for idx in  tqdm(list(range(len(test_data)))):\n            xb = torch.from_numpy(test_data[idx]).to(DEVICE)\n            pred = 0.\n            for net in nets:\n                o = net(xb)\n                o = torch.sigmoid(o)\n\n                pred += o\n\n            pred /= len(nets)\n            \n            if names:\n                pred = get_bird_names(get_thresh_preds(pred))\n\n            preds.append(pred)\n    return preds","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:16:51.438439Z","iopub.execute_input":"2023-12-14T20:16:51.438724Z","iopub.status.idle":"2023-12-14T20:16:51.447127Z","shell.execute_reply.started":"2023-12-14T20:16:51.438687Z","shell.execute_reply":"2023-12-14T20:16:51.446455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_probas = predict(nets, test_data, names=False)\nprint(len(pred_probas))","metadata":{"papermill":{"duration":7466.932385,"end_time":"2021-02-16T18:04:58.116349","exception":false,"start_time":"2021-02-16T16:00:31.183964","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-12-14T20:16:51.448153Z","iopub.execute_input":"2023-12-14T20:16:51.448519Z","iopub.status.idle":"2023-12-14T20:18:01.159938Z","shell.execute_reply.started":"2023-12-14T20:16:51.448482Z","shell.execute_reply":"2023-12-14T20:18:01.158716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = [get_bird_names(get_thresh_preds(pred, thresh=THRESH)) for pred in pred_probas]\n# preds[:2]","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:18:01.162039Z","iopub.execute_input":"2023-12-14T20:18:01.162875Z","iopub.status.idle":"2023-12-14T20:18:01.332467Z","shell.execute_reply.started":"2023-12-14T20:18:01.162816Z","shell.execute_reply":"2023-12-14T20:18:01.331739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def preds_as_df(data, preds):\n    sub = {\n        \"row_id\": [],\n        \"birds\": [],\n    }\n    \n    for row, pred in zip(data.itertuples(False), preds):\n        row_id = [f\"{row.id}_{row.site}_{5*i}\" for i in range(1, len(pred)+1)]\n        sub[\"birds\"] += pred\n        sub[\"row_id\"] += row_id\n        \n    sub = pd.DataFrame(sub)\n    \n    if SAMPLE_SUB_PATH:\n        sample_sub = pd.read_csv(SAMPLE_SUB_PATH, usecols=[\"row_id\"])\n        sub = sample_sub.merge(sub, on=\"row_id\", how=\"left\")\n        sub[\"birds\"] = sub[\"birds\"].fillna(\"nocall\")\n    return sub","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:18:01.333858Z","iopub.execute_input":"2023-12-14T20:18:01.334230Z","iopub.status.idle":"2023-12-14T20:18:01.341185Z","shell.execute_reply.started":"2023-12-14T20:18:01.334194Z","shell.execute_reply":"2023-12-14T20:18:01.340459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = preds_as_df(data, preds)\nprint(sub.shape)\nsub","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:18:01.342425Z","iopub.execute_input":"2023-12-14T20:18:01.342717Z","iopub.status.idle":"2023-12-14T20:18:01.362683Z","shell.execute_reply.started":"2023-12-14T20:18:01.342691Z","shell.execute_reply":"2023-12-14T20:18:01.361976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:18:01.363925Z","iopub.execute_input":"2023-12-14T20:18:01.364303Z","iopub.status.idle":"2023-12-14T20:18:01.631039Z","shell.execute_reply.started":"2023-12-14T20:18:01.364264Z","shell.execute_reply":"2023-12-14T20:18:01.630277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Small validation","metadata":{}},{"cell_type":"code","source":"def get_metrics(s_true, s_pred):\n    s_true = set(s_true.split())\n    s_pred = set(s_pred.split())\n    n, n_true, n_pred = len(s_true.intersection(s_pred)), len(s_true), len(s_pred)\n    \n    prec = n/n_pred\n    rec = n/n_true\n    f1 = 2*prec*rec/(prec + rec) if prec + rec else 0\n    \n    return {\"f1\": f1, \"prec\": prec, \"rec\": rec, \"n_true\": n_true, \"n_pred\": n_pred, \"n\": n}","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:18:01.632155Z","iopub.execute_input":"2023-12-14T20:18:01.632446Z","iopub.status.idle":"2023-12-14T20:18:01.638757Z","shell.execute_reply.started":"2023-12-14T20:18:01.632417Z","shell.execute_reply":"2023-12-14T20:18:01.637641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if TARGET_PATH:\n    sub_target = pd.read_csv(TARGET_PATH)\n    sub_target = sub_target.merge(sub, how=\"left\", on=\"row_id\")\n    \n    print(sub_target[\"birds_x\"].notnull().sum(), sub_target[\"birds_x\"].notnull().sum())\n    assert sub_target[\"birds_x\"].notnull().all()\n    assert sub_target[\"birds_y\"].notnull().all()\n    \n    df_metrics = pd.DataFrame([get_metrics(s_true, s_pred) for s_true, s_pred in zip(sub_target.birds_x, sub_target.birds_y)])\n    \n    print(df_metrics.mean())","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:18:01.639979Z","iopub.execute_input":"2023-12-14T20:18:01.640267Z","iopub.status.idle":"2023-12-14T20:18:01.689652Z","shell.execute_reply.started":"2023-12-14T20:18:01.640239Z","shell.execute_reply":"2023-12-14T20:18:01.688839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_target[sub_target.birds_y != \"nocall\"]","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:18:01.690796Z","iopub.execute_input":"2023-12-14T20:18:01.691159Z","iopub.status.idle":"2023-12-14T20:18:01.709473Z","shell.execute_reply.started":"2023-12-14T20:18:01.691122Z","shell.execute_reply":"2023-12-14T20:18:01.708737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_target[sub_target.birds_x != \"nocall\"]","metadata":{"execution":{"iopub.status.busy":"2023-12-14T20:18:01.710613Z","iopub.execute_input":"2023-12-14T20:18:01.710885Z","iopub.status.idle":"2023-12-14T20:18:01.730249Z","shell.execute_reply.started":"2023-12-14T20:18:01.710860Z","shell.execute_reply":"2023-12-14T20:18:01.729410Z"},"trusted":true},"execution_count":null,"outputs":[]}]}