{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:12:43.410527Z","iopub.execute_input":"2022-04-25T18:12:43.410821Z","iopub.status.idle":"2022-04-25T18:12:43.415574Z","shell.execute_reply.started":"2022-04-25T18:12:43.410788Z","shell.execute_reply":"2022-04-25T18:12:43.414707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls '../input/'","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:12:43.427444Z","iopub.execute_input":"2022-04-25T18:12:43.427954Z","iopub.status.idle":"2022-04-25T18:12:44.146960Z","shell.execute_reply.started":"2022-04-25T18:12:43.427923Z","shell.execute_reply":"2022-04-25T18:12:44.146175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install torch_audiomentations\n!pip install timm","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:12:44.149099Z","iopub.execute_input":"2022-04-25T18:12:44.149580Z","iopub.status.idle":"2022-04-25T18:12:59.232350Z","shell.execute_reply.started":"2022-04-25T18:12:44.149537Z","shell.execute_reply":"2022-04-25T18:12:59.231506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fastai.vision.all import *","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:12:59.233981Z","iopub.execute_input":"2022-04-25T18:12:59.234266Z","iopub.status.idle":"2022-04-25T18:12:59.241482Z","shell.execute_reply.started":"2022-04-25T18:12:59.234226Z","shell.execute_reply":"2022-04-25T18:12:59.240568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport timm\nimport albumentations as A\nfrom albumentations.pytorch import ToTensorV2\nfrom torchvision.transforms import Compose\nimport torchvision\nimport torch_audiomentations as tA","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:12:59.243793Z","iopub.execute_input":"2022-04-25T18:12:59.244976Z","iopub.status.idle":"2022-04-25T18:12:59.250911Z","shell.execute_reply.started":"2022-04-25T18:12:59.244948Z","shell.execute_reply":"2022-04-25T18:12:59.250129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls '../input/'","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:12:59.252093Z","iopub.execute_input":"2022-04-25T18:12:59.252724Z","iopub.status.idle":"2022-04-25T18:12:59.975607Z","shell.execute_reply.started":"2022-04-25T18:12:59.252688Z","shell.execute_reply":"2022-04-25T18:12:59.974804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Valid test files","metadata":{}},{"cell_type":"code","source":"df_test = pd.read_csv('../input/kaggle-pog-series-s01e02/test.csv')\ndf_train = pd.read_csv('../input/kaggle-pog-series-s01e02/train.csv')\ndf_test.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:12:59.979008Z","iopub.execute_input":"2022-04-25T18:12:59.979238Z","iopub.status.idle":"2022-04-25T18:13:00.026100Z","shell.execute_reply.started":"2022-04-25T18:12:59.979210Z","shell.execute_reply":"2022-04-25T18:13:00.025419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.027241Z","iopub.execute_input":"2022-04-25T18:13:00.027478Z","iopub.status.idle":"2022-04-25T18:13:00.037671Z","shell.execute_reply.started":"2022-04-25T18:13:00.027444Z","shell.execute_reply":"2022-04-25T18:13:00.036850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"valid_fnames = pd.read_csv('../input/valid-testfiles/valid_fnames_test.csv')\nvalid_fnames['filename']=valid_fnames['0'].apply(lambda x: x.split('.')[0])+'.ogg'\n# valid_fnames.head()\ndf_test_valid = df_test[df_test['filename'].isin(valid_fnames['filename'])].reset_index(drop=True)\ndf_test_valid.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.039066Z","iopub.execute_input":"2022-04-25T18:13:00.039846Z","iopub.status.idle":"2022-04-25T18:13:00.064757Z","shell.execute_reply.started":"2022-04-25T18:13:00.039805Z","shell.execute_reply":"2022-04-25T18:13:00.064079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"valid_fnames.shape,df_test_valid.shape","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.066045Z","iopub.execute_input":"2022-04-25T18:13:00.066531Z","iopub.status.idle":"2022-04-25T18:13:00.071916Z","shell.execute_reply.started":"2022-04-25T18:13:00.066493Z","shell.execute_reply":"2022-04-25T18:13:00.071252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Loaders","metadata":{}},{"cell_type":"code","source":"def getTfms(sz=448):\n    if sz == 448:\n        return Compose([torchvision.transforms.CenterCrop((160,1072))])\n    elif sz == 512:\n        return Compose([torchvision.transforms.CenterCrop((128,960))])\n    else:\n        return Compose([torchvision.transforms.CenterCrop((64,1072))])        \n    \nclass POGFiles(torch.utils.data.Dataset):\n    \n    def __init__(self, df=df_test_valid, \n                 train = False,\n                 sz = 448\n                ):\n        \n        \n        self.df = df\n        self.train = train\n        self.sz = sz\n        self.transform=getTfms(sz=sz)\n        \n    def __len__(self):\n        return len(self.df)\n    \n    def load_file(self, filename):\n        if self.sz == 448:\n            if self.train:\n                spec = np.load(f'../input/pog-spec-hop448-mels160/448_160/train/{filename}')\n            else:\n                spec = np.load(f'../input/pog-spec-hop448-mels160/448_160/test/{filename}')\n        elif self.sz == 512:\n            if self.train:\n                spec = np.load(f'../input/pog-spec-hop512-mels128/512_128/train/{filename}')\n            else:\n                spec = np.load(f'../input/pog-spec-hop512-mels128/512_128/test/{filename}')\n        else:\n            if self.train:\n                spec = np.load(f'../input/pog-spec-hop448-mels64/448_64/train/{filename}')\n            else:\n                spec = np.load(f'../input/pog-spec-hop448-mels64/448_64/test/{filename}')\n        return spec\n    \n    def __getitem__(self, index):\n        row  = self.df.iloc[index]\n        \n        samples = self.load_file(row.filename.split('.')[0]+'.npy')\n        samples = torch.from_numpy(samples).float()\n        \n        if self.transform is not None:\n            samples = self.transform(samples)\n                \n        if self.train:\n            label = torch.tensor(row.genre_id,dtype=torch.long)\n            return samples, label\n        else:\n\n            return samples","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.074906Z","iopub.execute_input":"2022-04-25T18:13:00.075414Z","iopub.status.idle":"2022-04-25T18:13:00.088232Z","shell.execute_reply.started":"2022-04-25T18:13:00.075376Z","shell.execute_reply":"2022-04-25T18:13:00.087611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"b = next(iter(POGFiles(sz=448)))\nb.shape","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.089567Z","iopub.execute_input":"2022-04-25T18:13:00.089854Z","iopub.status.idle":"2022-04-25T18:13:00.111689Z","shell.execute_reply.started":"2022-04-25T18:13:00.089787Z","shell.execute_reply":"2022-04-25T18:13:00.111018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### CQT Dataset","metadata":{}},{"cell_type":"code","source":"def getTfmsCQT(sz=448):\n    if sz == 448:\n        return Compose([torchvision.transforms.CenterCrop((84,1072))])\n    else:\n        return Compose([torchvision.transforms.Resize((64,960))])\n\nclass POGFilesCQT(torch.utils.data.Dataset):\n    \n    def __init__(self, df=df_test_valid, \n                 train = False,\n                 sz = 448\n                ):\n        \n        self.sz = sz\n        self.df = df\n        self.train = train\n        self.transform=getTfmsCQT(self.sz)\n        \n    def __len__(self):\n        return len(self.df)\n    \n    def load_file(self, filename):\n        if self.sz == 448:\n            if self.train:\n                CQT = np.load(f'../input/pog-cqt-hop448-bins84/448_84/train/{filename}')\n            else:\n                CQT = np.load(f'../input/pog-cqt-hop448-bins84/448_84/test/{filename}')\n        else:\n            if self.train:\n                CQT = np.load(f'../input/pog-cqt-hop512-bins64/512_64/train/{filename}')\n            else:\n                CQT = np.load(f'../input/pog-cqt-hop512-bins64/512_64/test/{filename}')\n            \n        return CQT\n    \n    def __getitem__(self, index):\n        row  = self.df.iloc[index]\n        \n        samples = self.load_file(row.filename.split('.')[0]+'.npy')\n        samples = torch.from_numpy(samples).float()\n        \n        if self.transform is not None:\n            samples = self.transform(samples)\n                \n        if self.train:\n            label = torch.tensor(row.genre_id,dtype=torch.long)\n            return samples, label\n        else:\n\n            return samples","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.114036Z","iopub.execute_input":"2022-04-25T18:13:00.114430Z","iopub.status.idle":"2022-04-25T18:13:00.125226Z","shell.execute_reply.started":"2022-04-25T18:13:00.114394Z","shell.execute_reply":"2022-04-25T18:13:00.124545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"b = next(iter(POGFilesCQT(sz=512)))\nb.shape","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.126471Z","iopub.execute_input":"2022-04-25T18:13:00.126872Z","iopub.status.idle":"2022-04-25T18:13:00.152045Z","shell.execute_reply.started":"2022-04-25T18:13:00.126835Z","shell.execute_reply":"2022-04-25T18:13:00.151087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Model infer","metadata":{}},{"cell_type":"code","source":"def getModel(_type='resnest50d',NCLASS = 19):\n    if _type == 'resnest50d':\n        model = timm.create_model('resnest50d', pretrained=False, in_chans=1)\n        model.conv1[0].stride = (1,1)\n        model.fc = nn.Linear(2048,NCLASS)\n        return model        \n    elif _type == 'eb1':\n        model = timm.create_model('efficientnet_b1', pretrained=False, in_chans=1)\n        model.conv_stem.stride = (1,1)\n        model.classifier = nn.Linear(1280,NCLASS,bias=False)\n        return model\n    elif _type == 'eb2':\n        model = timm.create_model('efficientnet_b2', pretrained=False, in_chans=1)\n        model.conv_stem.stride = (1,1)\n        model.classifier = nn.Linear(1408,NCLASS)\n        return model        \n    elif _type == 'ecaresnet50t':\n        model = timm.create_model('ecaresnet50t', pretrained=False, in_chans=1)\n        model.conv1[0].stride = (1,1)\n        model.fc = nn.Linear(2048,NCLASS)\n        return model\n    elif _type == 'ecaresnet50d':   \n        model = timm.create_model('ecaresnet50d',in_chans=1,pretrained=False)\n        model.conv1[0].stride = (1,1)\n        model.fc = nn.Linear(2048,NCLASS)\n        return model\n    elif _type == 'densenet121d':\n        model = timm.create_model('densenet121d', pretrained=False, in_chans=1)\n        model.features.conv0.stride = (1,1)\n        model.classifier = nn.Linear(1024,NCLASS)\n        return model\n    elif _type == 'ecaresnext50t_32x4d':\n        model = timm.create_model('ecaresnext50t_32x4d',in_chans=1,pretrained=False)\n        model.conv1[0].stride = (1,1)\n        model.fc = nn.Linear(2048,NCLASS)\n        return model\n    elif _type == 'resnext50d_32x4d':\n        model = timm.create_model('resnext50d_32x4d',in_chans=1,pretrained=False)\n        model.conv1[0].stride = (1,1)\n        model.fc = nn.Linear(2048,NCLASS)\n        return model\n    else:\n        print(f'{_type} not implemented')","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.157543Z","iopub.execute_input":"2022-04-25T18:13:00.160234Z","iopub.status.idle":"2022-04-25T18:13:00.178996Z","shell.execute_reply.started":"2022-04-25T18:13:00.160153Z","shell.execute_reply":"2022-04-25T18:13:00.178209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mDirs = ['pog2-eb1-monospec-hop448-mels160','pog2-ecaresnet50t-monospec-hop448-mels160-ftune',\n         'pog2-resnest50d-monospec-hop448-mels160-ftune','pog2-resnest50d-monospec-hop448-mels160-noisytrain',\n         'pog2-tf-efficientnet-b1-monospec-hop512-mels128']\n\nmNames = ['eb1','ecaresnet50t','resnest50d','resnest50d','eb1']\n\nmZip = list(zip(mNames,mDirs))","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.190520Z","iopub.execute_input":"2022-04-25T18:13:00.192412Z","iopub.status.idle":"2022-04-25T18:13:00.198001Z","shell.execute_reply.started":"2022-04-25T18:13:00.192371Z","shell.execute_reply":"2022-04-25T18:13:00.197206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import gc\nimport torch","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.199494Z","iopub.execute_input":"2022-04-25T18:13:00.199987Z","iopub.status.idle":"2022-04-25T18:13:00.216268Z","shell.execute_reply.started":"2022-04-25T18:13:00.199938Z","shell.execute_reply":"2022-04-25T18:13:00.215442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def inference(_model='resnest50d',modelpth=None,retLogits = False,retProbits=False,sz=None,clsCount=19,testDF=df_test_valid):\n    if retLogits or retProbits:\n        l = np.zeros((len(testDF),clsCount))\n    else:\n        l = np.zeros((len(testDF),1))\n    \n    if sz is None:\n        sz = [448 if '448' in modelpth else 512]\n    else:\n        sz = sz\n        \n    for fold_num in [0,1,2,3,4]:\n        print('*****************************************')\n        print(f'Inference Fold {fold_num}')\n        print(f'using size:{sz[0]}')\n        print('*****************************************')\n        \n        batch_size = 32\n        \n        model = getModel(_model,NCLASS=clsCount)\n        \n        train_ds = POGFiles(df_train,\n                            train=True,\n                            sz=sz[0]\n                           )\n        \n        dls = torch.utils.data.DataLoader(train_ds, batch_size=batch_size)\n        learn = Learner(dls, model,opt_func=ranger,loss_func=CrossEntropyLossFlat(),metrics=['f1_score'],model_dir=Path('.')).to_fp16()\n        \n        test_ds = POGFiles(testDF,\n                           train=False,\n                           sz = sz[0]\n                           )\n\n        test_dl = torch.utils.data.DataLoader(test_ds, batch_size=batch_size, num_workers=4, shuffle=False)\n        pp = Path(f'../input/{modelpth}/fold_{fold_num}')\n        learn = learn.load(pp)\n        learn.model.eval()\n        learn.cuda()\n\n        bs = batch_size\n\n        preds  =  []\n        probs  =  []\n        logits = []\n        for xb  in progress_bar(test_dl):\n            with torch.no_grad():\n                output = learn.model(xb.cuda())\n                if retLogits:\n                    logits.append(output.float().squeeze().cpu())\n                elif retProbits:\n                    probs.append(torch.softmax(output.float(),1).squeeze().cpu())\n                else:\n                    preds.append(torch.argmax(output.float(),1).squeeze().cpu())\n                    \n        if retProbits:\n            l += np.concatenate(probs)/5\n        elif retLogits:\n            l += np.concatenate(logits)/5\n        else:\n            l = np.hstack((l,np.concatenate(preds).reshape(-1,1)))\n\n    del model, learn\n    \n    gc.collect()\n    torch.cuda.empty_cache()\n    if retLogits or retProbits:\n        return l\n    else:\n        return l[:,1:]","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.220021Z","iopub.execute_input":"2022-04-25T18:13:00.220239Z","iopub.status.idle":"2022-04-25T18:13:00.253847Z","shell.execute_reply.started":"2022-04-25T18:13:00.220189Z","shell.execute_reply":"2022-04-25T18:13:00.252921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def inferenceCQT(_model='ecaresnext50t_32x4d',modelpth=None,retLogits = False,retProbits=False,sz=None,clsCount=19,testDF=df_test_valid):\n    if retLogits or retProbits:\n        l = np.zeros((len(testDF),clsCount))\n    else:\n        l = np.zeros((len(testDF),1))\n    \n    if sz is None:\n        sz = [448 if '448' in modelpth else 512]\n    else:\n        sz = sz\n        \n    for fold_num in [0,1,2,3,4]:\n        print('*****************************************')\n        print(f'Inference Fold {fold_num}')\n        print(f'using size:{sz[0]}')\n        print('*****************************************')\n        \n        batch_size = 32\n        \n        model = getModel(_model,NCLASS=clsCount)\n        \n        train_ds = POGFilesCQT(df_train,\n                            train=True,\n                            sz=sz[0]\n                           )\n        \n        dls = torch.utils.data.DataLoader(train_ds, batch_size=batch_size)\n        learn = Learner(dls, model,opt_func=ranger,loss_func=CrossEntropyLossFlat(),metrics=['f1_score'],model_dir=Path('.')).to_fp16()\n        \n        test_ds = POGFilesCQT(testDF,\n                           train=False,\n                            sz=sz[0]\n                           )\n\n        test_dl = torch.utils.data.DataLoader(test_ds, batch_size=batch_size, num_workers=4, shuffle=False)\n        pp = Path(f'../input/{modelpth}/fold_{fold_num}')\n        learn = learn.load(pp)\n        learn.model.eval()\n        learn.cuda()\n\n        bs = batch_size\n\n        preds  =  []\n        probs  =  []\n        logits = []\n        for xb  in progress_bar(test_dl):\n            with torch.no_grad():\n                output = learn.model(xb.cuda())\n                if retLogits:\n                    logits.append(output.float().squeeze().cpu())\n                elif retProbits:\n                    probs.append(torch.softmax(output.float(),1).squeeze().cpu())\n                else:\n                    preds.append(torch.argmax(output.float(),1).squeeze().cpu())\n                    \n        if retProbits:\n            l += np.concatenate(probs)/5\n        elif retLogits:\n            l += np.concatenate(logits)/5\n        else:\n            l = np.hstack((l,np.concatenate(preds).reshape(-1,1)))\n\n    del model, learn\n    \n    gc.collect()\n    torch.cuda.empty_cache()\n    if retLogits or retProbits:\n        return l\n    else:\n        return l[:,1:]","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.258648Z","iopub.execute_input":"2022-04-25T18:13:00.261033Z","iopub.status.idle":"2022-04-25T18:13:00.282716Z","shell.execute_reply.started":"2022-04-25T18:13:00.260992Z","shell.execute_reply":"2022-04-25T18:13:00.281644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls '../input'","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:00.287780Z","iopub.execute_input":"2022-04-25T18:13:00.289989Z","iopub.status.idle":"2022-04-25T18:13:01.098218Z","shell.execute_reply.started":"2022-04-25T18:13:00.289952Z","shell.execute_reply":"2022-04-25T18:13:01.097264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-04-25T18:13:01.100300Z","iopub.execute_input":"2022-04-25T18:13:01.100585Z","iopub.status.idle":"2022-04-25T18:16:54.264121Z","shell.execute_reply.started":"2022-04-25T18:13:01.100546Z","shell.execute_reply":"2022-04-25T18:16:54.263344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"l_1_CQT = inferenceCQT(_model = 'ecaresnext50t_32x4d',modelpth='pog2-ecaresnext50t-32x4d-cqt-512-64')\nl_2_CQT = inferenceCQT(_model = 'ecaresnext50t_32x4d',modelpth='pog2-ecaresnext50t-32x4d-cqt-512-64-mixup')\nl_3_CQT = inferenceCQT(_model = 'ecaresnext50t_32x4d',modelpth='pog2-ecaresnext50t-32x4d-cqt-448-84-tune')\nl_4_CQT = inferenceCQT(_model = 'ecaresnext50t_32x4d',modelpth='pog2-ecaresnext50t-32x4d-cqt-512-64-noisy')\nl_5_CQT = inferenceCQT(_model = 'eb1',modelpth='pog2-efficientnet-b1-cqt-512-64')\nl_6_CQT = inferenceCQT(_model = 'eb2',modelpth='pog2-efficientnet-b2-cqt-512-64')\nl_7_CQT = inferenceCQT(_model = 'ecaresnet50d',modelpth='pog2-ecaresnet50d-cqt-512-64')","metadata":{"execution":{"iopub.status.busy":"2022-04-22T12:09:44.005754Z","iopub.execute_input":"2022-04-22T12:09:44.00603Z","iopub.status.idle":"2022-04-22T12:10:12.953783Z","shell.execute_reply.started":"2022-04-22T12:09:44.005995Z","shell.execute_reply":"2022-04-22T12:10:12.951865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"l_1 = inference(_model='resnest50d',modelpth='pog2-resnest50d-monospec-hop448-mels160-ftune')\nl_2 = inference(_model='resnest50d',modelpth='pog2-resnest50d-monospec-hop448-mels160-noisytrain')\n# l_3 = inference(_model='eb1',modelpth='pog2-eb1-monospec-hop448-mels160')\n# l_4 = inference(_model='eb1',modelpth='pog2-tf-efficientnet-b1-monospec-hop512-mels128')\n# l_5 = inference(_model='ecaresnet50t',modelpth='pog2-ecaresnet50t-monospec-hop448-mels160-ftune')\nl_6 = inference(_model = 'ecaresnext50t_32x4d',modelpth='pog2-ecaresnext50t-32x4d-monospec-hop448-mels160')\nl_7 = inference(_model = 'resnext50d_32x4d',modelpth='pog2-resnext50d-32x4d-monospec-hop448-mels160')\nl_8 = inference(_model = 'ecaresnext50t_32x4d',modelpth='pog2-ecaresnext50t-32x4d-monospec-hop448-mels64',sz=[64])\nl_9 = inference(_model = 'ecaresnext50t_32x4d',modelpth='pog2-ecaresnext50t-32x4d-spec-hop448-mels64-tune',sz=[64])\nl_10 = inference(_model = 'ecaresnext50t_32x4d',modelpth='pog2-ecaresnext50t-32x4d-spec-hop448-mels64-noisy',sz=[64])\nl_11 = inference(_model = 'resnext50d_32x4d',modelpth='pog2-resnext50t-32x4d-spec-hop448-mels64-noisy',sz=[64])\nl_12 = inference(_model = 'densenet121d',modelpth='pog2-densenet121d-monospec-hop448-mels64-noisy',sz=[64])\n","metadata":{"execution":{"iopub.status.busy":"2022-04-23T07:01:22.789617Z","iopub.execute_input":"2022-04-23T07:01:22.790433Z","iopub.status.idle":"2022-04-23T07:01:43.857814Z","shell.execute_reply.started":"2022-04-23T07:01:22.79039Z","shell.execute_reply":"2022-04-23T07:01:43.856627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# l_11 = inference(_model='resnest50d',modelpth='pog2-resnest50d-monospec-hop448-mels160-ftune',sz=[512])\n# l_21 = inference(_model='resnest50d',modelpth='pog2-resnest50d-monospec-hop448-mels160-noisytrain',sz=[512])\n# l_31 = inference(_model='eb1',modelpth='pog2-eb1-monospec-hop448-mels160',sz=[512])\n# l_41 = inference(_model='eb1',modelpth='pog2-tf-efficientnet-b1-monospec-hop512-mels128')\n# l_51 = inference(_model='ecaresnet50t',modelpth='pog2-ecaresnet50t-monospec-hop448-mels160-ftune')\n# l_61 = inference(_model = 'ecaresnext50t_32x4d',modelpth='pog2-ecaresnext50t-32x4d-monospec-hop448-mels160',sz=[512])\n# l_71 = inference(_model = 'resnext50d_32x4d',modelpth='pog2-resnext50d-32x4d-monospec-hop448-mels160',sz=[512])\n# l_81 = inference(_model = 'ecaresnext50t_32x4d',modelpth='pog2-ecaresnext50t-32x4d-monospec-hop448-mels64',sz=[448])","metadata":{"execution":{"iopub.status.busy":"2022-04-13T15:14:37.252138Z","iopub.execute_input":"2022-04-13T15:14:37.2528Z","iopub.status.idle":"2022-04-13T15:23:16.899848Z","shell.execute_reply.started":"2022-04-13T15:14:37.252755Z","shell.execute_reply":"2022-04-13T15:23:16.898847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ll = pd.DataFrame(l_1).mode(1)[0].astype(int)\n# ll\nll = np.hstack((l_1,l_2,l_6,l_7,l_8,l_9,l_10,l_11,l_12,l_1_CQT,l_2_CQT,l_3_CQT,l_4_CQT,l_5_CQT,l_6_CQT,l_7_CQT))\n\n# ll = np.hstack((l_1,l_2,l_3,l_6,l_7,l_8,l_11,l_21,l_31,l_61,l_71,l_81,l_1_CQT,l_2_CQT,l_3_CQT))\nll = pd.DataFrame(ll).mode(1)[0].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-04-16T11:08:05.804961Z","iopub.execute_input":"2022-04-16T11:08:05.805771Z","iopub.status.idle":"2022-04-16T11:08:07.757601Z","shell.execute_reply.started":"2022-04-16T11:08:05.805725Z","shell.execute_reply":"2022-04-16T11:08:07.756882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test_valid['genre_id']=ll","metadata":{"execution":{"iopub.status.busy":"2022-04-16T11:36:38.783907Z","iopub.execute_input":"2022-04-16T11:36:38.784451Z","iopub.status.idle":"2022-04-16T11:36:38.788412Z","shell.execute_reply.started":"2022-04-16T11:36:38.784414Z","shell.execute_reply":"2022-04-16T11:36:38.78774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test_valid.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-16T11:37:20.708068Z","iopub.execute_input":"2022-04-16T11:37:20.708618Z","iopub.status.idle":"2022-04-16T11:37:20.719339Z","shell.execute_reply.started":"2022-04-16T11:37:20.708582Z","shell.execute_reply":"2022-04-16T11:37:20.718215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test_valid['genre_id'] = df_test_valid['genre_id'].astype(int)\nsubmit = pd.read_csv('../input/kaggle-pog-series-s01e02/sample_submission.csv')\nsubmit = pd.merge(submit['song_id'],df_test_valid[['song_id','genre_id']], on = 'song_id', how='left')\nsubmit.loc[submit['song_id']==22612,'genre_id'] = 1\nsubmit.loc[submit['song_id']==24013,'genre_id'] = 0\nsubmit['genre_id'] = submit['genre_id'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-04-15T06:42:11.267695Z","iopub.execute_input":"2022-04-15T06:42:11.268008Z","iopub.status.idle":"2022-04-15T06:42:11.306774Z","shell.execute_reply.started":"2022-04-15T06:42:11.267975Z","shell.execute_reply":"2022-04-15T06:42:11.305696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-15T06:42:12.96831Z","iopub.execute_input":"2022-04-15T06:42:12.968824Z","iopub.status.idle":"2022-04-15T06:42:12.979334Z","shell.execute_reply.started":"2022-04-15T06:42:12.968787Z","shell.execute_reply":"2022-04-15T06:42:12.978057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit['genre_id'].isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-04-15T06:42:25.503903Z","iopub.execute_input":"2022-04-15T06:42:25.504456Z","iopub.status.idle":"2022-04-15T06:42:25.519996Z","shell.execute_reply.started":"2022-04-15T06:42:25.504401Z","shell.execute_reply":"2022-04-15T06:42:25.51708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit['genre_id'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-04-15T06:44:46.543974Z","iopub.execute_input":"2022-04-15T06:44:46.544286Z","iopub.status.idle":"2022-04-15T06:44:46.554325Z","shell.execute_reply.started":"2022-04-15T06:44:46.544252Z","shell.execute_reply":"2022-04-15T06:44:46.553174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-04-13T05:51:34.022883Z","iopub.status.idle":"2022-04-13T05:51:34.023506Z","shell.execute_reply.started":"2022-04-13T05:51:34.02325Z","shell.execute_reply":"2022-04-13T05:51:34.023273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### Fin ###","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-04-13T05:51:34.02469Z","iopub.status.idle":"2022-04-13T05:51:34.025323Z","shell.execute_reply.started":"2022-04-13T05:51:34.025077Z","shell.execute_reply":"2022-04-13T05:51:34.025101Z"},"trusted":true},"execution_count":null,"outputs":[]}]}