├── .gitignore ├── images ├── mfcc.png ├── raw.png ├── spec.png ├── Section-0-Panel-0-3919lbfls.png ├── Section-0-Panel-1-jmn9k1muq.png ├── Section-0-Panel-2-99q67v5kr.png └── Section-0-Panel-3-tg061apfa.png ├── demo.ipynb ├── codes ├── pre_processing │ ├── plot_acc_loss.py │ ├── create_csv_augment.py │ ├── create_csv_urbansound.py │ ├── pre_processing_urbansound.py │ ├── plot_data.py │ ├── data_augmentation.py │ ├── create_csv.py │ └── utils.py └── baseline │ ├── demo.py │ ├── finetune_models.py │ ├── main.py │ ├── data_loader.py │ ├── config.py │ ├── utils.py │ ├── models │ ├── resnet_utils.py │ ├── models.py │ └── densenet_utils.py │ └── trainer.py ├── requirements.txt ├── data ├── augmented_data │ ├── val │ │ └── val.csv │ └── train │ │ └── train.csv └── training_data │ └── train │ └── train.csv └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | data/ 3 | *.wav 4 | *.npy 5 | *.pdf 6 | *.gz 7 | *.pth 8 | *.pyc 9 | -------------------------------------------------------------------------------- /images/mfcc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekysethi/audio_classification/HEAD/images/mfcc.png -------------------------------------------------------------------------------- /images/raw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekysethi/audio_classification/HEAD/images/raw.png -------------------------------------------------------------------------------- /images/spec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekysethi/audio_classification/HEAD/images/spec.png -------------------------------------------------------------------------------- /images/Section-0-Panel-0-3919lbfls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekysethi/audio_classification/HEAD/images/Section-0-Panel-0-3919lbfls.png -------------------------------------------------------------------------------- /images/Section-0-Panel-1-jmn9k1muq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekysethi/audio_classification/HEAD/images/Section-0-Panel-1-jmn9k1muq.png -------------------------------------------------------------------------------- /images/Section-0-Panel-2-99q67v5kr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekysethi/audio_classification/HEAD/images/Section-0-Panel-2-99q67v5kr.png -------------------------------------------------------------------------------- /images/Section-0-Panel-3-tg061apfa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geekysethi/audio_classification/HEAD/images/Section-0-Panel-3-tg061apfa.png -------------------------------------------------------------------------------- /demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "demo.ipynb", 7 | "provenance": [] 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | }, 13 | "accelerator": "GPU" 14 | }, 15 | "cells": [ 16 | { 17 | "cell_type": "code", 18 | "metadata": { 19 | "id": "N5laUwGxvxE3", 20 | "colab_type": "code", 21 | "colab": {} 22 | }, 23 | "source": [ 24 | "" 25 | ], 26 | "execution_count": 0, 27 | "outputs": [] 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /codes/pre_processing/plot_acc_loss.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from matplotlib import pyplot as plt 3 | 4 | model_name = ["cnn"] 5 | 6 | file_type = ["mfcc","spec"] 7 | plot_values = {"mfcc":"Mfcc", 8 | "spec":"Sprectrogram"} 9 | 10 | for current_model in model_name: 11 | plt.figure() 12 | for current_file_type in file_type: 13 | path = "../baseline/outputs/saved_models/"+str(current_model)+"/"+str(current_file_type) 14 | 15 | train_acc = np.load(path+"/data/train_acc.npy") 16 | train_loss = np.load(path+"/data/train_loss.npy") 17 | val_acc = np.load(path+"/data/val_acc.npy") 18 | val_loss = np.load(path+"/data/val_loss.npy") 19 | 20 | plt.plot(np.arange(len(train_acc)),train_acc) 21 | 22 | # print(path) 23 | # plt.figure() 24 | # t 25 | # plt.plot(np.arange()) -------------------------------------------------------------------------------- /codes/pre_processing/create_csv_augment.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | import glob 4 | 5 | 6 | 7 | 8 | if __name__ == "__main__": 9 | 10 | flag = "val" 11 | file_list = glob.glob("../../data/augmented_data/"+str(flag)+"/wav_files/*") 12 | total_list = [] 13 | for current_file_path in file_list: 14 | print(current_file_path) 15 | current_file_id = current_file_path.split("/")[6].split(".")[0] 16 | current_class = current_file_id.split("_")[1] 17 | total_list.append([current_file_id,current_class]) 18 | 19 | 20 | columns = ['file_id',"label"] 21 | print("[INFO] SAVING DATA IN DATAFRAME") 22 | df = pd.DataFrame(index=np.arange(len(total_list)), columns=columns) 23 | df.loc[:] = total_list 24 | df.to_csv("../../data/augmented_data/"+str(flag)+"/"+str(flag)+".csv", encoding="utf-8", index=False) 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /codes/baseline/demo.py: -------------------------------------------------------------------------------- 1 | from trainer import Trainer 2 | from data_loader import train_dataloader, test_dataloader 3 | import config 4 | 5 | 6 | 7 | def main(config): 8 | 9 | 10 | train_loader = train_dataloader(config.train_file_path, 11 | config.train_labels_path, 12 | config.file_type, 13 | config.batch_size) 14 | 15 | val_loader = test_dataloader(config.val_file_path, 16 | config.val_labels_path, 17 | config.file_type, 18 | config.batch_size) 19 | 20 | 21 | 22 | trainer=Trainer(config,train_loader,val_loader,config.model_name) 23 | trainer.test(val_loader) 24 | 25 | 26 | 27 | if __name__ == "__main__": 28 | 29 | resume_flag = True 30 | debug = True 31 | file_type = "mfcc" 32 | model_name = "cnn" 33 | config_object = config.config_class(resume_flag,debug,file_type,model_name) 34 | 35 | main(config_object) 36 | 37 | 38 | -------------------------------------------------------------------------------- /codes/pre_processing/create_csv_urbansound.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | import shutil 4 | import glob 5 | from sklearn.model_selection import train_test_split 6 | 7 | 8 | if __name__ == "__main__": 9 | file_path = "/home/ashish18024/Deep-Learning-Assignments/assignment_2/question_3/data/UrbanSound8K/metadata/UrbanSound8K.csv" 10 | df = pd.read_csv(file_path) 11 | 12 | df["slice_file_name"] = df['slice_file_name'].str.split('.',expand=True)[0] 13 | columns = ['file_id',"label"] 14 | new_df = pd.DataFrame(index=np.arange(len(df)), columns=columns) 15 | new_df["file_id"] = df["slice_file_name"] 16 | new_df["label"] = df["classID"] 17 | train_df,val_df = train_test_split(new_df, test_size=0.20, random_state=42) 18 | 19 | 20 | print("[INFO] SAVING DATA IN DATAFRAME") 21 | train_df.to_csv("../../data/UrbanSound8K/train.csv", encoding="utf-8", index=False) 22 | val_df.to_csv("../../data/UrbanSound8K/val.csv", encoding="utf-8", index=False) 23 | -------------------------------------------------------------------------------- /codes/baseline/finetune_models.py: -------------------------------------------------------------------------------- 1 | from trainer import Trainer 2 | from data_loader import train_dataloader, test_dataloader 3 | from utils import prepareDirs 4 | import config 5 | 6 | 7 | 8 | def main(config): 9 | 10 | prepareDirs(config) 11 | 12 | 13 | train_loader = train_dataloader(config.train_file_path, 14 | config.train_labels_path, 15 | config.file_type, 16 | config.batch_size) 17 | 18 | val_loader = test_dataloader(config.val_file_path, 19 | config.val_labels_path, 20 | config.file_type, 21 | config.batch_size) 22 | 23 | 24 | 25 | model_name = config.file_type + "_model" 26 | trainer=Trainer(config,train_loader,val_loader,config.model_name) 27 | trainer.train() 28 | trainer.test(val_loader) 29 | 30 | 31 | 32 | 33 | if __name__ == "__main__": 34 | 35 | resume_flag = True 36 | debug = True 37 | file_type = "spec" 38 | model_name = "cnn" 39 | config_object = config.config_class(resume_flag,debug,file_type,model_name) 40 | 41 | main(config_object) 42 | 43 | 44 | -------------------------------------------------------------------------------- /codes/baseline/main.py: -------------------------------------------------------------------------------- 1 | from trainer import Trainer 2 | from data_loader import train_dataloader, test_dataloader 3 | from utils import prepareDirs 4 | import config 5 | 6 | 7 | 8 | def main(config): 9 | 10 | prepareDirs(config) 11 | 12 | 13 | train_loader = train_dataloader(config.train_file_path, 14 | config.train_labels_path, 15 | config.file_type, 16 | config.batch_size) 17 | 18 | val_loader = test_dataloader(config.val_file_path, 19 | config.val_labels_path, 20 | config.file_type, 21 | config.batch_size) 22 | 23 | # print(len(train_loader.dataset)) 24 | # print(len(val_loader.dataset)) 25 | 26 | 27 | model_name = config.file_type + "_model" 28 | trainer=Trainer(config,train_loader,val_loader,config.model_name) 29 | trainer.train() 30 | trainer.test(val_loader) 31 | 32 | # del(model) 33 | # temp = iter(train_loader) 34 | # data = temp.next() 35 | # # print(data.size()) 36 | # print(data[0].size()) 37 | # print(data[1].size()) 38 | 39 | 40 | if __name__ == "__main__": 41 | 42 | resume_flag = False 43 | debug = True 44 | file_type = "mfcc" 45 | model_name = "cnn" 46 | config_object = config.config_class(resume_flag,debug,file_type,model_name) 47 | 48 | main(config_object) 49 | 50 | 51 | -------------------------------------------------------------------------------- /codes/pre_processing/pre_processing_urbansound.py: -------------------------------------------------------------------------------- 1 | import glob 2 | import shutil 3 | import librosa 4 | import librosa.display 5 | import numpy as np 6 | import pandas as pd 7 | import skimage 8 | from matplotlib import cm 9 | from matplotlib import pyplot as plt 10 | 11 | from utils import mfcc_image, save_raw_vectors, spectrogram_image,load_audio_file 12 | 13 | if __name__ == "__main__": 14 | hop_length = 512 15 | n_mels = 128 16 | time_steps = 384 17 | 18 | 19 | df = pd.read_csv("../../data/UrbanSound8K/metadata/UrbanSound8K.csv") 20 | 21 | for i in range(len(df)): 22 | current_row = df.iloc[i] 23 | 24 | current_file_path = "../../data/UrbanSound8K/audio/fold"+str(current_row["fold"])+"/"+str(current_row["slice_file_name"]) 25 | file_id = current_row["slice_file_name"].split(".")[0] 26 | 27 | # print(file_id) 28 | mfcc_save_path = "../../data/UrbanSound8K/mfcc/"+str(file_id)+".png" 29 | spec_save_path = "../../data/UrbanSound8K/spec/"+str(file_id)+".png" 30 | raw_save_path = "../../data/UrbanSound8K/raw_vectors/"+str(file_id)+".npy" 31 | wav_save_path = "../../data/UrbanSound8K/wav_files/"+str(file_id)+".wav" 32 | 33 | 34 | print(current_file_path) 35 | y = load_audio_file(current_file_path) 36 | sr = 22050 37 | # print(y.shape) 38 | mfcc_image(y,sr,mfcc_save_path) 39 | spectrogram_image(y, sr=sr, hop_length=hop_length, n_mels=n_mels, save_path = spec_save_path) 40 | save_raw_vectors(y,raw_save_path) 41 | shutil.copyfile(current_file_path,wav_save_path) 42 | -------------------------------------------------------------------------------- /codes/pre_processing/plot_data.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import librosa 3 | import librosa.display 4 | from matplotlib import pyplot as plt 5 | import skimage 6 | import glob 7 | 8 | def plot_data(feat,save_path): 9 | plt.figure() 10 | d = librosa.amplitude_to_db(np.abs(feat), ref=np.max) 11 | print(d.shape) 12 | print(mfcc_feat.shape) 13 | librosa.display.specshow(d, x_axis='time') 14 | ax = plt.subplot(111) 15 | ax.get_xaxis().set_visible(False) 16 | plt.tight_layout() 17 | plt.savefig(save_path,dpi = 300) 18 | plt.close() 19 | 20 | def plot_wave_data(y,sr,save_path): 21 | plt.figure() 22 | plt.title("Audio waveform") 23 | librosa.display.waveplot(y, sr=sr) 24 | plt.savefig(save_path,dpi = 300) 25 | plt.close() 26 | 27 | 28 | 29 | if __name__ == "__main__": 30 | 31 | 32 | file_paths = glob.glob("../../data/raw_data/wav_files/*") 33 | 34 | # print(len(file_paths)) 35 | 36 | for current_file in file_paths: 37 | plt.figure() 38 | current_file_id = current_file.split("/")[5].split(".")[0] 39 | print(current_file_id) 40 | 41 | y,sr = librosa.load(current_file) 42 | mfcc_feat = librosa.feature.mfcc(y= y,sr = sr, n_mfcc=20) 43 | spec_feat = librosa.feature.melspectrogram(y=y, sr=sr) 44 | 45 | mfcc_save_path = "../../data/plots/mfcc/"+str(current_file_id)+".png" 46 | spec_save_path = "../../data/plots/spec/"+str(current_file_id)+".png" 47 | wave_save_path = "../../data/plots/waveforms/"+str(current_file_id)+".png" 48 | 49 | plot_data(mfcc_feat,mfcc_save_path) 50 | plot_data(spec_feat,spec_save_path) 51 | plot_wave_data(y,sr,wave_save_path) 52 | 53 | # break 54 | 55 | 56 | -------------------------------------------------------------------------------- /codes/baseline/data_loader.py: -------------------------------------------------------------------------------- 1 | import glob 2 | import librosa 3 | import numpy as np 4 | import pandas as pd 5 | from PIL import Image 6 | from torch.utils.data import DataLoader, Dataset 7 | from torchvision import transforms, utils 8 | import torch 9 | 10 | 11 | transform_train = transforms.Compose([transforms.ToTensor()]) 12 | transform_test = transforms.Compose([transforms.ToTensor()]) 13 | 14 | 15 | class read_dataset(Dataset): 16 | 17 | def __init__(self,file_path, labels_path, file_type, transforms=None): 18 | 19 | self.df = pd.read_csv(labels_path) 20 | self.file_path = file_path 21 | self.file_type = file_type 22 | self.transforms = transforms 23 | 24 | 25 | def __len__(self): 26 | return len(self.df) 27 | 28 | def __getitem__(self, index): 29 | 30 | if(self.file_type == "raw_file"): 31 | file_data = np.load(self.file_path+"/"+str(self.df["file_id"][index])+".npy") 32 | file_data = torch.from_numpy(file_data) 33 | file_data = file_data.type(torch.FloatTensor) 34 | file_data = file_data.view(file_data.size(0),1) 35 | 36 | else: 37 | file_data = Image.open(self.file_path+"/"+str(self.df["file_id"][index])+".png") 38 | file_data = self.transforms(file_data) 39 | 40 | 41 | label = self.df["label"][index] 42 | 43 | 44 | 45 | return (file_data, label) 46 | 47 | 48 | 49 | 50 | def train_dataloader(file_path, labels_path, file_type, batch_size): 51 | 52 | train_set = read_dataset(file_path, labels_path, file_type, transform_train) 53 | 54 | return DataLoader(train_set, batch_size = batch_size, shuffle=True) 55 | 56 | 57 | def test_dataloader(file_path, labels_path, file_type, batch_size): 58 | 59 | test_set = read_dataset(file_path, labels_path, file_type, transform_test) 60 | return DataLoader(test_set, batch_size=batch_size, shuffle=False) 61 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # This file may be used to create an environment using: 2 | # $ conda create --name --file 3 | # platform: linux-64 4 | _libgcc_mutex=0.1=main 5 | audioread=2.1.8=pypi_0 6 | blas=1.0=mkl 7 | ca-certificates=2020.1.1=0 8 | certifi=2019.11.28=py37_0 9 | cffi=1.14.0=py37h2e261b9_0 10 | cudatoolkit=10.0.130=0 11 | cycler=0.10.0=pypi_0 12 | decorator=4.4.2=pypi_0 13 | freetype=2.9.1=h8a8886c_1 14 | intel-openmp=2020.0=166 15 | joblib=0.14.1=pypi_0 16 | jpeg=9b=h024ee3a_2 17 | kiwisolver=1.1.0=pypi_0 18 | ld_impl_linux-64=2.33.1=h53a641e_7 19 | libedit=3.1.20181209=hc058e9b_0 20 | libffi=3.2.1=hd88cf55_4 21 | libgcc-ng=9.1.0=hdf63c60_0 22 | libgfortran-ng=7.3.0=hdf63c60_0 23 | libpng=1.6.37=hbc83047_0 24 | librosa=0.7.2=pypi_0 25 | libstdcxx-ng=9.1.0=hdf63c60_0 26 | libtiff=4.1.0=h2733197_0 27 | llvmlite=0.31.0=pypi_0 28 | matplotlib=3.1.3=pypi_0 29 | mkl=2020.0=166 30 | mkl-service=2.3.0=py37he904b0f_0 31 | mkl_fft=1.0.15=py37ha843d7b_0 32 | mkl_random=1.1.0=py37hd6b4f25_0 33 | ncurses=6.2=he6710b0_0 34 | ninja=1.9.0=py37hfd86e86_0 35 | numba=0.48.0=pypi_0 36 | numpy=1.18.1=py37h4f9e942_0 37 | numpy-base=1.18.1=py37hde5b4d6_1 38 | olefile=0.46=py37_0 39 | opencv-python=4.2.0.32=pypi_0 40 | openssl=1.1.1d=h7b6447c_4 41 | pandas=1.0.1=pypi_0 42 | pillow=6.1.0=py37h34e0f95_0 43 | pip=20.0.2=py37_1 44 | pycparser=2.19=py37_0 45 | pyparsing=2.4.6=pypi_0 46 | python=3.7.6=h0371630_2 47 | python-dateutil=2.8.1=pypi_0 48 | pytorch=1.2.0=py3.7_cuda10.0.130_cudnn7.6.2_0 49 | pytz=2019.3=pypi_0 50 | readline=7.0=h7b6447c_5 51 | resampy=0.2.2=pypi_0 52 | scikit-learn=0.22.2=pypi_0 53 | scipy=1.4.1=pypi_0 54 | seaborn=0.10.0=pypi_0 55 | setuptools=45.2.0=py37_0 56 | six=1.14.0=py37_0 57 | sklearn=0.0=pypi_0 58 | soundfile=0.10.3.post1=pypi_0 59 | sqlite=3.31.1=h7b6447c_0 60 | tk=8.6.8=hbc83047_0 61 | torchsummary=1.5.1=pypi_0 62 | torchvision=0.4.0=py37_cu100 63 | wheel=0.34.2=py37_0 64 | xz=5.2.4=h14c3975_4 65 | zlib=1.2.11=h7b6447c_3 66 | zstd=1.3.7=h0b5b093_0 67 | -------------------------------------------------------------------------------- /codes/pre_processing/data_augmentation.py: -------------------------------------------------------------------------------- 1 | from utils import augment_data,mfcc_image, spectrogram_image,save_raw_vectors,plot_time_series 2 | 3 | 4 | import glob 5 | import shutil 6 | import librosa 7 | import librosa.display 8 | import numpy as np 9 | import pandas as pd 10 | import skimage 11 | from matplotlib import cm 12 | from matplotlib import pyplot as plt 13 | 14 | 15 | if __name__ == "__main__": 16 | hop_length = 512 17 | n_mels = 128 18 | time_steps = 384 19 | 20 | flag = "val" 21 | file_list = glob.glob("../../data/training_data/"+str(flag)+"/wav_files/*") 22 | 23 | 24 | for current_file_path in file_list: 25 | 26 | file_id = current_file_path.split("/")[6].split(".")[0] 27 | 28 | mfcc_save_path = "../../data/augmented_data/"+str(flag)+"mfcc/"+str(file_id)+".png" 29 | spec_save_path = "../../data/augmented_data/"+str(flag)+"spec/"+str(file_id)+".png" 30 | raw_save_path = "../../data/augmented_data/"+str(flag)+"raw_vectors/"+str(file_id)+".npy" 31 | wav_save_path = "../../data/augmented_data/"+str(flag)+"wave_files/"+str(file_id)+".png" 32 | 33 | print(current_file_path) 34 | y, sr = librosa.load(current_file_path) 35 | augmented_data = augment_data(y) 36 | for i in range(4): 37 | 38 | mfcc_save_path = "../../data/augmented_data/"+str(flag)+"/mfcc/"+str(file_id)+"_"+str(i)+".png" 39 | spec_save_path = "../../data/augmented_data/"+str(flag)+"/spec/"+str(file_id)+"_"+str(i)+".png" 40 | raw_save_path = "../../data/augmented_data/"+str(flag)+"/raw_vectors/"+str(file_id)+"_"+str(i)+".npy" 41 | wav_save_path = "../../data/augmented_data/"+str(flag)+"/wav_files/"+str(file_id)+"_"+str(i)+".png" 42 | 43 | current_data = augmented_data[i] 44 | if(len(current_data) != 110250): 45 | print("*******************YOLO*********************") 46 | # temp_path = str(i)+".png" 47 | # plot_time_series(current_data,temp_path) 48 | 49 | librosa.output.write_wav(wav_save_path,current_data,sr) 50 | mfcc_image(current_data,sr,mfcc_save_path) 51 | spectrogram_image(current_data, sr=sr, hop_length=hop_length, n_mels=n_mels, save_path = spec_save_path) 52 | save_raw_vectors(current_data,raw_save_path) 53 | 54 | # break 55 | 56 | -------------------------------------------------------------------------------- /codes/pre_processing/create_csv.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | import shutil 4 | import glob 5 | 6 | total_per_class = 30 7 | total_classes = 10 8 | 9 | train = [] 10 | validation = [] 11 | 12 | def main(): 13 | for current_class in range(total_classes): 14 | print("*"*80) 15 | print(current_class) 16 | 17 | for i in range(1,total_per_class+1): 18 | # print("+"*40) 19 | current_wav_path = "../../data/raw_data/wav_files/"+str(i)+"_"+str(current_class)+".wav" 20 | current_mfcc_path = "../../data/raw_data/mfcc/"+str(i)+"_"+str(current_class)+".png" 21 | current_spectrogram_path = "../../data/raw_data/spectrogram/"+str(i)+"_"+str(current_class)+".png" 22 | current_file_id = str(i)+"_"+str(current_class) 23 | current_row = [current_file_id,current_class] 24 | print(current_file_id) 25 | 26 | if(i<=25): 27 | copy_wav_path = "../../data/training_data/train/wav_files/"+str(i)+"_"+str(current_class)+".wav" 28 | copy_mfcc_path = "../../data/training_data/train/mfcc/"+str(i)+"_"+str(current_class)+".png" 29 | copy_spec_path = "../../data/training_data/train/spectrogram/"+str(i)+"_"+str(current_class)+".png" 30 | train.append(current_row) 31 | 32 | 33 | else: 34 | copy_wav_path = "../../data/training_data/validation/wav_files/"+str(i)+"_"+str(current_class)+".wav" 35 | copy_mfcc_path = "../../data/training_data/validation/mfcc/"+str(i)+"_"+str(current_class)+".png" 36 | copy_spec_path = "../../data/training_data/validation/spectrogram/"+str(i)+"_"+str(current_class)+".png" 37 | validation.append(current_row) 38 | 39 | shutil.copy(current_wav_path,copy_wav_path) 40 | shutil.copy(current_mfcc_path,copy_mfcc_path) 41 | shutil.copy(current_spectrogram_path,copy_spec_path) 42 | 43 | 44 | 45 | # break 46 | 47 | columns = ['file_id',"label"] 48 | print("[INFO] SAVING DATA IN DATAFRAME") 49 | df = pd.DataFrame(index=np.arange(len(train)), columns=columns) 50 | df.loc[:] = train 51 | df.to_csv("../../data/training_data/train/train.csv", encoding="utf-8", index=False) 52 | 53 | 54 | 55 | df = pd.DataFrame(index=np.arange(len(validation)), columns=columns) 56 | df.loc[:] = validation 57 | df.to_csv("../../data/training_data/validation/validation.csv", encoding="utf-8", index=False) 58 | 59 | if __name__ == "__main__": 60 | main() -------------------------------------------------------------------------------- /codes/pre_processing/utils.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | import random 3 | import librosa 4 | import matplotlib.pyplot as plt 5 | import numpy as np 6 | import skimage 7 | import skimage.io 8 | 9 | 10 | def scale_minmax(X, min=0.0, max=1.0): 11 | X_std = (X - X.min()) / (X.max() - X.min()) 12 | X_scaled = X_std * (max - min) + min 13 | return X_scaled 14 | 15 | def spectrogram_image(y, sr, hop_length, n_mels,save_path): 16 | mels = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=n_mels, n_fft=hop_length*2, hop_length=hop_length) 17 | mels = np.log(mels + 1e-9) 18 | 19 | img = scale_minmax(mels, 0, 255).astype(np.uint8) 20 | img = np.flip(img, axis=0) 21 | img = 255-img # invert. make black==more energy 22 | 23 | # save as PNG 24 | skimage.io.imsave(save_path, img) 25 | 26 | 27 | def mfcc_image(y, sr,save_path): 28 | mfcc_feat = librosa.feature.mfcc(y= y,sr = sr) 29 | d = librosa.amplitude_to_db(np.abs(mfcc_feat), ref=np.max) 30 | 31 | 32 | img = scale_minmax(d, 0, 255).astype(np.uint8) 33 | img = np.flip(img, axis=0) 34 | img = 255-img 35 | skimage.io.imsave(save_path, img) 36 | 37 | 38 | def save_raw_vectors(y,save_path): 39 | 40 | np.save(save_path,y) 41 | 42 | 43 | 44 | 45 | 46 | def load_audio_file(file_path): 47 | input_length = 110250 48 | data = librosa.core.load(file_path)[0] #, sr=16000 49 | if len(data)>input_length: 50 | data = data[:input_length] 51 | else: 52 | data = np.pad(data, (0, max(0, input_length - len(data))), "constant") 53 | return data 54 | 55 | 56 | def constant_length(data): 57 | input_length = 110250 58 | if len(data)>input_length: 59 | data = data[:input_length] 60 | else: 61 | data = np.pad(data, (0, max(0, input_length - len(data))), "constant") 62 | return data 63 | 64 | 65 | 66 | 67 | def plot_time_series(data,save_path): 68 | fig = plt.figure() 69 | plt.title('Raw wave ') 70 | plt.ylabel('Amplitude') 71 | plt.plot(np.linspace(0, 1, len(data)), data) 72 | plt.show() 73 | plt.savefig(save_path,dpi = 300) 74 | 75 | # Noise 76 | def add_noise(data): 77 | wn = np.random.randn(len(data)) 78 | data_wn = data + 0.005*wn 79 | return data_wn 80 | 81 | # Shifting the sound 82 | def shift(data): 83 | 84 | data_roll = np.roll(data, 2000) 85 | data_roll = constant_length(data_roll) 86 | return data_roll 87 | 88 | 89 | 90 | def stretch(data, rate= 0.8): 91 | new_data = librosa.effects.time_stretch(data, rate) 92 | new_data = constant_length(new_data) 93 | return new_data 94 | 95 | def augment_data(data): 96 | new_data = [] 97 | new_data.append(scale_minmax(data)) 98 | new_data.append(scale_minmax(add_noise(data))) 99 | new_data.append(scale_minmax(shift(data))) 100 | new_data.append(scale_minmax(stretch(data))) 101 | 102 | return new_data 103 | 104 | 105 | -------------------------------------------------------------------------------- /data/augmented_data/val/val.csv: -------------------------------------------------------------------------------- 1 | file_id,label 2 | 28_7_1,7 3 | 28_1_1,1 4 | 26_5_2,5 5 | 26_7_1,7 6 | 30_2_2,2 7 | 27_5_0,5 8 | 29_1_2,1 9 | 29_3_3,3 10 | 27_9_1,9 11 | 27_8_3,8 12 | 29_5_0,5 13 | 30_6_0,6 14 | 29_8_3,8 15 | 30_3_2,3 16 | 28_2_1,2 17 | 27_5_3,5 18 | 27_4_2,4 19 | 30_5_2,5 20 | 28_5_1,5 21 | 28_9_0,9 22 | 26_6_0,6 23 | 27_6_2,6 24 | 29_7_3,7 25 | 30_0_3,0 26 | 28_3_3,3 27 | 26_2_3,2 28 | 27_1_0,1 29 | 27_2_3,2 30 | 29_7_0,7 31 | 28_4_2,4 32 | 26_6_1,6 33 | 28_5_2,5 34 | 29_9_0,9 35 | 27_0_3,0 36 | 29_5_3,5 37 | 27_7_0,7 38 | 30_4_2,4 39 | 29_3_1,3 40 | 30_1_2,1 41 | 29_3_0,3 42 | 26_4_1,4 43 | 30_1_0,1 44 | 28_2_0,2 45 | 30_2_1,2 46 | 29_6_3,6 47 | 27_7_3,7 48 | 27_4_1,4 49 | 26_0_0,0 50 | 27_8_1,8 51 | 28_8_1,8 52 | 26_2_0,2 53 | 27_0_1,0 54 | 27_9_3,9 55 | 26_3_1,3 56 | 28_7_3,7 57 | 29_2_3,2 58 | 26_9_1,9 59 | 29_7_1,7 60 | 27_9_2,9 61 | 27_3_2,3 62 | 26_8_2,8 63 | 27_6_1,6 64 | 26_8_0,8 65 | 26_5_3,5 66 | 28_1_3,1 67 | 27_1_2,1 68 | 26_2_2,2 69 | 29_0_2,0 70 | 29_0_3,0 71 | 28_3_1,3 72 | 30_2_3,2 73 | 26_5_1,5 74 | 28_3_2,3 75 | 30_1_1,1 76 | 28_9_1,9 77 | 27_3_3,3 78 | 28_0_0,0 79 | 30_9_3,9 80 | 30_7_2,7 81 | 28_5_0,5 82 | 30_2_0,2 83 | 27_3_1,3 84 | 30_8_1,8 85 | 30_7_1,7 86 | 29_2_1,2 87 | 29_5_2,5 88 | 27_4_3,4 89 | 28_0_3,0 90 | 26_1_1,1 91 | 26_7_3,7 92 | 29_6_0,6 93 | 26_4_3,4 94 | 26_5_0,5 95 | 26_2_1,2 96 | 30_3_1,3 97 | 29_2_2,2 98 | 26_9_0,9 99 | 30_6_1,6 100 | 30_8_0,8 101 | 29_6_2,6 102 | 28_9_3,9 103 | 29_4_0,4 104 | 26_0_2,0 105 | 29_8_1,8 106 | 29_0_1,0 107 | 26_9_2,9 108 | 28_3_0,3 109 | 27_7_1,7 110 | 26_6_2,6 111 | 28_4_1,4 112 | 29_1_3,1 113 | 30_1_3,1 114 | 27_6_0,6 115 | 26_8_1,8 116 | 30_5_1,5 117 | 30_8_2,8 118 | 26_0_3,0 119 | 29_9_1,9 120 | 30_9_2,9 121 | 30_8_3,8 122 | 26_7_0,7 123 | 26_6_3,6 124 | 30_0_2,0 125 | 29_2_0,2 126 | 26_1_2,1 127 | 28_4_0,4 128 | 30_0_1,0 129 | 26_3_2,3 130 | 30_0_0,0 131 | 30_6_2,6 132 | 30_4_3,4 133 | 27_8_0,8 134 | 29_5_1,5 135 | 30_7_3,7 136 | 30_5_0,5 137 | 26_3_0,3 138 | 28_9_2,9 139 | 28_7_2,7 140 | 27_8_2,8 141 | 26_4_2,4 142 | 28_5_3,5 143 | 28_1_2,1 144 | 27_4_0,4 145 | 26_0_1,0 146 | 26_7_2,7 147 | 29_4_1,4 148 | 29_4_2,4 149 | 29_4_3,4 150 | 28_8_2,8 151 | 28_2_3,2 152 | 27_5_2,5 153 | 28_8_3,8 154 | 27_3_0,3 155 | 27_7_2,7 156 | 29_7_2,7 157 | 28_6_1,6 158 | 26_1_0,1 159 | 27_1_1,1 160 | 27_2_0,2 161 | 28_2_2,2 162 | 27_2_1,2 163 | 30_9_1,9 164 | 28_8_0,8 165 | 29_6_1,6 166 | 27_0_2,0 167 | 28_4_3,4 168 | 27_5_1,5 169 | 28_1_0,1 170 | 30_9_0,9 171 | 26_9_3,9 172 | 29_1_0,1 173 | 29_8_2,8 174 | 29_8_0,8 175 | 27_6_3,6 176 | 28_6_2,6 177 | 27_2_2,2 178 | 30_3_3,3 179 | 30_4_1,4 180 | 27_9_0,9 181 | 30_5_3,5 182 | 30_6_3,6 183 | 29_3_2,3 184 | 29_9_3,9 185 | 26_3_3,3 186 | 26_8_3,8 187 | 28_0_1,0 188 | 30_4_0,4 189 | 28_0_2,0 190 | 27_1_3,1 191 | 28_7_0,7 192 | 29_1_1,1 193 | 26_1_3,1 194 | 29_0_0,0 195 | 30_7_0,7 196 | 28_6_3,6 197 | 28_6_0,6 198 | 29_9_2,9 199 | 26_4_0,4 200 | 30_3_0,3 201 | 27_0_0,0 202 | -------------------------------------------------------------------------------- /data/training_data/train/train.csv: -------------------------------------------------------------------------------- 1 | file_id,label 2 | 1_0,0 3 | 2_0,0 4 | 3_0,0 5 | 4_0,0 6 | 5_0,0 7 | 6_0,0 8 | 7_0,0 9 | 8_0,0 10 | 9_0,0 11 | 10_0,0 12 | 11_0,0 13 | 12_0,0 14 | 13_0,0 15 | 14_0,0 16 | 15_0,0 17 | 16_0,0 18 | 17_0,0 19 | 18_0,0 20 | 19_0,0 21 | 20_0,0 22 | 21_0,0 23 | 22_0,0 24 | 23_0,0 25 | 24_0,0 26 | 25_0,0 27 | 1_1,1 28 | 2_1,1 29 | 3_1,1 30 | 4_1,1 31 | 5_1,1 32 | 6_1,1 33 | 7_1,1 34 | 8_1,1 35 | 9_1,1 36 | 10_1,1 37 | 11_1,1 38 | 12_1,1 39 | 13_1,1 40 | 14_1,1 41 | 15_1,1 42 | 16_1,1 43 | 17_1,1 44 | 18_1,1 45 | 19_1,1 46 | 20_1,1 47 | 21_1,1 48 | 22_1,1 49 | 23_1,1 50 | 24_1,1 51 | 25_1,1 52 | 1_2,2 53 | 2_2,2 54 | 3_2,2 55 | 4_2,2 56 | 5_2,2 57 | 6_2,2 58 | 7_2,2 59 | 8_2,2 60 | 9_2,2 61 | 10_2,2 62 | 11_2,2 63 | 12_2,2 64 | 13_2,2 65 | 14_2,2 66 | 15_2,2 67 | 16_2,2 68 | 17_2,2 69 | 18_2,2 70 | 19_2,2 71 | 20_2,2 72 | 21_2,2 73 | 22_2,2 74 | 23_2,2 75 | 24_2,2 76 | 25_2,2 77 | 1_3,3 78 | 2_3,3 79 | 3_3,3 80 | 4_3,3 81 | 5_3,3 82 | 6_3,3 83 | 7_3,3 84 | 8_3,3 85 | 9_3,3 86 | 10_3,3 87 | 11_3,3 88 | 12_3,3 89 | 13_3,3 90 | 14_3,3 91 | 15_3,3 92 | 16_3,3 93 | 17_3,3 94 | 18_3,3 95 | 19_3,3 96 | 20_3,3 97 | 21_3,3 98 | 22_3,3 99 | 23_3,3 100 | 24_3,3 101 | 25_3,3 102 | 1_4,4 103 | 2_4,4 104 | 3_4,4 105 | 4_4,4 106 | 5_4,4 107 | 6_4,4 108 | 7_4,4 109 | 8_4,4 110 | 9_4,4 111 | 10_4,4 112 | 11_4,4 113 | 12_4,4 114 | 13_4,4 115 | 14_4,4 116 | 15_4,4 117 | 16_4,4 118 | 17_4,4 119 | 18_4,4 120 | 19_4,4 121 | 20_4,4 122 | 21_4,4 123 | 22_4,4 124 | 23_4,4 125 | 24_4,4 126 | 25_4,4 127 | 1_5,5 128 | 2_5,5 129 | 3_5,5 130 | 4_5,5 131 | 5_5,5 132 | 6_5,5 133 | 7_5,5 134 | 8_5,5 135 | 9_5,5 136 | 10_5,5 137 | 11_5,5 138 | 12_5,5 139 | 13_5,5 140 | 14_5,5 141 | 15_5,5 142 | 16_5,5 143 | 17_5,5 144 | 18_5,5 145 | 19_5,5 146 | 20_5,5 147 | 21_5,5 148 | 22_5,5 149 | 23_5,5 150 | 24_5,5 151 | 25_5,5 152 | 1_6,6 153 | 2_6,6 154 | 3_6,6 155 | 4_6,6 156 | 5_6,6 157 | 6_6,6 158 | 7_6,6 159 | 8_6,6 160 | 9_6,6 161 | 10_6,6 162 | 11_6,6 163 | 12_6,6 164 | 13_6,6 165 | 14_6,6 166 | 15_6,6 167 | 16_6,6 168 | 17_6,6 169 | 18_6,6 170 | 19_6,6 171 | 20_6,6 172 | 21_6,6 173 | 22_6,6 174 | 23_6,6 175 | 24_6,6 176 | 25_6,6 177 | 1_7,7 178 | 2_7,7 179 | 3_7,7 180 | 4_7,7 181 | 5_7,7 182 | 6_7,7 183 | 7_7,7 184 | 8_7,7 185 | 9_7,7 186 | 10_7,7 187 | 11_7,7 188 | 12_7,7 189 | 13_7,7 190 | 14_7,7 191 | 15_7,7 192 | 16_7,7 193 | 17_7,7 194 | 18_7,7 195 | 19_7,7 196 | 20_7,7 197 | 21_7,7 198 | 22_7,7 199 | 23_7,7 200 | 24_7,7 201 | 25_7,7 202 | 1_8,8 203 | 2_8,8 204 | 3_8,8 205 | 4_8,8 206 | 5_8,8 207 | 6_8,8 208 | 7_8,8 209 | 8_8,8 210 | 9_8,8 211 | 10_8,8 212 | 11_8,8 213 | 12_8,8 214 | 13_8,8 215 | 14_8,8 216 | 15_8,8 217 | 16_8,8 218 | 17_8,8 219 | 18_8,8 220 | 19_8,8 221 | 20_8,8 222 | 21_8,8 223 | 22_8,8 224 | 23_8,8 225 | 24_8,8 226 | 25_8,8 227 | 1_9,9 228 | 2_9,9 229 | 3_9,9 230 | 4_9,9 231 | 5_9,9 232 | 6_9,9 233 | 7_9,9 234 | 8_9,9 235 | 9_9,9 236 | 10_9,9 237 | 11_9,9 238 | 12_9,9 239 | 13_9,9 240 | 14_9,9 241 | 15_9,9 242 | 16_9,9 243 | 17_9,9 244 | 18_9,9 245 | 19_9,9 246 | 20_9,9 247 | 21_9,9 248 | 22_9,9 249 | 23_9,9 250 | 24_9,9 251 | 25_9,9 252 | -------------------------------------------------------------------------------- /codes/baseline/config.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pathlib import Path 3 | 4 | 5 | class config_class(): 6 | def __init__(self,resume,debug,file_type,model_name): 7 | 8 | 9 | 10 | 11 | self.file_type = file_type 12 | self.model_name = model_name 13 | 14 | self.dataset = "base" #"urbansound", "augmentd", "base" 15 | # self.saved_model_dir = "./outputs/urbansound_models/" 16 | # self.output_model_dir = "./outputs/"+self.dataset+"_fintune_models/" 17 | 18 | self.saved_model_dir = "./outputs/base_models/" 19 | self.output_model_dir = "./outputs/base_models/" 20 | 21 | 22 | print("DATASET SELECTED: ",self.dataset.upper()) 23 | 24 | 25 | 26 | if(self.file_type == "raw_file"): 27 | if(self.dataset == "augmented"): 28 | 29 | self.train_file_path = "../../data/augmented_data/train/raw_vectors" 30 | self.val_file_path = "../../data/augmented_data/val/raw_vectors/" 31 | 32 | 33 | elif(self.dataset == "urbansound"): 34 | 35 | self.train_file_path = "../../data/UrbanSound8K/raw_vectors" 36 | self.val_file_path = "../../data/UrbanSound8K/raw_vectors/" 37 | 38 | 39 | elif(self.dataset == "base"): 40 | 41 | self.train_file_path = "../../data/training_data/train/raw_vectors" 42 | self.val_file_path = "../../data/training_data/val/raw_vectors/" 43 | 44 | 45 | 46 | 47 | elif(self.file_type == "mfcc"): 48 | 49 | if(self.dataset == "augmented"): 50 | self.train_file_path = "../../data/augmented_data/train/mfcc" 51 | self.val_file_path = "../../data/augmented_data/val/mfcc/" 52 | 53 | 54 | elif(self.dataset == "urbansound"): 55 | 56 | self.train_file_path = "../../data/UrbanSound8K/mfcc" 57 | self.val_file_path = "../../data/UrbanSound8K/mfcc/" 58 | 59 | 60 | elif(self.dataset == "base"): 61 | 62 | self.train_file_path = "../../data/training_data/train/mfcc" 63 | self.val_file_path = "../../data/training_data/val/mfcc/" 64 | 65 | 66 | 67 | elif(self.file_type == "spec"): 68 | 69 | if(self.dataset == "augmented"): 70 | self.train_file_path = "../../data/augmented_data/train/spec" 71 | self.val_file_path = "../../data/augmented_data/val/spec/" 72 | 73 | 74 | elif(self.dataset == "urbansound"): 75 | 76 | self.train_file_path = "../../data/UrbanSound8K/spec" 77 | self.val_file_path = "../../data/UrbanSound8K/spec/" 78 | 79 | 80 | 81 | 82 | elif(self.dataset == "base"): 83 | self.train_file_path = "../../data/training_data/train/spectrogram" 84 | self.val_file_path = "../../data/training_data/val/spectrogram" 85 | 86 | 87 | if(self.dataset == "augmented"): 88 | self.train_labels_path = "../../data/augmented_data/train/train.csv" 89 | self.val_labels_path = "../../data/augmented_data/val/val.csv" 90 | 91 | 92 | elif(self.dataset == "urbansound"): 93 | self.train_labels_path = "../../data/UrbanSound8K/train.csv" 94 | self.val_labels_path = "../../data/UrbanSound8K/val.csv" 95 | 96 | 97 | 98 | elif(self.dataset == "base"): 99 | 100 | self.train_labels_path = "../../data/training_data/train/train.csv" 101 | self.val_labels_path = "../../data/training_data/val/val.csv" 102 | 103 | 104 | self.epochs = 200 105 | self.batch_size = 16 106 | self.numWorkers = 2 107 | self.lr=0.001 108 | self.momentum=0.9 109 | self.weight_decay=5e-4 110 | self.train_paitence=20 111 | 112 | 113 | 114 | self.resume=resume 115 | self.debug = debug 116 | self.use_pretrained=True 117 | self.best_model = True 118 | self.use_gpu=True -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Audio classification using CNN and LSTM 2 | 3 | 4 | 5 | ## Data Visualization 6 | 7 | ### MFCC Features 8 | 9 | 10 | ### Spectrogram 11 | 12 | 13 | 14 | ### Raw Audio 15 | 16 | 17 | 18 | ## Results 19 | 20 | 21 | 34 | 35 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
CNN
SpectrogramMFCC
DatasetTrainValidationTrainValidation
urbansound8k99.91497.25210084.544
66 | 67 | 68 | 69 | 70 | 71 | 72 | # 73 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
CNN-LSTM
SpectrogramMFCC
DatasetTrainValidationTrainValidation
urbansound8k99.92896.45199.98582.369
104 | 105 | 106 | ### Training Accuracy Plot 107 | 108 | 109 | 110 | 111 | ### Validation Accuracy Plot 112 | 113 | 114 | 115 | 116 | 117 | 118 | ### Training Error Plot 119 | 120 | 121 | 122 | 123 | 124 | ### Validation Error Plot 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | ## Installation 133 | 134 | Use the package manager [pip](https://pip.pypa.io/en/stable/) to install foobar. 135 | 136 | ```bash 137 | pip install requirements.txt 138 | ``` 139 | 140 | or 141 | 142 | ```bash 143 | conda create --name --file requirements.txt 144 | ``` 145 | 146 | ## Usage 147 | ### Dataset 148 | [urbansound8k] 149 | 150 | ### Pre-process Data 151 | 152 | ```bash 153 | python codes/pre_processing/pre_processing_urbansound.py 154 | ``` 155 | ### Train and Test 156 | ```bash 157 | python codes/baseline/main.py 158 | ``` 159 | 160 | 161 | [urbansound8k]: [https://urbansounddataset.weebly.com/urbansound8k.html] 162 | 163 | ## Contributing 164 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 165 | 166 | Please make sure to update tests as appropriate. 167 | 168 | 169 | ## License 170 | [MIT](https://choosealicense.com/licenses/mit/) -------------------------------------------------------------------------------- /codes/baseline/utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import shutil 3 | import os 4 | import time 5 | import sys 6 | from matplotlib import pyplot as plt 7 | import seaborn as sns 8 | import cv2 9 | from pathlib import Path 10 | from sklearn.metrics import confusion_matrix, roc_curve, auc, roc_auc_score 11 | from sklearn import preprocessing 12 | 13 | 14 | 15 | def prepareDirs(config): 16 | 17 | print('==> Preparing data..') 18 | if not os.path.exists(config.output_model_dir): 19 | os.makedirs(config.output_model_dir) 20 | 21 | if not os.path.exists(config.output_model_dir+"/"+config.model_name): 22 | os.makedirs(config.output_model_dir+"/"+config.model_name) 23 | 24 | if not os.path.exists(config.output_model_dir+"/"+config.model_name+"/"+config.file_type): 25 | os.makedirs(config.output_model_dir+"/"+config.model_name+"/"+config.file_type) 26 | 27 | if not os.path.exists(config.output_model_dir+"/"+config.model_name+"/"+config.file_type +"/data"): 28 | os.makedirs(config.output_model_dir+"/"+config.model_name+"/"+config.file_type + "/data") 29 | 30 | 31 | def prepareData(data): 32 | finalData=[] 33 | for i in data: 34 | 35 | try: 36 | for j in i: 37 | finalData.append(j) 38 | except: 39 | print("ERROR") 40 | finalData=np.array(finalData) 41 | # print(finalData.shape) 42 | return finalData 43 | 44 | 45 | 46 | _, term_width = os.popen('stty size', 'r').read().split() 47 | term_width = int(term_width) 48 | 49 | TOTAL_BAR_LENGTH = 65. 50 | last_time = time.time() 51 | begin_time = last_time 52 | def progress_bar(current, total, msg=None): 53 | global last_time, begin_time 54 | if current == 0: 55 | begin_time = time.time() # Reset for new bar. 56 | 57 | cur_len = int(TOTAL_BAR_LENGTH*current/total) 58 | rest_len = int(TOTAL_BAR_LENGTH - cur_len) - 1 59 | 60 | sys.stdout.write(' [') 61 | for i in range(cur_len): 62 | sys.stdout.write('=') 63 | sys.stdout.write('>') 64 | for i in range(rest_len): 65 | sys.stdout.write('.') 66 | sys.stdout.write(']') 67 | 68 | cur_time = time.time() 69 | step_time = cur_time - last_time 70 | last_time = cur_time 71 | tot_time = cur_time - begin_time 72 | 73 | L = [] 74 | L.append(' Step: %s' % format_time(step_time)) 75 | L.append(' | Tot: %s' % format_time(tot_time)) 76 | if msg: 77 | L.append(' | ' + msg) 78 | 79 | msg = ''.join(L) 80 | sys.stdout.write(msg) 81 | for i in range(term_width-int(TOTAL_BAR_LENGTH)-len(msg)-3): 82 | sys.stdout.write(' ') 83 | 84 | # Go back to the center of the bar. 85 | for i in range(term_width-int(TOTAL_BAR_LENGTH/2)+2): 86 | sys.stdout.write('\b') 87 | sys.stdout.write(' %d/%d ' % (current+1, total)) 88 | 89 | if current < total-1: 90 | sys.stdout.write('\r') 91 | else: 92 | sys.stdout.write('\n') 93 | sys.stdout.flush() 94 | 95 | 96 | def format_time(seconds): 97 | days = int(seconds / 3600/24) 98 | seconds = seconds - days*3600*24 99 | hours = int(seconds / 3600) 100 | seconds = seconds - hours*3600 101 | minutes = int(seconds / 60) 102 | seconds = seconds - minutes*60 103 | secondsf = int(seconds) 104 | seconds = seconds - secondsf 105 | millis = int(seconds*1000) 106 | 107 | f = '' 108 | i = 1 109 | if days > 0: 110 | f += str(days) + 'D' 111 | i += 1 112 | if hours > 0 and i <= 2: 113 | f += str(hours) + 'h' 114 | i += 1 115 | if minutes > 0 and i <= 2: 116 | f += str(minutes) + 'm' 117 | i += 1 118 | if secondsf > 0 and i <= 2: 119 | f += str(secondsf) + 's' 120 | i += 1 121 | if millis > 0 and i <= 2: 122 | f += str(millis) + 'ms' 123 | i += 1 124 | if f == '': 125 | f = '0ms' 126 | return f 127 | 128 | 129 | 130 | def normalized_confusion_matrix(true_labels,predict_labels,classes_list,save_path): 131 | 132 | cmap=plt.cm.Blues 133 | 134 | cm = confusion_matrix(true_labels, predict_labels) 135 | cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis] 136 | print(cm) 137 | cm =np.round(cm,2) 138 | plt.imshow(cm, interpolation='nearest', cmap=cmap) 139 | plt.title("confusion matrix") 140 | plt.colorbar() 141 | tick_marks = np.arange(len(classes_list)) 142 | plt.xticks(tick_marks, classes_list, rotation=45) 143 | plt.yticks(tick_marks, classes_list) 144 | 145 | thresh = cm.max() / 2. 146 | for i in range (cm.shape[0]): 147 | for j in range (cm.shape[1]): 148 | plt.text(j, i, cm[i, j],horizontalalignment="center",color="white" if cm[i, j] > thresh else "black") 149 | 150 | plt.tight_layout() 151 | plt.ylabel('True label') 152 | plt.xlabel('Predicted label') 153 | plt.savefig(save_path + "confusion_matrix.png",dpi = 300) 154 | 155 | return None 156 | 157 | 158 | def one_hot(labels): 159 | 160 | label_binarizer = preprocessing.LabelBinarizer() 161 | label_binarizer.fit(range(max(labels)+1)) 162 | b = label_binarizer.transform(labels) 163 | 164 | return b 165 | 166 | def plot_roc_curve(true_labels,pred_labels,classes_list,save_path): 167 | 168 | 169 | 170 | fpr = dict() 171 | tpr = dict() 172 | roc_auc = dict() 173 | for i in classes_list: 174 | fpr[i], tpr[i], _ = roc_curve(true_labels[:, i], pred_labels[:, i]) 175 | roc_auc[i] = auc(fpr[i], tpr[i]) 176 | 177 | 178 | 179 | plt.figure() 180 | for i in classes_list: 181 | plt.plot(fpr[i], tpr[i], label='Class {0} (area = {1:0.2f})'''.format(i, roc_auc[i])) 182 | 183 | plt.plot([0, 1], [0, 1], 'k--') 184 | plt.xlim([0.0, 1.0]) 185 | plt.ylim([0.0, 1.05]) 186 | plt.xlabel('False Positive Rate') 187 | plt.ylabel('True Positive Rate') 188 | plt.title('ROC CURVE') 189 | plt.legend(loc="lower right") 190 | plt.savefig(save_path+"roc_curve.png",dpi = 300) 191 | -------------------------------------------------------------------------------- /codes/baseline/models/resnet_utils.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | # from .utils import load_state_dict_from_url 4 | 5 | 6 | 7 | model_urls = { 8 | 'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth', 9 | 'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth', 10 | 'resnet50': 'https://download.pytorch.org/models/resnet50-19c8e357.pth', 11 | 'resnet101': 'https://download.pytorch.org/models/resnet101-5d3b4d8f.pth', 12 | 'resnet152': 'https://download.pytorch.org/models/resnet152-b121ed2d.pth', 13 | } 14 | 15 | 16 | def conv3x3(in_planes, out_planes, stride=1, groups=1, dilation=1): 17 | """3x3 convolution with padding""" 18 | return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, 19 | padding=dilation, groups=groups, bias=False, dilation=dilation) 20 | 21 | 22 | def conv1x1(in_planes, out_planes, stride=1): 23 | """1x1 convolution""" 24 | return nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride, bias=False) 25 | 26 | 27 | class BasicBlock(nn.Module): 28 | expansion = 1 29 | __constants__ = ['downsample'] 30 | 31 | def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1, 32 | base_width=64, dilation=1, norm_layer=None): 33 | super(BasicBlock, self).__init__() 34 | if norm_layer is None: 35 | norm_layer = nn.BatchNorm2d 36 | if groups != 1 or base_width != 64: 37 | raise ValueError('BasicBlock only supports groups=1 and base_width=64') 38 | if dilation > 1: 39 | raise NotImplementedError("Dilation > 1 not supported in BasicBlock") 40 | # Both self.conv1 and self.downsample layers downsample the input when stride != 1 41 | self.conv1 = conv3x3(inplanes, planes, stride) 42 | self.bn1 = norm_layer(planes) 43 | self.relu = nn.ReLU(inplace=True) 44 | self.conv2 = conv3x3(planes, planes) 45 | self.bn2 = norm_layer(planes) 46 | self.downsample = downsample 47 | self.stride = stride 48 | 49 | def forward(self, x): 50 | identity = x 51 | 52 | out = self.conv1(x) 53 | out = self.bn1(out) 54 | out = self.relu(out) 55 | 56 | out = self.conv2(out) 57 | out = self.bn2(out) 58 | 59 | if self.downsample is not None: 60 | identity = self.downsample(x) 61 | 62 | out += identity 63 | out = self.relu(out) 64 | 65 | return out 66 | 67 | 68 | class Bottleneck(nn.Module): 69 | expansion = 4 70 | __constants__ = ['downsample'] 71 | 72 | def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1, 73 | base_width=64, dilation=1, norm_layer=None): 74 | super(Bottleneck, self).__init__() 75 | if norm_layer is None: 76 | norm_layer = nn.BatchNorm2d 77 | width = int(planes * (base_width / 64.)) * groups 78 | # Both self.conv2 and self.downsample layers downsample the input when stride != 1 79 | self.conv1 = conv1x1(inplanes, width) 80 | self.bn1 = norm_layer(width) 81 | self.conv2 = conv3x3(width, width, stride, groups, dilation) 82 | self.bn2 = norm_layer(width) 83 | self.conv3 = conv1x1(width, planes * self.expansion) 84 | self.bn3 = norm_layer(planes * self.expansion) 85 | self.relu = nn.ReLU(inplace=True) 86 | self.downsample = downsample 87 | self.stride = stride 88 | 89 | def forward(self, x): 90 | identity = x 91 | 92 | out = self.conv1(x) 93 | out = self.bn1(out) 94 | out = self.relu(out) 95 | 96 | out = self.conv2(out) 97 | out = self.bn2(out) 98 | out = self.relu(out) 99 | 100 | out = self.conv3(out) 101 | out = self.bn3(out) 102 | 103 | if self.downsample is not None: 104 | identity = self.downsample(x) 105 | 106 | out += identity 107 | out = self.relu(out) 108 | 109 | return out 110 | 111 | 112 | class ResNet(nn.Module): 113 | 114 | def __init__(self, block, layers, num_classes=10, zero_init_residual=False, 115 | groups=1, width_per_group=64, replace_stride_with_dilation=None, 116 | norm_layer=None): 117 | super(ResNet, self).__init__() 118 | if norm_layer is None: 119 | norm_layer = nn.BatchNorm2d 120 | self._norm_layer = norm_layer 121 | 122 | self.inplanes = 64 123 | self.dilation = 1 124 | if replace_stride_with_dilation is None: 125 | # each element in the tuple indicates if we should replace 126 | # the 2x2 stride with a dilated convolution instead 127 | replace_stride_with_dilation = [False, False, False] 128 | if len(replace_stride_with_dilation) != 3: 129 | raise ValueError("replace_stride_with_dilation should be None " 130 | "or a 3-element tuple, got {}".format(replace_stride_with_dilation)) 131 | self.groups = groups 132 | self.base_width = width_per_group 133 | self.conv1 = nn.Conv2d(1, self.inplanes, kernel_size=7, stride=2, padding=3, 134 | bias=False) 135 | self.bn1 = norm_layer(self.inplanes) 136 | self.relu = nn.ReLU(inplace=True) 137 | self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) 138 | self.layer1 = self._make_layer(block, 64, layers[0]) 139 | self.layer2 = self._make_layer(block, 128, layers[1], stride=2, 140 | dilate=replace_stride_with_dilation[0]) 141 | self.layer3 = self._make_layer(block, 256, layers[2], stride=2, 142 | dilate=replace_stride_with_dilation[1]) 143 | self.layer4 = self._make_layer(block, 512, layers[3], stride=2, 144 | dilate=replace_stride_with_dilation[2]) 145 | self.avgpool = nn.AdaptiveAvgPool2d((1, 1)) 146 | self.fc = nn.Linear(512 * block.expansion, num_classes) 147 | 148 | for m in self.modules(): 149 | if isinstance(m, nn.Conv2d): 150 | nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu') 151 | elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)): 152 | nn.init.constant_(m.weight, 1) 153 | nn.init.constant_(m.bias, 0) 154 | 155 | # Zero-initialize the last BN in each residual branch, 156 | # so that the residual branch starts with zeros, and each residual block behaves like an identity. 157 | # This improves the model by 0.2~0.3% according to https://arxiv.org/abs/1706.02677 158 | if zero_init_residual: 159 | for m in self.modules(): 160 | if isinstance(m, Bottleneck): 161 | nn.init.constant_(m.bn3.weight, 0) 162 | elif isinstance(m, BasicBlock): 163 | nn.init.constant_(m.bn2.weight, 0) 164 | 165 | def _make_layer(self, block, planes, blocks, stride=1, dilate=False): 166 | norm_layer = self._norm_layer 167 | downsample = None 168 | previous_dilation = self.dilation 169 | if dilate: 170 | self.dilation *= stride 171 | stride = 1 172 | if stride != 1 or self.inplanes != planes * block.expansion: 173 | downsample = nn.Sequential( 174 | conv1x1(self.inplanes, planes * block.expansion, stride), 175 | norm_layer(planes * block.expansion), 176 | ) 177 | 178 | layers = [] 179 | layers.append(block(self.inplanes, planes, stride, downsample, self.groups, 180 | self.base_width, previous_dilation, norm_layer)) 181 | self.inplanes = planes * block.expansion 182 | for _ in range(1, blocks): 183 | layers.append(block(self.inplanes, planes, groups=self.groups, 184 | base_width=self.base_width, dilation=self.dilation, 185 | norm_layer=norm_layer)) 186 | 187 | return nn.Sequential(*layers) 188 | 189 | def _forward_impl(self, x): 190 | 191 | x = self.conv1(x) 192 | x = self.bn1(x) 193 | x = self.relu(x) 194 | x = self.maxpool(x) 195 | 196 | x = self.layer1(x) 197 | x = self.layer2(x) 198 | x = self.layer3(x) 199 | x = self.layer4(x) 200 | 201 | x = self.avgpool(x) 202 | x = torch.flatten(x, 1) 203 | x = self.fc(x) 204 | 205 | return x 206 | 207 | def forward(self, x): 208 | return self._forward_impl(x) 209 | 210 | 211 | def _resnet(arch, block, layers, pretrained, progress, **kwargs): 212 | model = ResNet(block, layers, **kwargs) 213 | # if pretrained: 214 | # state_dict = load_state_dict_from_url(model_urls[arch], 215 | # progress=progress) 216 | # model.load_state_dict(state_dict) 217 | 218 | return model 219 | 220 | -------------------------------------------------------------------------------- /codes/baseline/models/models.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | import torch.nn.functional as F 3 | from torchsummary import summary 4 | from resnet_utils import BasicBlock, Bottleneck, _resnet 5 | from densenet_utils import densenet121 6 | import torch 7 | 8 | def resnet18(pretrained=False, progress=True, **kwargs): 9 | 10 | return _resnet('resnet18', BasicBlock, [2, 2, 2, 2], pretrained, progress, 11 | **kwargs) 12 | 13 | def resnet34(pretrained=False, progress=True, **kwargs): 14 | 15 | return _resnet('resnet34', BasicBlock, [3, 4, 6, 3], pretrained, progress, 16 | **kwargs) 17 | 18 | 19 | def resnet50(pretrained=False, progress=True, **kwargs): 20 | 21 | return _resnet('resnet50', Bottleneck, [3, 4, 6, 3], pretrained, progress, 22 | **kwargs) 23 | 24 | 25 | def resnet101(pretrained=False, progress=True, **kwargs): 26 | 27 | return _resnet('resnet101', Bottleneck, [3, 4, 23, 3], pretrained, progress, 28 | **kwargs) 29 | 30 | 31 | def resnet152(pretrained=False, progress=True, **kwargs): 32 | return _resnet('resnet152', Bottleneck, [3, 8, 36, 3], pretrained, progress, 33 | **kwargs) 34 | 35 | def resnet_feature_model(): 36 | 37 | model = resnet18() 38 | model = nn.Sequential(*list(model.classifier.children())[:-3]) 39 | return model 40 | 41 | class LSTM_2(nn.Module): 42 | def __init__(self): 43 | super(LSTM_2, self).__init__() 44 | 45 | # 59049 x 1 46 | self.conv1 = nn.Sequential( 47 | nn.Conv1d(1, 128, kernel_size=3, stride=3, padding=0), 48 | nn.BatchNorm1d(128), 49 | nn.ReLU()) 50 | # 19683 x 128 51 | self.conv2 = nn.Sequential( 52 | nn.Conv1d(128, 128, kernel_size=3, stride=1, padding=1), 53 | nn.BatchNorm1d(128), 54 | nn.ReLU(), 55 | nn.MaxPool1d(3, stride=3)) 56 | # 6561 x 128 57 | self.conv3 = nn.Sequential( 58 | nn.Conv1d(128, 128, kernel_size=3, stride=1, padding=1), 59 | nn.BatchNorm1d(128), 60 | nn.ReLU(), 61 | nn.MaxPool1d(3,stride=3)) 62 | # 2187 x 128 63 | self.conv4 = nn.Sequential( 64 | nn.Conv1d(128, 256, kernel_size=3, stride=1, padding=1), 65 | nn.BatchNorm1d(256), 66 | nn.ReLU(), 67 | nn.MaxPool1d(3,stride=3)) 68 | # 729 x 256 69 | self.conv5 = nn.Sequential( 70 | nn.Conv1d(256, 256, kernel_size=3, stride=1, padding=1), 71 | nn.BatchNorm1d(256), 72 | nn.ReLU(), 73 | nn.MaxPool1d(3,stride=3)) 74 | # 243 x 256 75 | self.conv6 = nn.Sequential( 76 | nn.Conv1d(256, 256, kernel_size=3, stride=1, padding=1), 77 | nn.BatchNorm1d(256), 78 | nn.ReLU(), 79 | nn.MaxPool1d(3,stride=3), 80 | nn.Dropout(0.4)) 81 | # 81 x 256 82 | self.conv7 = nn.Sequential( 83 | nn.Conv1d(256, 256, kernel_size=3, stride=1, padding=1), 84 | nn.BatchNorm1d(256), 85 | nn.ReLU(), 86 | nn.MaxPool1d(3,stride=3)) 87 | # 27 x 256 88 | self.conv8 = nn.Sequential( 89 | nn.Conv1d(256, 256, kernel_size=3, stride=1, padding=1), 90 | nn.BatchNorm1d(256), 91 | nn.ReLU(), 92 | nn.MaxPool1d(3,stride=3)) 93 | 94 | # 9 x 256 95 | self.conv9 = nn.Sequential( 96 | nn.Conv1d(256, 256, kernel_size=3, stride=1, padding=1), 97 | nn.BatchNorm1d(256), 98 | nn.ReLU(), 99 | nn.MaxPool1d(3,stride=3)) 100 | 101 | # 3 x 256 102 | self.conv10 = nn.Sequential( 103 | nn.Conv1d(256, 512, kernel_size=3, stride=1, padding=1), 104 | nn.BatchNorm1d(512), 105 | nn.ReLU(), 106 | nn.MaxPool1d(3,stride=3)) 107 | # 1 x 512 108 | self.conv11 = nn.Sequential( 109 | nn.Conv1d(512, 512, kernel_size=3, stride=1, padding=1), 110 | nn.BatchNorm1d(512), 111 | nn.ReLU(), 112 | nn.Dropout(0.4)) 113 | # 1 x 512 114 | self.lstm = nn.LSTM(1, 128, 2, dropout=0.01,batch_first = True) 115 | self.fc = nn.Linear(512*128, 10) 116 | 117 | 118 | def forward(self, x): 119 | # input x : 23 x 59049 x 1 120 | # expected conv1d input : minibatch_size x num_channel x width 121 | 122 | x = x.view(x.shape[0], 1,-1) 123 | # print(x.size()) 124 | # x : 23 x 1 x 59049 125 | 126 | out = self.conv1(x) 127 | out = self.conv2(out) 128 | out = self.conv3(out) 129 | out = self.conv4(out) 130 | out = self.conv5(out) 131 | out = self.conv6(out) 132 | out = self.conv7(out) 133 | out = self.conv8(out) 134 | out = self.conv9(out) 135 | out = self.conv10(out) 136 | out = self.conv11(out) 137 | out,hidden = self.lstm(out) 138 | out = out.reshape(x.shape[0], out.size(1) * out.size(2)) 139 | out = self.fc(out) 140 | out = F.log_softmax(out, dim=1) 141 | 142 | 143 | #logit = self.activation(logit) 144 | 145 | return out 146 | 147 | 148 | 149 | 150 | class LSTM(nn.Module): 151 | def __init__(self, input_dim,input_size, hidden_dim, batch_size, num_layers, output_dim): 152 | super(LSTM, self).__init__() 153 | self.input_dim = input_dim 154 | self.input_size = input_size 155 | self.hidden_dim = hidden_dim 156 | self.batch_size = batch_size 157 | self.num_layers = num_layers 158 | self.output_dim = output_dim 159 | 160 | 161 | 162 | self.lstm = nn.LSTM(self.input_dim, self.hidden_dim, self.num_layers, batch_first = True, dropout = 0.4) 163 | self.linear = nn.Linear(self.hidden_dim, output_dim) 164 | 165 | def init_hidden(self): 166 | return ( 167 | torch.zeros(self.num_layers, self.batch_size, self.hidden_dim).cuda(), 168 | torch.zeros(self.num_layers, self.batch_size, self.hidden_dim).cuda(), 169 | ) 170 | 171 | def forward(self, x): 172 | 173 | out,hidden = self.lstm(x) 174 | out = out[:,-1] 175 | # out = out.reshape(-1,out.size(1)*out.size(2)) 176 | out = self.linear(out) 177 | out = F.log_softmax(out, dim=1) 178 | 179 | return out 180 | 181 | class CRNN(nn.Module): 182 | def __init__(self,hidden_dim , 183 | batch_size , 184 | num_layers, 185 | output_dim, 186 | temp, 187 | dropout=0): 188 | 189 | super(CRNN, self).__init__() 190 | 191 | self.hidden_dim = hidden_dim 192 | self.batch_size = batch_size 193 | self.num_layers = num_layers 194 | self.output_dim = output_dim 195 | self.dropout = dropout 196 | 197 | 198 | self.cnn = self.feature_extractor() 199 | self.lstm = nn.LSTM(self.get_block_size(self.cnn),self.hidden_dim, self.num_layers,batch_first=True,dropout=self.dropout) 200 | self.linear = nn.Linear(self.hidden_dim*temp, output_dim) 201 | 202 | 203 | 204 | 205 | 206 | def forward(self, x): 207 | 208 | 209 | # hidden = self.init_hidden() 210 | features = self.cnn(x) 211 | features = features.view(-1,features.size(1),features.size(2)*features.size(3)) 212 | features = features.permute(0, 2, 1) 213 | out, hidden = self.lstm(features) 214 | out = out.reshape(-1,out.size(1)*out.size(2)) 215 | out = self.linear(out) 216 | out = F.log_softmax(out, dim=1) 217 | return out 218 | 219 | def feature_extractor(self): 220 | 221 | model = resnet18() 222 | new_model = nn.Sequential(model.conv1, 223 | model.bn1, 224 | model.relu, 225 | model.maxpool, 226 | model.layer1, 227 | model.layer2, 228 | model.layer3, 229 | model.layer4 230 | ) 231 | 232 | return new_model 233 | 234 | 235 | 236 | def init_hidden(self): 237 | return ( 238 | torch.zeros(self.num_layers, self.batch_size, self.hidden_dim).cuda(), 239 | torch.zeros(self.num_layers, self.batch_size, self.hidden_dim).cuda(), 240 | ) 241 | 242 | 243 | 244 | def get_block_size(self, layer): 245 | return layer[-1][-1].bn2.weight.size()[0] 246 | 247 | 248 | 249 | class Ensemble_model(nn.Module): 250 | def __init__(self): 251 | super(Ensemble_model, self).__init__() 252 | self.spec_net = resnet18() 253 | self.mfcc_net = resnet18() 254 | 255 | 256 | 257 | def forward(self, spec_file, mfcc_file): 258 | spec_out = self.spec_net(spec_file) 259 | mfcc_out = self.mfcc_net(mfcc_file) 260 | 261 | mean_output = torch.mean(torch.stack((spec_out,mfcc_out)),dim = 0) 262 | 263 | return spec_out 264 | 265 | 266 | def select_model(model_name,data_type): 267 | 268 | if(model_name == "cnn"): 269 | 270 | print("RESNET !!!") 271 | # model = resnet18() 272 | model = densenet121() 273 | 274 | 275 | elif(model_name == "lstm"): 276 | 277 | print("Build LSTM RNN model ...") 278 | input_size = 1 279 | hidden_size = 128 280 | output_size = 10 281 | batch_size = 5 282 | n_layers = 2 283 | seq_len = 110250 284 | 285 | model = LSTM_2() 286 | 287 | 288 | elif("cnn_lstm"): 289 | 290 | print("Build CNN LSTM model ...") 291 | 292 | if(data_type == "spec"): 293 | print("FOR SPECTROGRAM DATA ...") 294 | temp = 28 295 | else: 296 | print("FOR MFCC DATA ...") 297 | 298 | temp = 7 299 | 300 | hidden_dim = 128 301 | batch_size = 2 302 | num_layers = 2 303 | output_dim = 10 304 | 305 | model = CRNN(hidden_dim,batch_size,num_layers,output_dim,temp) 306 | 307 | return model 308 | 309 | 310 | 311 | 312 | 313 | # model = select_model("lstm_model") 314 | # x = torch.randn((2,110250,1)) 315 | 316 | # model(x) -------------------------------------------------------------------------------- /codes/baseline/trainer.py: -------------------------------------------------------------------------------- 1 | import wandb 2 | import sys 3 | sys.path.insert(1, 'models/') 4 | from torchsummary import summary 5 | import torch.optim as optim 6 | import numpy as np 7 | import torch 8 | import os 9 | from utils import progress_bar,prepareData,normalized_confusion_matrix,plot_roc_curve,one_hot 10 | 11 | from torch.nn import functional as F 12 | import torch.nn as nn 13 | from models import select_model 14 | import shutil 15 | from PIL import Image 16 | 17 | 18 | class Trainer(): 19 | 20 | def __init__(self,config,train_loader,val_loader,model_name): 21 | 22 | self.config = config 23 | self.train_loader = train_loader 24 | self.val_loader = val_loader 25 | self.model_name = model_name 26 | 27 | 28 | self.num_train = len(self.train_loader.dataset) 29 | self.num_valid = len(self.val_loader.dataset) 30 | self.saved_model_dir = self.config.saved_model_dir 31 | self.output_model_dir = self.config.output_model_dir 32 | self.best_model = config.best_model 33 | self.use_gpu = self.config.use_gpu 34 | 35 | 36 | 37 | if(self.config.resume == True): 38 | print("LOADING SAVED MODEL") 39 | self.net = select_model(self.model_name,self.config.file_type) 40 | self.loadCheckpoint() 41 | 42 | else: 43 | print("INTIALIZING NEW MODEL") 44 | 45 | self.net = select_model(self.model_name,self.config.file_type) 46 | 47 | self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") 48 | self.net = self.net.to(self.device) 49 | self.total_epochs = config.epochs 50 | 51 | 52 | if(self.model_name =="lstm_model" or self.model_name =="cnn_lstm_model"): 53 | print("NLL LOSS") 54 | self.criterion = nn.NLLLoss() 55 | self.optimizer = optim.Adam(self.net.parameters(), lr=0.0001) 56 | loss_name = "nll_loss" 57 | lr = 0.0001 58 | 59 | else: 60 | self.criterion = nn.CrossEntropyLoss() 61 | self.optimizer = optim.SGD(self.net.parameters(),lr = self.config.lr, 62 | momentum = self.config.momentum, 63 | weight_decay = self.config.weight_decay) 64 | 65 | loss_name = "crossentropy_loss" 66 | lr = self.config.lr 67 | 68 | 69 | 70 | self.num_params = sum([p.data.nelement() for p in self.net.parameters()]) 71 | self.batch_size = self.config.batch_size 72 | self.train_paitence = config.train_paitence 73 | self.num_classes = 10 74 | 75 | if(self.config.debug == False): 76 | self.experiment = wandb.init(project="audio_classification") 77 | 78 | hyper_params = { 79 | "model_name": self.model_name, 80 | "file_type": self.config.file_type, 81 | "dataset": self.config.dataset, 82 | "batch_size": self.config.batch_size, 83 | "num_epochs": self.total_epochs, 84 | "loss_function": loss_name, 85 | "learning_rate": lr, 86 | "momentum": self.config.momentum, 87 | "weight_decay": self.config.weight_decay 88 | 89 | } 90 | self.experiment.config.update(hyper_params) 91 | wandb.watch(self.net) 92 | 93 | # summary(self.net, input_size=(1, 128, 216)) 94 | print('[*] Number of model parameters: {:,}'.format(self.num_params)) 95 | 96 | 97 | 98 | 99 | def train(self): 100 | best_valid_acc=0 101 | 102 | print("\n[*] Train on {} sample pairs, validate on {} trials".format( 103 | self.num_train, self.num_valid)) 104 | 105 | train_acc_list = [] 106 | train_loss_list = [] 107 | val_acc_list = [] 108 | val_loss_list = [] 109 | 110 | for epoch in range(0,self.total_epochs): 111 | 112 | print('\nEpoch: {}/{}'.format(epoch+1, self.total_epochs)) 113 | 114 | 115 | train_acc,train_loss = self.train_one_epoch(epoch) 116 | val_acc,val_loss = self.val_one_epoch(epoch) 117 | 118 | train_acc_list.append(train_acc) 119 | train_loss_list.append(train_loss) 120 | val_acc_list.append(val_acc) 121 | val_loss_list.append(val_loss) 122 | # check for improvement 123 | if(val_acc > best_valid_acc): 124 | print("COUNT RESET !!!") 125 | best_valid_acc = val_acc 126 | self.counter = 0 127 | self.saveCheckPoint( 128 | { 129 | 'epoch': epoch + 1, 130 | 'model_state': self.net.state_dict(), 131 | 'optim_state': self.optimizer.state_dict(), 132 | 'best_valid_acc': best_valid_acc, 133 | },True) 134 | 135 | else: 136 | self.counter += 1 137 | 138 | 139 | if self.counter > self.train_paitence: 140 | self.saveCheckPoint( 141 | { 142 | 'epoch': epoch + 1, 143 | 'model_state': self.net.state_dict(), 144 | 'optim_state': self.optimizer.state_dict(), 145 | 'best_valid_acc': val_acc, 146 | },False) 147 | print("[!] No improvement in a while, stopping training...") 148 | print("BEST VALIDATION ACCURACY: ",best_valid_acc) 149 | 150 | 151 | break 152 | 153 | print("Saving Data ...") 154 | self.plot_cm_roc(self.val_loader) 155 | save_path = os.path.join(self.output_model_dir, self.config.model_name, self.config.file_type) 156 | if(self.config.debug == False): 157 | wandb.run.summary["best_accuracy"] = best_valid_acc 158 | np.save(os.path.join(save_path,"data/train_acc.npy"), np.array(train_acc_list)) 159 | np.save(os.path.join(save_path,"data/train_loss.npy"),np.array(train_loss_list)) 160 | np.save(os.path.join(save_path,"data/val_acc.npy"),np.array(val_acc_list)) 161 | np.save(os.path.join(save_path,"data/val_loss.npy"),np.array(val_loss_list)) 162 | 163 | # return train_acc_list,train_loss_list,val_acc_list,val_loss_list 164 | 165 | 166 | 167 | 168 | 169 | def train_one_epoch(self,epoch): 170 | self.net.train() 171 | train_loss = 0 172 | correct = 0 173 | total = 0 174 | 175 | for batch_idx, (file_data, targets) in enumerate(self.train_loader): 176 | 177 | file_data = file_data.to(self.device) 178 | targets = targets.to(self.device) 179 | 180 | self.optimizer.zero_grad() 181 | 182 | outputs = self.net(file_data) 183 | 184 | loss = self.criterion(outputs, targets) 185 | loss.backward() 186 | self.optimizer.step() 187 | 188 | train_loss += loss.item() 189 | currentTrainLoss=loss.item() 190 | _, predicted = outputs.max(1) 191 | total += targets.size(0) 192 | correct += predicted.eq(targets).sum().item() 193 | 194 | del(file_data) 195 | del(targets) 196 | 197 | progress_bar(batch_idx, len(self.train_loader), 'Loss: %.3f | Acc: %.3f%% (%d/%d)' 198 | % (train_loss/(batch_idx+1), 100.*correct/total, correct, total)) 199 | 200 | if(self.config.debug == False): 201 | 202 | self.experiment.log({'Train/Loss': train_loss/(batch_idx+1)},step = epoch) 203 | self.experiment.log({"Train/Accuracy": correct / total},step = epoch) 204 | 205 | return correct/total, currentTrainLoss 206 | 207 | 208 | 209 | def val_one_epoch(self,epoch): 210 | self.net.eval() 211 | validation_loss = 0 212 | correct = 0 213 | total = 0 214 | accuracy_list = [] 215 | loss_list = [] 216 | 217 | 218 | with torch.no_grad(): 219 | for batch_idx, (file_data, targets) in enumerate(self.val_loader): 220 | 221 | 222 | file_data = file_data.to(self.device) 223 | targets = targets.to(self.device) 224 | outputs = self.net(file_data) 225 | loss = self.criterion(outputs, targets) 226 | validation_loss += loss.item() 227 | _, predicted = outputs.max(1) 228 | total += targets.size(0) 229 | correct += predicted.eq(targets).sum().item() 230 | progress_bar(batch_idx, len(self.val_loader), 'Loss: %.3f | Acc: %.3f%% (%d/%d)' 231 | % (validation_loss/(batch_idx+1), 100.*correct/total, correct, total)) 232 | 233 | del(file_data) 234 | del(targets) 235 | if(self.config.debug == False): 236 | 237 | self.experiment.log({'Validation/Loss': validation_loss/(batch_idx+1)},step = epoch) 238 | self.experiment.log({"Validation/Accuracy": correct/total}, step = epoch) 239 | 240 | 241 | 242 | validation_accuracy = correct/total 243 | return validation_accuracy, validation_loss/(batch_idx+1) 244 | 245 | 246 | 247 | def test(self,dataLoader): 248 | self.net.eval() 249 | test_loss = 0 250 | correct = 0 251 | total = 0 252 | 253 | probOutput=[] 254 | trueOutput=[] 255 | predictedOutput = [] 256 | 257 | 258 | with torch.no_grad(): 259 | for batch_idx, (file_data, targets) in enumerate(dataLoader): 260 | 261 | 262 | file_data = file_data.to(self.device) 263 | targets = targets.to(self.device) 264 | outputs = self.net(file_data) 265 | 266 | _, predicted = outputs.max(1) 267 | tempOutput = F.softmax(outputs,dim=1).cpu().numpy() 268 | probOutput.append(tempOutput) 269 | 270 | trueOutput.append(targets.cpu().numpy()) 271 | predictedOutput.append(predicted.cpu().numpy()) 272 | 273 | total += targets.size(0) 274 | correct += predicted.eq(targets).sum().item() 275 | 276 | 277 | del(file_data) 278 | del(targets) 279 | 280 | print("\nTEST ACCURACY: ",100.*correct/total) 281 | if(self.config.debug == False): 282 | wandb.run.summary["test_accuracy"] = correct/total 283 | 284 | return probOutput,trueOutput,predictedOutput 285 | 286 | 287 | 288 | def saveCheckPoint(self,state,isBest): 289 | filename = "model.pth" 290 | ckpt_path = os.path.join(self.output_model_dir,self.config.model_name,self.config.file_type, filename) 291 | torch.save(state, ckpt_path) 292 | 293 | if isBest: 294 | 295 | filename = "best_model.pth" 296 | shutil.copyfile(ckpt_path, os.path.join(self.output_model_dir,self.config.model_name,self.config.file_type, filename)) 297 | 298 | 299 | def loadCheckpoint(self): 300 | 301 | print("[*] Loading model from {}".format(self.saved_model_dir)) 302 | if(self.best_model): 303 | print("LOADING BEST MODEL") 304 | 305 | filename = "best_model.pth" 306 | 307 | else: 308 | filename = "model.pth" 309 | 310 | ckpt_path = os.path.join(self.saved_model_dir,self.model_name,self.config.file_type, filename) 311 | print(ckpt_path) 312 | 313 | if(self.use_gpu==False): 314 | self.net=torch.load(ckpt_path, map_location=lambda storage, loc: storage) 315 | 316 | else: 317 | print("*"*40+" LOADING MODEL FROM GPU "+"*"*40) 318 | self.ckpt = torch.load(ckpt_path) 319 | self.net.load_state_dict(self.ckpt['model_state']) 320 | self.net.cuda() 321 | 322 | 323 | def plot_cm_roc(self,data_loader): 324 | print("*****************Calculating Confusion Matrix*****************") 325 | 326 | 327 | save_path = os.path.join(self.output_model_dir, self.config.model_name, self.config.file_type,"data/") 328 | 329 | classes = np.arange(self.num_classes) 330 | probOutput,trueOutput,predictedOutput = self.test(data_loader) 331 | 332 | 333 | trueOutput = prepareData(trueOutput) 334 | predictedOutput = prepareData(predictedOutput) 335 | probOutput = prepareData(probOutput) 336 | 337 | one_hot_true_out = one_hot(trueOutput) 338 | 339 | normalized_confusion_matrix(trueOutput,predictedOutput,classes,save_path) 340 | plot_roc_curve(one_hot_true_out,probOutput,classes,save_path) 341 | 342 | if(self.config.debug == False): 343 | path = os.path.join(self.output_model_dir, self.config.model_name, self.config.file_type,"data/") 344 | 345 | cm = Image.open(path+"confusion_matrix.png") 346 | roc = Image.open(path+"roc_curve.png") 347 | 348 | wandb.log({"Confusion Matrix": [wandb.Image(cm, caption="Confusion Matrix")]}) 349 | wandb.log({"ROC Curve": [wandb.Image(roc, caption="ROC Curve")]}) 350 | 351 | # wandb.sklearn.plot_confusion_matrix(trueOutput,predictedOutput,classes) 352 | # wandb.sklearn.plot_roc(one_hot_true_out,probOutput,classes) 353 | 354 | 355 | 356 | 357 | return None 358 | -------------------------------------------------------------------------------- /codes/baseline/models/densenet_utils.py: -------------------------------------------------------------------------------- 1 | import re 2 | import torch 3 | import torch.nn as nn 4 | import torch.nn.functional as F 5 | import torch.utils.checkpoint as cp 6 | from collections import OrderedDict 7 | from torch import Tensor 8 | from torch.jit.annotations import List 9 | 10 | 11 | __all__ = ['DenseNet', 'densenet121', 'densenet169', 'densenet201', 'densenet161'] 12 | 13 | model_urls = { 14 | 'densenet121': 'https://download.pytorch.org/models/densenet121-a639ec97.pth', 15 | 'densenet169': 'https://download.pytorch.org/models/densenet169-b2777c0a.pth', 16 | 'densenet201': 'https://download.pytorch.org/models/densenet201-c1103571.pth', 17 | 'densenet161': 'https://download.pytorch.org/models/densenet161-8d451a50.pth', 18 | } 19 | 20 | 21 | class _DenseLayer(nn.Module): 22 | def __init__(self, num_input_features, growth_rate, bn_size, drop_rate, memory_efficient=False): 23 | super(_DenseLayer, self).__init__() 24 | self.add_module('norm1', nn.BatchNorm2d(num_input_features)), 25 | self.add_module('relu1', nn.ReLU(inplace=True)), 26 | self.add_module('conv1', nn.Conv2d(num_input_features, bn_size * 27 | growth_rate, kernel_size=1, stride=1, 28 | bias=False)), 29 | self.add_module('norm2', nn.BatchNorm2d(bn_size * growth_rate)), 30 | self.add_module('relu2', nn.ReLU(inplace=True)), 31 | self.add_module('conv2', nn.Conv2d(bn_size * growth_rate, growth_rate, 32 | kernel_size=3, stride=1, padding=1, 33 | bias=False)), 34 | self.drop_rate = float(drop_rate) 35 | self.memory_efficient = memory_efficient 36 | 37 | def bn_function(self, inputs): 38 | # type: (List[Tensor]) -> Tensor 39 | concated_features = torch.cat(inputs, 1) 40 | bottleneck_output = self.conv1(self.relu1(self.norm1(concated_features))) # noqa: T484 41 | return bottleneck_output 42 | 43 | # todo: rewrite when torchscript supports any 44 | def any_requires_grad(self, input): 45 | # type: (List[Tensor]) -> bool 46 | for tensor in input: 47 | if tensor.requires_grad: 48 | return True 49 | return False 50 | 51 | # @torch.jit.unused # noqa: T484 52 | def call_checkpoint_bottleneck(self, input): 53 | # type: (List[Tensor]) -> Tensor 54 | def closure(*inputs): 55 | return self.bn_function(*inputs) 56 | 57 | return cp.checkpoint(closure, input) 58 | 59 | # @torch.jit._overload_method # noqa: F811 60 | def forward(self, input): 61 | # type: (List[Tensor]) -> (Tensor) 62 | pass 63 | 64 | # @torch.jit._overload_method # noqa: F811 65 | def forward(self, input): 66 | # type: (Tensor) -> (Tensor) 67 | pass 68 | 69 | # torchscript does not yet support *args, so we overload method 70 | # allowing it to take either a List[Tensor] or single Tensor 71 | def forward(self, input): # noqa: F811 72 | if isinstance(input, Tensor): 73 | prev_features = [input] 74 | else: 75 | prev_features = input 76 | 77 | if self.memory_efficient and self.any_requires_grad(prev_features): 78 | if torch.jit.is_scripting(): 79 | raise Exception("Memory Efficient not supported in JIT") 80 | 81 | bottleneck_output = self.call_checkpoint_bottleneck(prev_features) 82 | else: 83 | bottleneck_output = self.bn_function(prev_features) 84 | 85 | new_features = self.conv2(self.relu2(self.norm2(bottleneck_output))) 86 | if self.drop_rate > 0: 87 | new_features = F.dropout(new_features, p=self.drop_rate, 88 | training=self.training) 89 | return new_features 90 | 91 | 92 | class _DenseBlock(nn.ModuleDict): 93 | _version = 2 94 | 95 | def __init__(self, num_layers, num_input_features, bn_size, growth_rate, drop_rate, memory_efficient=False): 96 | super(_DenseBlock, self).__init__() 97 | for i in range(num_layers): 98 | layer = _DenseLayer( 99 | num_input_features + i * growth_rate, 100 | growth_rate=growth_rate, 101 | bn_size=bn_size, 102 | drop_rate=drop_rate, 103 | memory_efficient=memory_efficient, 104 | ) 105 | self.add_module('denselayer%d' % (i + 1), layer) 106 | 107 | def forward(self, init_features): 108 | features = [init_features] 109 | for name, layer in self.items(): 110 | new_features = layer(features) 111 | features.append(new_features) 112 | return torch.cat(features, 1) 113 | 114 | 115 | class _Transition(nn.Sequential): 116 | def __init__(self, num_input_features, num_output_features): 117 | super(_Transition, self).__init__() 118 | self.add_module('norm', nn.BatchNorm2d(num_input_features)) 119 | self.add_module('relu', nn.ReLU(inplace=True)) 120 | self.add_module('conv', nn.Conv2d(num_input_features, num_output_features, 121 | kernel_size=1, stride=1, bias=False)) 122 | self.add_module('pool', nn.AvgPool2d(kernel_size=2, stride=2)) 123 | 124 | 125 | class DenseNet(nn.Module): 126 | r"""Densenet-BC model class, based on 127 | `"Densely Connected Convolutional Networks" `_ 128 | 129 | Args: 130 | growth_rate (int) - how many filters to add each layer (`k` in paper) 131 | block_config (list of 4 ints) - how many layers in each pooling block 132 | num_init_features (int) - the number of filters to learn in the first convolution layer 133 | bn_size (int) - multiplicative factor for number of bottle neck layers 134 | (i.e. bn_size * k features in the bottleneck layer) 135 | drop_rate (float) - dropout rate after each dense layer 136 | num_classes (int) - number of classification classes 137 | memory_efficient (bool) - If True, uses checkpointing. Much more memory efficient, 138 | but slower. Default: *False*. See `"paper" `_ 139 | """ 140 | 141 | def __init__(self, growth_rate=32, block_config=(6, 12, 24, 16), 142 | num_init_features=64, bn_size=4, drop_rate=0, num_classes = 10, memory_efficient=False): 143 | 144 | super(DenseNet, self).__init__() 145 | 146 | # First convolution 147 | self.features = nn.Sequential(OrderedDict([ 148 | ('conv0', nn.Conv2d(1, num_init_features, kernel_size=7, stride=2, 149 | padding=3, bias=False)), 150 | ('norm0', nn.BatchNorm2d(num_init_features)), 151 | ('relu0', nn.ReLU(inplace=True)), 152 | ('pool0', nn.MaxPool2d(kernel_size=3, stride=2, padding=1)), 153 | ])) 154 | 155 | # Each denseblock 156 | num_features = num_init_features 157 | for i, num_layers in enumerate(block_config): 158 | block = _DenseBlock( 159 | num_layers=num_layers, 160 | num_input_features=num_features, 161 | bn_size=bn_size, 162 | growth_rate=growth_rate, 163 | drop_rate=drop_rate, 164 | memory_efficient=memory_efficient 165 | ) 166 | self.features.add_module('denseblock%d' % (i + 1), block) 167 | num_features = num_features + num_layers * growth_rate 168 | if i != len(block_config) - 1: 169 | trans = _Transition(num_input_features=num_features, 170 | num_output_features=num_features // 2) 171 | self.features.add_module('transition%d' % (i + 1), trans) 172 | num_features = num_features // 2 173 | 174 | # Final batch norm 175 | self.features.add_module('norm5', nn.BatchNorm2d(num_features)) 176 | 177 | # Linear layer 178 | self.classifier = nn.Linear(num_features, num_classes) 179 | 180 | # Official init from torch repo. 181 | for m in self.modules(): 182 | if isinstance(m, nn.Conv2d): 183 | nn.init.kaiming_normal_(m.weight) 184 | elif isinstance(m, nn.BatchNorm2d): 185 | nn.init.constant_(m.weight, 1) 186 | nn.init.constant_(m.bias, 0) 187 | elif isinstance(m, nn.Linear): 188 | nn.init.constant_(m.bias, 0) 189 | 190 | def forward(self, x): 191 | features = self.features(x) 192 | out = F.relu(features, inplace=True) 193 | out = F.adaptive_avg_pool2d(out, (1, 1)) 194 | out = torch.flatten(out, 1) 195 | out = self.classifier(out) 196 | return out 197 | 198 | 199 | def _load_state_dict(model, model_url, progress): 200 | # '.'s are no longer allowed in module names, but previous _DenseLayer 201 | # has keys 'norm.1', 'relu.1', 'conv.1', 'norm.2', 'relu.2', 'conv.2'. 202 | # They are also in the checkpoints in model_urls. This pattern is used 203 | # to find such keys. 204 | pattern = re.compile( 205 | r'^(.*denselayer\d+\.(?:norm|relu|conv))\.((?:[12])\.(?:weight|bias|running_mean|running_var))$') 206 | 207 | state_dict = load_state_dict_from_url(model_url, progress=progress) 208 | for key in list(state_dict.keys()): 209 | res = pattern.match(key) 210 | if res: 211 | new_key = res.group(1) + res.group(2) 212 | state_dict[new_key] = state_dict[key] 213 | del state_dict[key] 214 | model.load_state_dict(state_dict) 215 | 216 | 217 | def _densenet(arch, growth_rate, block_config, num_init_features, pretrained, progress, 218 | **kwargs): 219 | model = DenseNet(growth_rate, block_config, num_init_features, **kwargs) 220 | if pretrained: 221 | _load_state_dict(model, model_urls[arch], progress) 222 | return model 223 | 224 | 225 | def densenet121(pretrained=False, progress=True, **kwargs): 226 | r"""Densenet-121 model from 227 | `"Densely Connected Convolutional Networks" `_ 228 | 229 | Args: 230 | pretrained (bool): If True, returns a model pre-trained on ImageNet 231 | progress (bool): If True, displays a progress bar of the download to stderr 232 | memory_efficient (bool) - If True, uses checkpointing. Much more memory efficient, 233 | but slower. Default: *False*. See `"paper" `_ 234 | """ 235 | return _densenet('densenet121', 32, (6, 12, 24, 16), 64, pretrained, progress, 236 | **kwargs) 237 | 238 | 239 | def densenet161(pretrained=False, progress=True, **kwargs): 240 | r"""Densenet-161 model from 241 | `"Densely Connected Convolutional Networks" `_ 242 | 243 | Args: 244 | pretrained (bool): If True, returns a model pre-trained on ImageNet 245 | progress (bool): If True, displays a progress bar of the download to stderr 246 | memory_efficient (bool) - If True, uses checkpointing. Much more memory efficient, 247 | but slower. Default: *False*. See `"paper" `_ 248 | """ 249 | return _densenet('densenet161', 48, (6, 12, 36, 24), 96, pretrained, progress, 250 | **kwargs) 251 | 252 | 253 | def densenet169(pretrained=False, progress=True, **kwargs): 254 | r"""Densenet-169 model from 255 | `"Densely Connected Convolutional Networks" `_ 256 | 257 | Args: 258 | pretrained (bool): If True, returns a model pre-trained on ImageNet 259 | progress (bool): If True, displays a progress bar of the download to stderr 260 | memory_efficient (bool) - If True, uses checkpointing. Much more memory efficient, 261 | but slower. Default: *False*. See `"paper" `_ 262 | """ 263 | return _densenet('densenet169', 32, (6, 12, 32, 32), 64, pretrained, progress, 264 | **kwargs) 265 | 266 | 267 | def densenet201(pretrained=False, progress=True, **kwargs): 268 | r"""Densenet-201 model from 269 | `"Densely Connected Convolutional Networks" `_ 270 | 271 | Args: 272 | pretrained (bool): If True, returns a model pre-trained on ImageNet 273 | progress (bool): If True, displays a progress bar of the download to stderr 274 | memory_efficient (bool) - If True, uses checkpointing. Much more memory efficient, 275 | but slower. Default: *False*. See `"paper" `_ 276 | """ 277 | return _densenet('densenet201', 32, (6, 12, 48, 32), 64, pretrained, progress, 278 | **kwargs) -------------------------------------------------------------------------------- /data/augmented_data/train/train.csv: -------------------------------------------------------------------------------- 1 | file_id,label 2 | 12_3_3,3 3 | 19_8_2,8 4 | 12_1_3,1 5 | 7_4_1,4 6 | 7_0_0,0 7 | 19_4_0,4 8 | 9_8_2,8 9 | 16_5_0,5 10 | 3_7_0,7 11 | 8_9_1,9 12 | 14_5_2,5 13 | 10_6_1,6 14 | 17_0_0,0 15 | 8_4_3,4 16 | 8_2_1,2 17 | 14_7_3,7 18 | 13_1_3,1 19 | 3_8_0,8 20 | 25_0_0,0 21 | 12_1_2,1 22 | 14_4_0,4 23 | 6_6_2,6 24 | 18_7_3,7 25 | 20_5_0,5 26 | 7_6_0,6 27 | 18_1_1,1 28 | 11_1_3,1 29 | 16_0_2,0 30 | 13_2_0,2 31 | 15_3_1,3 32 | 8_4_0,4 33 | 15_2_0,2 34 | 4_2_2,2 35 | 6_6_3,6 36 | 24_6_0,6 37 | 2_1_0,1 38 | 22_5_0,5 39 | 6_1_2,1 40 | 19_1_0,1 41 | 22_1_3,1 42 | 7_3_2,3 43 | 10_1_1,1 44 | 7_0_3,0 45 | 2_7_3,7 46 | 22_8_3,8 47 | 7_6_3,6 48 | 22_7_1,7 49 | 16_3_1,3 50 | 3_5_3,5 51 | 13_5_1,5 52 | 5_6_0,6 53 | 22_3_2,3 54 | 18_3_3,3 55 | 25_4_3,4 56 | 23_6_3,6 57 | 2_8_2,8 58 | 16_8_1,8 59 | 22_4_0,4 60 | 7_3_0,3 61 | 8_0_0,0 62 | 12_7_2,7 63 | 13_6_2,6 64 | 19_3_1,3 65 | 4_6_2,6 66 | 13_9_3,9 67 | 16_6_2,6 68 | 13_3_0,3 69 | 14_0_3,0 70 | 25_9_2,9 71 | 19_3_3,3 72 | 1_0_2,0 73 | 5_2_2,2 74 | 4_0_3,0 75 | 12_5_0,5 76 | 11_6_2,6 77 | 16_0_0,0 78 | 15_1_3,1 79 | 8_2_3,2 80 | 24_6_2,6 81 | 9_4_0,4 82 | 23_1_0,1 83 | 1_7_3,7 84 | 7_9_0,9 85 | 17_2_2,2 86 | 17_0_3,0 87 | 14_2_3,2 88 | 25_9_0,9 89 | 12_7_1,7 90 | 7_7_0,7 91 | 5_7_1,7 92 | 3_9_0,9 93 | 13_9_1,9 94 | 25_3_1,3 95 | 10_9_1,9 96 | 19_1_2,1 97 | 23_9_2,9 98 | 13_7_2,7 99 | 21_1_1,1 100 | 14_7_0,7 101 | 13_9_0,9 102 | 17_6_1,6 103 | 10_1_0,1 104 | 10_4_3,4 105 | 18_5_1,5 106 | 1_3_0,3 107 | 7_7_2,7 108 | 7_6_2,6 109 | 1_1_1,1 110 | 2_6_2,6 111 | 8_3_0,3 112 | 23_6_1,6 113 | 25_9_1,9 114 | 11_8_3,8 115 | 20_6_2,6 116 | 15_9_2,9 117 | 5_5_2,5 118 | 23_7_0,7 119 | 20_3_3,3 120 | 23_7_2,7 121 | 21_5_3,5 122 | 20_8_0,8 123 | 1_2_0,2 124 | 18_5_2,5 125 | 20_1_2,1 126 | 2_3_1,3 127 | 14_1_3,1 128 | 4_8_3,8 129 | 20_1_1,1 130 | 22_6_1,6 131 | 14_3_2,3 132 | 16_8_0,8 133 | 23_2_2,2 134 | 21_5_0,5 135 | 14_0_1,0 136 | 24_7_3,7 137 | 16_2_2,2 138 | 20_7_3,7 139 | 3_1_1,1 140 | 18_2_2,2 141 | 9_5_1,5 142 | 6_9_0,9 143 | 25_5_1,5 144 | 15_9_0,9 145 | 5_0_1,0 146 | 15_2_1,2 147 | 5_8_3,8 148 | 17_8_1,8 149 | 24_0_3,0 150 | 16_1_3,1 151 | 13_7_3,7 152 | 24_1_0,1 153 | 24_9_3,9 154 | 5_3_0,3 155 | 7_4_0,4 156 | 19_1_3,1 157 | 20_2_1,2 158 | 23_0_3,0 159 | 13_1_0,1 160 | 10_0_0,0 161 | 2_8_1,8 162 | 13_8_2,8 163 | 1_0_3,0 164 | 14_1_2,1 165 | 13_2_3,2 166 | 24_2_1,2 167 | 1_2_3,2 168 | 7_8_3,8 169 | 9_2_3,2 170 | 7_9_2,9 171 | 24_4_2,4 172 | 7_5_3,5 173 | 23_4_2,4 174 | 1_9_3,9 175 | 3_3_0,3 176 | 14_1_0,1 177 | 21_7_0,7 178 | 11_5_1,5 179 | 9_8_1,8 180 | 8_9_0,9 181 | 17_0_1,0 182 | 2_7_1,7 183 | 24_3_0,3 184 | 1_6_2,6 185 | 9_1_1,1 186 | 21_6_0,6 187 | 17_4_3,4 188 | 22_0_0,0 189 | 10_2_0,2 190 | 18_5_3,5 191 | 9_1_3,1 192 | 23_5_3,5 193 | 21_2_2,2 194 | 20_9_2,9 195 | 6_7_2,7 196 | 15_4_3,4 197 | 11_7_3,7 198 | 10_7_0,7 199 | 5_6_1,6 200 | 3_9_2,9 201 | 12_2_3,2 202 | 12_8_2,8 203 | 17_4_2,4 204 | 22_2_2,2 205 | 16_5_1,5 206 | 4_4_3,4 207 | 8_2_0,2 208 | 7_6_1,6 209 | 24_7_0,7 210 | 10_7_3,7 211 | 15_2_2,2 212 | 11_5_0,5 213 | 13_6_1,6 214 | 12_2_1,2 215 | 14_8_0,8 216 | 15_1_2,1 217 | 6_0_2,0 218 | 11_3_0,3 219 | 10_4_1,4 220 | 22_4_1,4 221 | 6_4_2,4 222 | 21_3_0,3 223 | 24_5_2,5 224 | 25_2_1,2 225 | 19_2_1,2 226 | 4_5_2,5 227 | 24_9_0,9 228 | 10_4_2,4 229 | 5_8_0,8 230 | 23_4_3,4 231 | 17_8_3,8 232 | 9_3_0,3 233 | 24_4_3,4 234 | 14_9_1,9 235 | 23_8_3,8 236 | 4_9_0,9 237 | 23_6_0,6 238 | 5_9_2,9 239 | 7_0_2,0 240 | 1_0_0,0 241 | 24_6_1,6 242 | 15_6_0,6 243 | 17_7_3,7 244 | 2_9_3,9 245 | 23_7_1,7 246 | 9_7_1,7 247 | 18_8_2,8 248 | 11_0_3,0 249 | 7_3_3,3 250 | 20_9_1,9 251 | 16_5_2,5 252 | 11_1_2,1 253 | 11_4_1,4 254 | 7_1_2,1 255 | 18_0_2,0 256 | 13_5_2,5 257 | 18_8_3,8 258 | 13_3_3,3 259 | 23_5_2,5 260 | 17_2_0,2 261 | 4_3_0,3 262 | 13_4_2,4 263 | 11_6_0,6 264 | 11_6_3,6 265 | 17_1_2,1 266 | 24_2_2,2 267 | 2_4_0,4 268 | 8_7_1,7 269 | 18_1_2,1 270 | 2_2_1,2 271 | 18_6_3,6 272 | 1_5_0,5 273 | 9_4_2,4 274 | 6_7_0,7 275 | 22_3_0,3 276 | 8_8_3,8 277 | 7_2_3,2 278 | 5_4_3,4 279 | 12_3_1,3 280 | 22_4_2,4 281 | 10_9_2,9 282 | 2_8_0,8 283 | 21_5_2,5 284 | 18_7_0,7 285 | 13_7_0,7 286 | 4_0_2,0 287 | 9_5_3,5 288 | 14_5_0,5 289 | 23_3_0,3 290 | 21_4_3,4 291 | 1_3_3,3 292 | 14_0_2,0 293 | 13_2_1,2 294 | 17_0_2,0 295 | 10_1_3,1 296 | 15_5_1,5 297 | 16_6_3,6 298 | 6_0_1,0 299 | 14_8_2,8 300 | 16_8_2,8 301 | 20_2_0,2 302 | 11_3_1,3 303 | 7_8_2,8 304 | 21_9_1,9 305 | 7_4_3,4 306 | 6_1_3,1 307 | 17_9_3,9 308 | 2_6_3,6 309 | 25_6_1,6 310 | 21_3_1,3 311 | 2_6_0,6 312 | 8_4_1,4 313 | 1_4_0,4 314 | 25_9_3,9 315 | 11_8_2,8 316 | 14_3_0,3 317 | 23_1_3,1 318 | 22_0_2,0 319 | 25_8_1,8 320 | 23_1_2,1 321 | 22_5_1,5 322 | 19_5_0,5 323 | 24_9_1,9 324 | 6_5_3,5 325 | 5_8_2,8 326 | 9_7_2,7 327 | 2_7_2,7 328 | 16_4_1,4 329 | 19_6_1,6 330 | 1_9_2,9 331 | 2_8_3,8 332 | 5_7_2,7 333 | 17_5_2,5 334 | 3_4_0,4 335 | 9_0_2,0 336 | 3_0_3,0 337 | 20_7_0,7 338 | 2_3_0,3 339 | 12_5_3,5 340 | 9_2_1,2 341 | 5_7_0,7 342 | 12_6_3,6 343 | 21_0_1,0 344 | 6_9_1,9 345 | 14_6_3,6 346 | 10_3_2,3 347 | 8_1_3,1 348 | 3_9_3,9 349 | 5_3_1,3 350 | 4_7_3,7 351 | 24_7_1,7 352 | 25_4_1,4 353 | 18_9_1,9 354 | 5_0_3,0 355 | 15_6_2,6 356 | 8_5_2,5 357 | 1_8_2,8 358 | 22_1_2,1 359 | 15_6_1,6 360 | 6_8_3,8 361 | 17_3_3,3 362 | 4_2_1,2 363 | 17_1_1,1 364 | 25_3_3,3 365 | 20_1_0,1 366 | 4_4_1,4 367 | 14_4_2,4 368 | 4_6_3,6 369 | 5_1_1,1 370 | 24_0_1,0 371 | 13_7_1,7 372 | 14_4_1,4 373 | 24_5_1,5 374 | 21_8_0,8 375 | 22_6_0,6 376 | 18_4_3,4 377 | 10_3_1,3 378 | 9_7_3,7 379 | 19_2_0,2 380 | 2_5_3,5 381 | 8_1_0,1 382 | 15_8_2,8 383 | 1_5_2,5 384 | 10_1_2,1 385 | 11_2_2,2 386 | 12_9_2,9 387 | 5_6_3,6 388 | 7_8_0,8 389 | 19_6_2,6 390 | 20_8_2,8 391 | 20_7_2,7 392 | 20_6_1,6 393 | 16_9_1,9 394 | 17_8_0,8 395 | 16_0_3,0 396 | 9_1_2,1 397 | 1_6_0,6 398 | 23_5_1,5 399 | 25_8_0,8 400 | 19_7_3,7 401 | 13_4_1,4 402 | 13_3_1,3 403 | 23_3_1,3 404 | 19_2_3,2 405 | 7_2_2,2 406 | 13_9_2,9 407 | 25_5_2,5 408 | 14_6_2,6 409 | 16_4_2,4 410 | 2_9_2,9 411 | 13_6_3,6 412 | 5_0_2,0 413 | 2_1_3,1 414 | 10_2_2,2 415 | 6_5_1,5 416 | 17_3_1,3 417 | 1_1_2,1 418 | 1_5_1,5 419 | 15_5_0,5 420 | 24_4_0,4 421 | 4_2_0,2 422 | 22_3_1,3 423 | 3_5_0,5 424 | 23_0_0,0 425 | 15_1_1,1 426 | 6_8_0,8 427 | 2_0_3,0 428 | 10_2_1,2 429 | 17_6_3,6 430 | 9_0_3,0 431 | 7_1_3,1 432 | 19_3_2,3 433 | 19_9_2,9 434 | 14_3_3,3 435 | 2_5_1,5 436 | 16_1_0,1 437 | 11_2_0,2 438 | 5_4_2,4 439 | 24_5_0,5 440 | 9_0_1,0 441 | 14_9_3,9 442 | 5_1_3,1 443 | 6_6_0,6 444 | 11_7_2,7 445 | 12_3_0,3 446 | 10_5_3,5 447 | 17_3_2,3 448 | 24_8_2,8 449 | 13_5_3,5 450 | 4_6_0,6 451 | 7_8_1,8 452 | 12_2_2,2 453 | 1_8_0,8 454 | 3_5_2,5 455 | 4_7_1,7 456 | 21_0_0,0 457 | 25_6_0,6 458 | 2_2_2,2 459 | 15_0_3,0 460 | 21_7_2,7 461 | 10_7_1,7 462 | 4_9_2,9 463 | 24_3_2,3 464 | 18_8_1,8 465 | 6_4_3,4 466 | 23_9_0,9 467 | 20_9_0,9 468 | 2_1_1,1 469 | 2_0_2,0 470 | 11_9_0,9 471 | 10_6_0,6 472 | 4_9_1,9 473 | 3_4_1,4 474 | 15_8_0,8 475 | 15_3_0,3 476 | 22_2_3,2 477 | 4_6_1,6 478 | 10_0_3,0 479 | 9_9_2,9 480 | 16_6_0,6 481 | 16_2_3,2 482 | 8_5_0,5 483 | 21_2_3,2 484 | 10_8_1,8 485 | 23_1_1,1 486 | 5_5_0,5 487 | 9_3_1,3 488 | 11_6_1,6 489 | 21_3_3,3 490 | 15_4_2,4 491 | 25_1_0,1 492 | 3_1_2,1 493 | 8_3_3,3 494 | 15_0_0,0 495 | 22_7_3,7 496 | 21_0_3,0 497 | 21_7_3,7 498 | 6_4_1,4 499 | 21_7_1,7 500 | 11_7_1,7 501 | 17_4_0,4 502 | 9_7_0,7 503 | 17_4_1,4 504 | 11_1_1,1 505 | 25_4_0,4 506 | 24_3_3,3 507 | 12_0_3,0 508 | 20_4_2,4 509 | 5_9_3,9 510 | 24_1_1,1 511 | 25_7_0,7 512 | 11_0_0,0 513 | 9_2_2,2 514 | 4_8_0,8 515 | 18_0_0,0 516 | 4_7_2,7 517 | 8_6_1,6 518 | 16_4_0,4 519 | 16_7_3,7 520 | 25_3_2,3 521 | 6_4_0,4 522 | 14_1_1,1 523 | 16_7_1,7 524 | 1_6_1,6 525 | 4_5_0,5 526 | 3_7_2,7 527 | 23_2_1,2 528 | 7_2_1,2 529 | 7_2_0,2 530 | 11_1_0,1 531 | 22_5_2,5 532 | 7_4_2,4 533 | 5_2_0,2 534 | 13_8_0,8 535 | 23_3_3,3 536 | 21_4_0,4 537 | 23_2_0,2 538 | 12_1_0,1 539 | 15_4_1,4 540 | 12_4_0,4 541 | 9_6_1,6 542 | 9_5_0,5 543 | 13_8_1,8 544 | 13_8_3,8 545 | 10_3_3,3 546 | 22_2_1,2 547 | 15_6_3,6 548 | 8_1_1,1 549 | 3_0_0,0 550 | 20_7_1,7 551 | 21_6_1,6 552 | 3_3_2,3 553 | 20_4_3,4 554 | 7_5_2,5 555 | 6_9_3,9 556 | 11_9_2,9 557 | 14_2_0,2 558 | 19_0_0,0 559 | 18_4_0,4 560 | 23_8_2,8 561 | 8_9_3,9 562 | 3_6_2,6 563 | 8_2_2,2 564 | 5_9_0,9 565 | 17_6_2,6 566 | 17_9_2,9 567 | 10_5_0,5 568 | 24_6_3,6 569 | 3_2_3,2 570 | 13_3_2,3 571 | 3_5_1,5 572 | 19_7_2,7 573 | 8_5_1,5 574 | 10_0_2,0 575 | 13_4_0,4 576 | 25_0_1,0 577 | 9_8_3,8 578 | 12_1_1,1 579 | 12_6_2,6 580 | 11_3_3,3 581 | 10_6_3,6 582 | 13_0_1,0 583 | 13_0_3,0 584 | 3_3_1,3 585 | 6_3_1,3 586 | 1_4_2,4 587 | 17_1_3,1 588 | 12_2_0,2 589 | 9_3_3,3 590 | 4_1_1,1 591 | 11_2_3,2 592 | 5_3_3,3 593 | 1_8_1,8 594 | 17_1_0,1 595 | 24_1_3,1 596 | 18_3_1,3 597 | 12_9_3,9 598 | 24_0_0,0 599 | 18_9_2,9 600 | 6_3_3,3 601 | 24_7_2,7 602 | 1_6_3,6 603 | 22_2_0,2 604 | 21_2_1,2 605 | 10_4_0,4 606 | 16_4_3,4 607 | 13_5_0,5 608 | 2_7_0,7 609 | 20_5_2,5 610 | 3_0_1,0 611 | 22_8_0,8 612 | 21_8_2,8 613 | 17_7_0,7 614 | 19_8_3,8 615 | 10_2_3,2 616 | 22_5_3,5 617 | 17_8_2,8 618 | 20_3_2,3 619 | 25_5_0,5 620 | 4_1_3,1 621 | 14_9_0,9 622 | 3_2_2,2 623 | 7_5_1,5 624 | 15_2_3,2 625 | 14_0_0,0 626 | 19_4_1,4 627 | 2_5_2,5 628 | 15_8_1,8 629 | 1_5_3,5 630 | 8_4_2,4 631 | 12_9_1,9 632 | 24_8_3,8 633 | 19_7_0,7 634 | 9_0_0,0 635 | 16_1_1,1 636 | 25_7_1,7 637 | 20_0_1,0 638 | 8_0_1,0 639 | 16_9_0,9 640 | 20_4_1,4 641 | 4_8_2,8 642 | 6_9_2,9 643 | 10_3_0,3 644 | 6_8_1,8 645 | 3_6_3,6 646 | 20_2_3,2 647 | 5_9_1,9 648 | 18_2_1,2 649 | 2_5_0,5 650 | 15_7_0,7 651 | 22_9_1,9 652 | 2_9_1,9 653 | 5_0_0,0 654 | 7_9_3,9 655 | 11_5_3,5 656 | 21_9_2,9 657 | 20_5_1,5 658 | 23_7_3,7 659 | 11_0_2,0 660 | 4_4_0,4 661 | 18_6_2,6 662 | 1_1_3,1 663 | 10_8_3,8 664 | 11_8_0,8 665 | 13_4_3,4 666 | 17_9_0,9 667 | 22_9_3,9 668 | 17_5_0,5 669 | 8_3_2,3 670 | 8_7_0,7 671 | 20_8_1,8 672 | 11_9_1,9 673 | 15_7_3,7 674 | 12_5_1,5 675 | 1_7_2,7 676 | 18_6_0,6 677 | 25_2_0,2 678 | 18_9_3,9 679 | 8_0_2,0 680 | 19_0_3,0 681 | 16_9_3,9 682 | 20_6_0,6 683 | 21_1_3,1 684 | 16_1_2,1 685 | 16_7_0,7 686 | 5_4_0,4 687 | 6_7_1,7 688 | 9_4_1,4 689 | 25_8_3,8 690 | 13_2_2,2 691 | 20_0_3,0 692 | 23_4_1,4 693 | 6_2_2,2 694 | 3_3_3,3 695 | 21_9_3,9 696 | 11_5_2,5 697 | 5_5_1,5 698 | 11_3_2,3 699 | 15_9_3,9 700 | 25_7_2,7 701 | 22_0_3,0 702 | 22_0_1,0 703 | 8_6_3,6 704 | 17_9_1,9 705 | 22_3_3,3 706 | 8_5_3,5 707 | 5_2_3,2 708 | 12_6_1,6 709 | 3_0_2,0 710 | 12_4_2,4 711 | 5_2_1,2 712 | 9_1_0,1 713 | 19_8_0,8 714 | 11_4_2,4 715 | 2_2_0,2 716 | 16_3_2,3 717 | 22_4_3,4 718 | 9_3_2,3 719 | 8_9_2,9 720 | 3_2_0,2 721 | 13_6_0,6 722 | 19_3_0,3 723 | 17_6_0,6 724 | 2_3_2,3 725 | 7_1_0,1 726 | 20_3_0,3 727 | 4_3_3,3 728 | 25_1_3,1 729 | 23_0_1,0 730 | 9_6_0,6 731 | 5_7_3,7 732 | 19_6_3,6 733 | 9_2_0,2 734 | 25_1_2,1 735 | 1_7_0,7 736 | 3_4_2,4 737 | 12_0_1,0 738 | 5_1_0,1 739 | 2_2_3,2 740 | 21_9_0,9 741 | 24_1_2,1 742 | 25_6_3,6 743 | 20_6_3,6 744 | 18_8_0,8 745 | 9_9_1,9 746 | 24_8_1,8 747 | 19_6_0,6 748 | 4_3_1,3 749 | 1_9_0,9 750 | 15_9_1,9 751 | 22_9_0,9 752 | 12_6_0,6 753 | 15_0_2,0 754 | 16_2_1,2 755 | 23_3_2,3 756 | 25_0_3,0 757 | 14_6_1,6 758 | 17_7_1,7 759 | 15_7_2,7 760 | 3_6_1,6 761 | 24_2_0,2 762 | 19_8_1,8 763 | 22_1_1,1 764 | 11_2_1,2 765 | 8_6_2,6 766 | 8_6_0,6 767 | 24_4_1,4 768 | 11_7_0,7 769 | 6_1_1,1 770 | 1_0_1,0 771 | 17_2_3,2 772 | 1_9_1,9 773 | 21_1_0,1 774 | 3_4_3,4 775 | 8_3_1,3 776 | 19_4_2,4 777 | 4_3_2,3 778 | 6_2_3,2 779 | 14_5_1,5 780 | 6_0_3,0 781 | 24_8_0,8 782 | 1_3_2,3 783 | 22_8_1,8 784 | 7_0_1,0 785 | 16_8_3,8 786 | 1_2_1,2 787 | 21_5_1,5 788 | 16_0_1,0 789 | 21_4_2,4 790 | 11_9_3,9 791 | 1_8_3,8 792 | 10_5_1,5 793 | 4_4_2,4 794 | 20_9_3,9 795 | 8_0_3,0 796 | 15_1_0,1 797 | 20_2_2,2 798 | 20_1_3,1 799 | 7_9_1,9 800 | 7_3_1,3 801 | 16_7_2,7 802 | 11_0_1,0 803 | 23_5_0,5 804 | 8_1_2,1 805 | 13_1_1,1 806 | 23_6_2,6 807 | 18_2_3,2 808 | 12_5_2,5 809 | 14_7_2,7 810 | 19_0_1,0 811 | 25_2_3,2 812 | 11_8_1,8 813 | 10_5_2,5 814 | 12_7_3,7 815 | 12_7_0,7 816 | 21_0_2,0 817 | 4_0_1,0 818 | 14_4_3,4 819 | 10_0_1,0 820 | 24_2_3,2 821 | 18_3_2,3 822 | 4_9_3,9 823 | 3_1_0,1 824 | 6_8_2,8 825 | 25_1_1,1 826 | 22_6_2,6 827 | 20_0_2,0 828 | 21_8_1,8 829 | 19_1_1,1 830 | 2_0_0,0 831 | 10_8_2,8 832 | 19_0_2,0 833 | 2_1_2,1 834 | 6_3_0,3 835 | 14_7_1,7 836 | 14_3_1,3 837 | 17_5_1,5 838 | 24_0_2,0 839 | 1_2_2,2 840 | 6_2_1,2 841 | 8_8_0,8 842 | 9_9_0,9 843 | 10_9_3,9 844 | 3_8_3,8 845 | 5_3_2,3 846 | 6_6_1,6 847 | 25_2_2,2 848 | 16_3_0,3 849 | 20_4_0,4 850 | 24_5_3,5 851 | 12_8_0,8 852 | 9_6_2,6 853 | 15_4_0,4 854 | 13_1_2,1 855 | 4_8_1,8 856 | 12_0_2,0 857 | 15_0_1,0 858 | 19_5_2,5 859 | 5_6_2,6 860 | 20_5_3,5 861 | 8_8_2,8 862 | 17_7_2,7 863 | 15_3_2,3 864 | 6_5_2,5 865 | 18_4_1,4 866 | 19_2_2,2 867 | 15_3_3,3 868 | 3_9_1,9 869 | 8_7_2,7 870 | 24_3_1,3 871 | 19_5_1,5 872 | 18_2_0,2 873 | 1_7_1,7 874 | 22_9_2,9 875 | 2_6_1,6 876 | 1_1_0,1 877 | 25_8_2,8 878 | 23_4_0,4 879 | 9_6_3,6 880 | 18_0_3,0 881 | 23_0_2,0 882 | 4_1_2,1 883 | 23_8_1,8 884 | 18_7_1,7 885 | 20_8_3,8 886 | 21_3_2,3 887 | 16_5_3,5 888 | 4_2_3,2 889 | 13_0_0,0 890 | 14_9_2,9 891 | 10_9_0,9 892 | 18_3_0,3 893 | 18_6_1,6 894 | 2_3_3,3 895 | 16_6_1,6 896 | 2_9_0,9 897 | 5_5_3,5 898 | 7_5_0,5 899 | 3_8_1,8 900 | 17_5_3,5 901 | 22_7_0,7 902 | 21_1_2,1 903 | 3_1_3,1 904 | 19_4_3,4 905 | 17_3_0,3 906 | 15_7_1,7 907 | 6_3_2,3 908 | 25_3_0,3 909 | 25_0_2,0 910 | 15_8_3,8 911 | 12_8_3,8 912 | 18_1_0,1 913 | 19_9_3,9 914 | 6_1_0,1 915 | 19_9_0,9 916 | 14_2_1,2 917 | 1_3_1,3 918 | 3_2_1,2 919 | 20_0_0,0 920 | 8_8_1,8 921 | 21_8_3,8 922 | 15_5_2,5 923 | 3_7_1,7 924 | 16_9_2,9 925 | 15_5_3,5 926 | 5_1_2,1 927 | 4_1_0,1 928 | 5_8_1,8 929 | 6_7_3,7 930 | 10_6_2,6 931 | 24_9_2,9 932 | 18_7_2,7 933 | 1_4_1,4 934 | 21_6_3,6 935 | 3_8_2,8 936 | 4_5_3,5 937 | 9_4_3,4 938 | 25_5_3,5 939 | 1_4_3,4 940 | 19_9_1,9 941 | 17_2_1,2 942 | 14_6_0,6 943 | 4_0_0,0 944 | 12_4_1,4 945 | 12_0_0,0 946 | 2_0_1,0 947 | 4_5_1,5 948 | 3_7_3,7 949 | 9_5_2,5 950 | 7_7_3,7 951 | 2_4_1,4 952 | 25_7_3,7 953 | 18_0_1,0 954 | 14_2_2,2 955 | 16_3_3,3 956 | 11_4_0,4 957 | 6_0_0,0 958 | 9_9_3,9 959 | 3_6_0,6 960 | 22_7_2,7 961 | 25_6_2,6 962 | 4_7_0,7 963 | 21_2_0,2 964 | 22_6_3,6 965 | 18_9_0,9 966 | 12_9_0,9 967 | 6_2_0,2 968 | 12_8_1,8 969 | 23_2_3,2 970 | 19_7_1,7 971 | 16_2_0,2 972 | 23_8_0,8 973 | 8_7_3,7 974 | 21_6_2,6 975 | 10_8_0,8 976 | 2_4_3,4 977 | 13_0_2,0 978 | 14_5_3,5 979 | 23_9_3,9 980 | 18_4_2,4 981 | 12_3_2,3 982 | 10_7_2,7 983 | 19_5_3,5 984 | 20_3_1,3 985 | 18_1_3,1 986 | 21_4_1,4 987 | 6_5_0,5 988 | 7_1_1,1 989 | 22_1_0,1 990 | 12_4_3,4 991 | 7_7_1,7 992 | 14_8_3,8 993 | 11_4_3,4 994 | 23_9_1,9 995 | 22_8_2,8 996 | 9_8_0,8 997 | 5_4_1,4 998 | 2_4_2,4 999 | 14_8_1,8 1000 | 18_5_0,5 1001 | 25_4_2,4 1002 | --------------------------------------------------------------------------------