├── 01_train_2025t2.sh ├── 02a_test_2025t2.sh ├── 02b_test_2025t2.sh ├── 03_summarize_results.sh ├── LISENCEv2.1.pdf ├── README.md ├── README_legacy.md ├── baseline.yaml ├── common.py ├── data ├── dcase2020t2 │ ├── dev_data │ │ ├── processed │ │ │ └── .gitignore │ │ └── raw │ │ │ └── .gitignore │ └── eval_data │ │ ├── processed │ │ └── .gitignore │ │ └── raw │ │ └── .gitignore ├── dcase2021t2 │ ├── dev_data │ │ ├── processed │ │ │ └── .gitignore │ │ └── raw │ │ │ └── .gitignore │ └── eval_data │ │ ├── processed │ │ └── .gitignore │ │ └── raw │ │ └── .gitignore ├── dcase2022t2 │ ├── dev_data │ │ ├── processed │ │ │ └── .gitignore │ │ └── raw │ │ │ └── .gitignore │ └── eval_data │ │ ├── processed │ │ └── .gitignore │ │ └── raw │ │ └── .gitignore ├── dcase2023t2 │ ├── dev_data │ │ ├── processed │ │ │ └── .gitignore │ │ └── raw │ │ │ └── .gitignore │ └── eval_data │ │ ├── processed │ │ └── .gitignore │ │ └── raw │ │ └── .gitignore ├── dcase2024t2 │ ├── dev_data │ │ ├── processed │ │ │ └── .gitignore │ │ └── raw │ │ │ └── .gitignore │ └── eval_data │ │ ├── processed │ │ └── .gitignore │ │ └── raw │ │ └── .gitignore └── dcase2025t2 │ ├── dev_data │ ├── processed │ │ └── .gitignore │ └── raw │ │ └── .gitignore │ └── eval_data │ ├── processed │ └── .gitignore │ └── raw │ └── .gitignore ├── data_download_2025add.sh ├── data_download_2025dev.sh ├── data_download_2025eval.sh ├── datasets ├── datasets.py ├── dcase_dcase202x_t2_loader.py ├── download_path_2023.yaml ├── download_path_2024.yaml ├── download_path_2025.yaml ├── download_path_legacy.yaml ├── eval_data_list_2020.csv ├── eval_data_list_2021.csv ├── eval_data_list_2022.csv ├── eval_data_list_2023.csv ├── eval_data_list_2024.csv ├── ground_truth_attributes │ └── dcase2024t2 │ │ ├── dev_data │ │ ├── ToyTrain │ │ │ ├── attributes_00_test_correspondence.csv │ │ │ └── attributes_00_train_correspondence.csv │ │ ├── gearbox │ │ │ ├── attributes_00_test_correspondence.csv │ │ │ └── attributes_00_train_correspondence.csv │ │ └── slider │ │ │ ├── attributes_00_test_correspondence.csv │ │ │ └── attributes_00_train_correspondence.csv │ │ └── eval_data │ │ ├── AirCompressor │ │ ├── attributes_00_test_correspondence.csv │ │ └── attributes_00_train_correspondence.csv │ │ ├── BrushlessMotor │ │ └── attributes_00_train_correspondence.csv │ │ ├── HoveringDrone │ │ ├── attributes_00_test_correspondence.csv │ │ └── attributes_00_train_correspondence.csv │ │ └── ToothBrush │ │ ├── attributes_00_test_correspondence.csv │ │ └── attributes_00_train_correspondence.csv ├── loader_common.py ├── machine_type_2023_dev.yaml ├── machine_type_2023_eval.yaml ├── machine_type_2024_dev.yaml ├── machine_type_2024_eval.yaml ├── machine_type_2025_dev.yaml ├── machine_type_2025_eval.yaml └── machine_type_legacy.yaml ├── dockerfile ├── logs └── .gitignore ├── models ├── checkpoint │ └── .gitignore └── saved_model │ └── .gitignore ├── networks ├── base_model.py ├── criterion │ └── mahala.py ├── dcase2023t2_ae │ ├── dcase2023t2_ae.py │ └── network.py └── models.py ├── requirements.txt ├── results ├── dev_data │ └── .gitignore └── eval_data │ └── .gitignore ├── test_ae.sh ├── tools ├── 01_train_legacy.sh ├── 02a_test_legacy.sh ├── 02b_test_legacy.sh ├── README.md ├── concat_divided_roc.py ├── data_download_2020.sh ├── data_download_2021.sh ├── data_download_2022.sh ├── data_download_2023.sh ├── data_download_2024.sh ├── export_results.py ├── export_results.sh ├── extract_results.py ├── plot_anm_score.py ├── plot_common.py ├── plot_loss_curve.py ├── plot_time_frequency.py └── rename_eval_wav.py ├── train.py └── train_ae.sh /01_train_2025t2.sh: -------------------------------------------------------------------------------- 1 | TZ=JST-9 date 2 | 3 | echo $0 $* 4 | 5 | dev_eval=$1 6 | echo -e "\tdev_eval = '$dev_eval'" 7 | echo 8 | 9 | # check args 10 | if [ "${dev_eval}" != "-d" ] \ 11 | && [ "${dev_eval}" != "-e" ] \ 12 | && [ "${dev_eval}" != "--dev" ] \ 13 | && [ "${dev_eval}" != "--eval" ] 14 | then 15 | echo "$0: argument error" 16 | echo -e "usage\t: $0 ['-d' | '--dev' | '-e' | '--eval']" 17 | echo -e "\tinvalid choice '$dev_eval'" 18 | echo -e "\tchoice from ['-d' | '--dev' | '-e' | '--eval']." 19 | echo -e "\t\t-d, --dev\t: Using Development dataset. " 20 | echo -e "\t\t-e, --eval\t: Using Additional training dataset and Evaluation dataset. " 21 | echo -e "example\t: $ bash $0 -d" 22 | exit 1 23 | fi 24 | 25 | # main process 26 | base_job="bash" 27 | job="train_ae.sh" 28 | 29 | if [ "${dev_eval}" = "-d" ] || [ "${dev_eval}" = "--dev" ] 30 | then 31 | dataset_list="\ 32 | DCASE2025T2ToyCar \ 33 | DCASE2025T2ToyTrain \ 34 | DCASE2025T2bearing \ 35 | DCASE2025T2fan \ 36 | DCASE2025T2gearbox \ 37 | DCASE2025T2slider \ 38 | DCASE2025T2valve \ 39 | " 40 | elif [ "${dev_eval}" = "-e" ] || [ "${dev_eval}" = "--eval" ] 41 | then 42 | dataset_list="\ 43 | DCASE2025T2ToyRCCar \ 44 | DCASE2025T2ToyPet \ 45 | DCASE2025T2HomeCamera \ 46 | DCASE2025T2AutoTrash \ 47 | DCASE2025T2Polisher \ 48 | DCASE2025T2ScrewFeeder \ 49 | DCASE2025T2BandSealer \ 50 | DCASE2025T2CoffeeGrinder \ 51 | " 52 | fi 53 | 54 | for dataset in $dataset_list; do 55 | ${base_job} ${job} ${dataset} ${dev_eval} 0 56 | done 57 | -------------------------------------------------------------------------------- /02a_test_2025t2.sh: -------------------------------------------------------------------------------- 1 | TZ=JST-9 date 2 | 3 | echo $0 $* 4 | 5 | dev_eval=$1 6 | echo -e "\tdev_eval = '$dev_eval'" 7 | echo 8 | 9 | # check args 10 | if [ "${dev_eval}" != "-d" ] \ 11 | && [ "${dev_eval}" != "-e" ] \ 12 | && [ "${dev_eval}" != "--dev" ] \ 13 | && [ "${dev_eval}" != "--eval" ] 14 | then 15 | echo "$0: argument error" 16 | echo -e "usage\t: $0 ['-d' | '--dev' | '-e' | '--eval']" 17 | echo -e "\tinvalid choice '$dev_eval'" 18 | echo -e "\tchoice from ['-d' | '--dev' | '-e' | '--eval']." 19 | echo -e "\t\t-d, --dev\t: Using Development dataset. " 20 | echo -e "\t\t-e, --eval\t: Using Additional training dataset and Evaluation dataset. " 21 | echo -e "example\t: $ bash $0 -d" 22 | exit 1 23 | fi 24 | 25 | # main process 26 | base_job="bash" 27 | job="test_ae.sh" 28 | 29 | if [ "${dev_eval}" = "-d" ] || [ "${dev_eval}" = "--dev" ] 30 | then 31 | dataset_list="\ 32 | DCASE2025T2ToyCar \ 33 | DCASE2025T2ToyTrain \ 34 | DCASE2025T2bearing \ 35 | DCASE2025T2fan \ 36 | DCASE2025T2gearbox \ 37 | DCASE2025T2slider \ 38 | DCASE2025T2valve \ 39 | " 40 | elif [ "${dev_eval}" = "-e" ] || [ "${dev_eval}" = "--eval" ] 41 | then 42 | dataset_list="\ 43 | DCASE2025T2ToyRCCar \ 44 | DCASE2025T2ToyPet \ 45 | DCASE2025T2HomeCamera \ 46 | DCASE2025T2AutoTrash \ 47 | DCASE2025T2Polisher \ 48 | DCASE2025T2ScrewFeeder \ 49 | DCASE2025T2BandSealer \ 50 | DCASE2025T2CoffeeGrinder \ 51 | " 52 | fi 53 | 54 | for dataset in $dataset_list; do 55 | ${base_job} ${job} ${dataset} ${dev_eval} "MSE" 0 56 | done -------------------------------------------------------------------------------- /02b_test_2025t2.sh: -------------------------------------------------------------------------------- 1 | TZ=JST-9 date 2 | 3 | echo $0 $* 4 | 5 | dev_eval=$1 6 | echo -e "\tdev_eval = '$dev_eval'" 7 | echo 8 | 9 | # check args 10 | if [ "${dev_eval}" != "-d" ] \ 11 | && [ "${dev_eval}" != "-e" ] \ 12 | && [ "${dev_eval}" != "--dev" ] \ 13 | && [ "${dev_eval}" != "--eval" ] 14 | then 15 | echo "$0: argument error" 16 | echo -e "usage\t: $0 ['-d' | '--dev' | '-e' | '--eval']" 17 | echo -e "\tinvalid choice '$dev_eval'" 18 | echo -e "\tchoice from ['-d' | '--dev' | '-e' | '--eval']." 19 | echo -e "\t\t-d, --dev\t: Using Development dataset. " 20 | echo -e "\t\t-e, --eval\t: Using Additional training dataset and Evaluation dataset. " 21 | echo -e "example\t: $ bash $0 -d" 22 | exit 1 23 | fi 24 | 25 | # main process 26 | base_job="bash" 27 | job="test_ae.sh" 28 | 29 | if [ "${dev_eval}" = "-d" ] || [ "${dev_eval}" = "--dev" ] 30 | then 31 | dataset_list="\ 32 | DCASE2025T2ToyCar \ 33 | DCASE2025T2ToyTrain \ 34 | DCASE2025T2bearing \ 35 | DCASE2025T2fan \ 36 | DCASE2025T2gearbox \ 37 | DCASE2025T2slider \ 38 | DCASE2025T2valve \ 39 | " 40 | elif [ "${dev_eval}" = "-e" ] || [ "${dev_eval}" = "--eval" ] 41 | then 42 | dataset_list="\ 43 | DCASE2025T2ToyRCCar \ 44 | DCASE2025T2ToyPet \ 45 | DCASE2025T2HomeCamera \ 46 | DCASE2025T2AutoTrash \ 47 | DCASE2025T2Polisher \ 48 | DCASE2025T2ScrewFeeder \ 49 | DCASE2025T2BandSealer \ 50 | DCASE2025T2CoffeeGrinder \ 51 | " 52 | fi 53 | 54 | for dataset in $dataset_list; do 55 | ${base_job} ${job} ${dataset} ${dev_eval} "MAHALA" 0 56 | done -------------------------------------------------------------------------------- /03_summarize_results.sh: -------------------------------------------------------------------------------- 1 | TZ=JST-9 date 2 | 3 | echo $0 $* 4 | 5 | dataset=$1 6 | dev_eval=$2 7 | echo -e "\tdataset = '$dataset'" 8 | echo -e "\tdev_eval = '$dev_eval'" 9 | echo 10 | 11 | # check args 12 | args_flag=0 13 | args_flag_dataset=0 14 | if [ "${dataset}" != "DCASE2020T2" ] \ 15 | && [ "${dataset}" != "DCASE2021T2" ] \ 16 | && [ "${dataset}" != "DCASE2022T2" ] \ 17 | && [ "${dataset}" != "DCASE2023T2" ] \ 18 | && [ "${dataset}" != "DCASE2024T2" ] \ 19 | && [ "${dataset}" != "DCASE2025T2" ] 20 | then 21 | args_flag=1 22 | args_flag_dataset=1 23 | fi 24 | 25 | args_flag_dev_eval=0 26 | if [ "${dev_eval}" != "-d" ] \ 27 | && [ "${dev_eval}" != "-e" ] \ 28 | && [ "${dev_eval}" != "--dev" ] \ 29 | && [ "${dev_eval}" != "--eval" ] 30 | then 31 | args_flag=1 32 | args_flag_dev_eval=1 33 | fi 34 | 35 | if [ $args_flag -eq 1 ] 36 | then 37 | echo "$0: argument error" 38 | echo -e "usage\t: $0 ['DCASE2020T2' | 'DCASE2021T2' | 'DCASE2022T2' | 'DCASE2023T2' | 'DCASE2024T2' | 'DCASE2025T2' ] ['-d' | '--dev' | '-e' | '--eval']" 39 | 40 | if [ $args_flag_dataset -eq 1 ] 41 | then 42 | echo -e "\tdataset: invalid choice '$dataset'" 43 | echo -e "\tchoice from ['DCASE2020T2' | 'DCASE2021T2' | 'DCASE2022T2' | 'DCASE2023T2' | 'DCASE2024T2' | 'DCASE2025T2' ]." 44 | echo -e "\t\tDCASE2020T2\t: Use DCASE2020 Task2 datasets. " 45 | echo -e "\t\tDCASE2021T2\t: Use DCASE2021 Task2 datasets. " 46 | echo -e "\t\tDCASE2022T2\t: Use DCASE2022 Task2 datasets. " 47 | echo -e "\t\tDCASE2023T2\t: Use DCASE2023 Task2 datasets. " 48 | echo -e "\t\tDCASE2024T2\t: Use DCASE2024 Task2 datasets. " 49 | echo -e "\t\tDCASE2025T2\t: Use DCASE2025 Task2 datasets. " 50 | echo 51 | fi 52 | 53 | if [ $args_flag_dev_eval -eq 1 ] 54 | then 55 | echo -e "\tdev_eval: invalid choice '$dev_eval'" 56 | echo -e "\tchoice from ['-d' | '--dev' | '-e' | '--eval']." 57 | echo -e "\t\t-d, --dev\t: Using Development dataset. " 58 | echo -e "\t\t-e, --eval\t: Using Additional training dataset and Evaluation dataset. " 59 | echo 60 | fi 61 | 62 | echo -e "example\t: $ bash $0 DCASE2020T2 -d" 63 | exit 1 64 | fi 65 | 66 | if [ "${dev_eval}" = "-d" ] \ 67 | || [ "${dev_eval}" = "--dev" ] 68 | then 69 | dev_eval_dir_name="dev_data" 70 | fi 71 | 72 | if [ "${dev_eval}" = "-e" ] \ 73 | || [ "${dev_eval}" = "--eval" ] 74 | then 75 | dev_eval_dir_name="eval_data" 76 | fi 77 | 78 | # parameters 79 | model="DCASE2023T2-AE" 80 | dir_name="summarize" 81 | float_format=None 82 | # float_format="%.4f" 83 | summarize_dir_list=" \ 84 | results/${dev_eval_dir_name}/baseline_MAHALA \ 85 | results/${dev_eval_dir_name}/baseline_MSE \ 86 | " 87 | 88 | # summarize all data 89 | export_dir="results/${dev_eval_dir_name}/baseline/${dir_name}/${dataset}" 90 | echo ${dataset} ${export_dir} ${float_format} ${dev_eval} ${summarize_dir_list} 91 | bash tools/export_results.sh ${dataset} ${export_dir} ${float_format} ${dev_eval} ${summarize_dir_list} 92 | -------------------------------------------------------------------------------- /LISENCEv2.1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nttcslab/dcase2023_task2_baseline_ae/786a8e2e541a0e4970e052429b25e5a2c1939ff0/LISENCEv2.1.pdf -------------------------------------------------------------------------------- /baseline.yaml: -------------------------------------------------------------------------------- 1 | --dataset_directory: ./data 2 | --result_directory: ./results 3 | --export_dir: baseline 4 | 5 | --use_cuda: True 6 | --log_interval: 100 7 | --model: DCASE2023T2-AE 8 | --score: MSE 9 | --seed: 13711 10 | --is_auto_download: False 11 | 12 | --max_fpr: 0.1 13 | --decision_threshold: 0.9 14 | 15 | # feature 16 | --n_mels: 128 17 | --frames: 5 18 | --frame_hop_length: 1 19 | --n_fft: 1024 20 | --hop_length: 512 21 | --power: 2.0 22 | --fmin: 0.0 23 | --fmax: null 24 | --win_length: null 25 | 26 | # fit 27 | --batch_size: 256 28 | --epochs: 100 29 | -lr: 0.001 30 | --shuffle: True 31 | --validation_split: 0.1 32 | -------------------------------------------------------------------------------- /common.py: -------------------------------------------------------------------------------- 1 | import yaml 2 | import itertools 3 | import argparse 4 | 5 | ######################################################################## 6 | # load parameter.yaml 7 | ######################################################################## 8 | def yaml_load(): 9 | with open("baseline.yaml") as stream: 10 | param = yaml.safe_load(stream) 11 | return param 12 | 13 | def param_to_args_list(params): 14 | params = list(itertools.chain.from_iterable(zip(params.keys(), params.values()))) 15 | args_list = [] 16 | for param in params: 17 | if type(param) is list: 18 | args_list.extend([str(p) for p in param]) 19 | else: 20 | args_list.append(str(param)) 21 | return args_list 22 | 23 | ######################################################################## 24 | # argparse setting 25 | ######################################################################## 26 | def str2bool(v): 27 | if v.lower() in ['true', 1]: 28 | return True 29 | elif v.lower() in ['false', 0]: 30 | return False 31 | else: 32 | raise argparse.ArgumentTypeError('Boolean value expected.') 33 | 34 | def float_or_None(v): 35 | if v.lower() in ["none", "null"]: 36 | return None 37 | return float(v) 38 | 39 | def get_argparse(): 40 | parser = argparse.ArgumentParser( 41 | description='Main function to call training for different AutoEncoders') 42 | parser.add_argument('--model', type=str, default='DCASE2023T2-AE', metavar='N', 43 | help='train model name') 44 | parser.add_argument('--score', type=str, default="MSE", choices=["MSE", "MAHALA"]) 45 | parser.add_argument('--seed', type=int, default=39876401, metavar='S', 46 | help='random seed (default: 39876401)') 47 | 48 | parser.add_argument('--use_cuda', type=str2bool, default=True, 49 | help='enables CUDA training') 50 | parser.add_argument('--gpu_id',type=int, nargs='*', default=[0,], 51 | help='Specify GPU id') 52 | parser.add_argument('--log_interval', type=int, default=100, metavar='N', 53 | help='how many batches to wait before logging training status') 54 | 55 | parser.add_argument('--decision_threshold', type=float, default=0.9) 56 | parser.add_argument('--max_fpr', type=float, default=0.1) 57 | 58 | # feature 59 | parser.add_argument('--n_mels',type=int, default=128, 60 | help='Length of the melfilter bank') 61 | parser.add_argument('--frames',type=int, default=5, 62 | help='Number of frames in a feature vector') 63 | parser.add_argument('--frame_hop_length',type=int, default=1, 64 | help='number of frames between successive feature') 65 | parser.add_argument('--n_fft',type=int, default=1024, 66 | help='length of the FFT window') 67 | parser.add_argument('--hop_length',type=int, default=512, 68 | help='number of samples between successive frames') 69 | parser.add_argument('--power', type=float, default=2.0) 70 | parser.add_argument('--fmin', type=float, default=0.0) 71 | parser.add_argument('--fmax', type=float_or_None, default=None) 72 | parser.add_argument('--win_length', type=float_or_None, default=None) 73 | 74 | # fit 75 | parser.add_argument('--batch_size', type=int, default=512, metavar='N', 76 | help='input batch size for training (default: 512)') 77 | parser.add_argument('--epochs', type=int, default=10, metavar='N', 78 | help='number of epochs to train (default: 10)') 79 | parser.add_argument('-lr', '--learning_rate', default=0.03, type=float, 80 | help='learning rate (default: 0.03)') 81 | parser.add_argument('--shuffle', type=str, default="full", 82 | help='shuffle type (full , simple)') 83 | parser.add_argument('--validation_split', type=float, default=0.1) 84 | 85 | # dataset 86 | parser.add_argument('--dataset_directory', type=str, default='data', 87 | help='Where to parent dataset dir') 88 | parser.add_argument('--dataset', type=str, default='DCASE2023T2ToyCar', metavar='N', 89 | help='dataset to use') 90 | parser.add_argument('-d', '--dev', action='store_true', 91 | help='Use Development dataset') 92 | parser.add_argument('-e', '--eval', action='store_true', 93 | help='Use Evaluation dataset') 94 | parser.add_argument('--use_ids', type=int, nargs='*', default=[], 95 | help='Machine ID to be treated as nml data') 96 | parser.add_argument('--is_auto_download', type=str2bool, default=False, 97 | help="Download dataset if not exist") 98 | 99 | # save data 100 | parser.add_argument('--result_directory', type=str, default='results/', metavar='N', 101 | help='Where to store images') 102 | parser.add_argument('--export_dir',type=str, default='', 103 | help='Name of the directory to be generated under the Result directory.') 104 | parser.add_argument('-tag','--model_name_suffix',type=str, default='', 105 | help='Add a word to file name') 106 | 107 | # resume learning 108 | parser.add_argument('--restart',action='store_true', 109 | help='Resume learning with checkpoint') 110 | parser.add_argument('--checkpoint_path', type=str, default="", 111 | help="Using checkpoint file path. default: this checkpoint") 112 | parser.add_argument('--train_only', action='store_true', default=False, 113 | help='Run train only') 114 | parser.add_argument('--test_only', action='store_true', default=False, 115 | help='Run test only') 116 | 117 | return parser -------------------------------------------------------------------------------- /data/dcase2020t2/dev_data/processed/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2020t2/dev_data/raw/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2020t2/eval_data/processed/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2020t2/eval_data/raw/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2021t2/dev_data/processed/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2021t2/dev_data/raw/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2021t2/eval_data/processed/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2021t2/eval_data/raw/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2022t2/dev_data/processed/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2022t2/dev_data/raw/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2022t2/eval_data/processed/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2022t2/eval_data/raw/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2023t2/dev_data/processed/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2023t2/dev_data/raw/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2023t2/eval_data/processed/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2023t2/eval_data/raw/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2024t2/dev_data/processed/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2024t2/dev_data/raw/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2024t2/eval_data/processed/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2024t2/eval_data/raw/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2025t2/dev_data/processed/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2025t2/dev_data/raw/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2025t2/eval_data/processed/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data/dcase2025t2/eval_data/raw/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /data_download_2025add.sh: -------------------------------------------------------------------------------- 1 | mkdir -p "data/dcase2025t2/eval_data/raw" 2 | 3 | # download dev data 4 | cd "data/dcase2025t2/eval_data/raw" 5 | for machine_type in \ 6 | "ToyRCCar" \ 7 | "ToyPet" \ 8 | "HomeCamera" \ 9 | "AutoTrash" \ 10 | "Polisher" \ 11 | "ScrewFeeder" \ 12 | "BandSealer" \ 13 | "CoffeeGrinder" \ 14 | ; do 15 | wget "https://zenodo.org/records/15392814/files/eval_data_${machine_type}_train.zip" 16 | unzip "eval_data_${machine_type}_train.zip" 17 | done 18 | -------------------------------------------------------------------------------- /data_download_2025dev.sh: -------------------------------------------------------------------------------- 1 | mkdir -p "data/dcase2025t2/dev_data/raw" 2 | 3 | # download dev data 4 | cd "data/dcase2025t2/dev_data/raw" 5 | for machine_type in \ 6 | "ToyCar" \ 7 | "ToyTrain" \ 8 | "bearing" \ 9 | "fan" \ 10 | "gearbox" \ 11 | "slider" \ 12 | "valve" \ 13 | ; do 14 | wget "https://zenodo.org/records/15097779/files/dev_${machine_type}.zip" 15 | unzip "dev_${machine_type}.zip" 16 | done 17 | -------------------------------------------------------------------------------- /data_download_2025eval.sh: -------------------------------------------------------------------------------- 1 | mkdir -p "data/dcase2025t2/eval_data/raw" 2 | 3 | # download dev data 4 | cd "data/dcase2025t2/eval_data/raw" 5 | for machine_type in \ 6 | "ToyRCCar" \ 7 | "ToyPet" \ 8 | "HomeCamera" \ 9 | "AutoTrash" \ 10 | "Polisher" \ 11 | "ScrewFeeder" \ 12 | "BandSealer" \ 13 | "CoffeeGrinder" \ 14 | ; do 15 | wget "https://zenodo.org/records/15519362/files/eval_data_${machine_type}_test.zip" 16 | unzip "eval_data_${machine_type}_test.zip" 17 | done 18 | -------------------------------------------------------------------------------- /datasets/datasets.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch.utils.data.dataset import Subset 3 | from sklearn.model_selection import train_test_split 4 | import sys 5 | 6 | from datasets.loader_common import get_machine_type_dict 7 | from datasets.dcase_dcase202x_t2_loader import DCASE202XT2Loader 8 | 9 | class DCASE202XT2(object): 10 | def __init__(self, args): 11 | self.width = args.frames 12 | self.height = args.n_mels 13 | self.channel = 1 14 | self.input_dim = self.width*self.height*self.channel 15 | shuffle = args.shuffle 16 | batch_sampler = None 17 | batch_size = args.batch_size 18 | print("input dim: %d" % (self.input_dim)) 19 | 20 | dataset_name = args.dataset[:11] 21 | machine_type = args.dataset[11:] 22 | if args.eval: 23 | data_path = f'{args.dataset_directory}/{dataset_name.lower()}/eval_data/' 24 | data_type = "eval" 25 | elif args.dev: 26 | data_path = f'{args.dataset_directory}/{dataset_name.lower()}/dev_data/' 27 | data_type = "dev" 28 | else: 29 | print("incorrect argument") 30 | print("please set option argument '--dev' or '--eval'") 31 | sys.exit() 32 | 33 | self.machine_type_dict = get_machine_type_dict(dataset_name, mode=args.dev)["machine_type"] 34 | self.section_id_list = self.machine_type_dict[machine_type][data_type] 35 | self.num_classes = len(self.section_id_list) 36 | print("num classes: %d" % (self.num_classes)) 37 | self.id_list = [int(machine_id) for machine_id in self.section_id_list] 38 | section_keyword = get_machine_type_dict(dataset_name, mode=args.dev)["section_keyword"] 39 | train_data = DCASE202XT2Loader( 40 | data_path, 41 | dataset_name=dataset_name, 42 | section_keyword=section_keyword, 43 | machine_type=machine_type, 44 | train=True, 45 | section_ids=self.section_id_list, 46 | frames=args.frames, 47 | n_mels=args.n_mels, 48 | frame_hop_length=args.frame_hop_length, 49 | n_fft=args.n_fft, 50 | hop_length=args.hop_length, 51 | power=args.power, 52 | fmax=args.fmax, 53 | fmin=args.fmin, 54 | win_length=args.win_length, 55 | data_type=data_type, 56 | use_id=args.use_ids, 57 | is_auto_download=args.is_auto_download, 58 | ) 59 | 60 | train_index, valid_index = train_test_split(range(len(train_data)), test_size=args.validation_split) 61 | self.train_dataset = Subset(train_data, train_index) 62 | self.train_loader = torch.utils.data.DataLoader( 63 | self.train_dataset, 64 | batch_size=batch_size, shuffle=shuffle, batch_sampler=batch_sampler, 65 | ) 66 | self.valid_dataset = Subset(train_data, valid_index) 67 | self.valid_loader = torch.utils.data.DataLoader( 68 | self.valid_dataset, 69 | batch_size=batch_size, shuffle=False, batch_sampler=batch_sampler, 70 | ) 71 | 72 | self.test_loader = [] 73 | if args.train_only: 74 | return 75 | for id in self.section_id_list: 76 | _test_loader = DCASE202XT2Loader( 77 | data_path, 78 | dataset_name=dataset_name, 79 | section_keyword=section_keyword, 80 | machine_type=machine_type, 81 | train=False, 82 | section_ids=[id], 83 | frames=args.frames, 84 | n_mels=args.n_mels, 85 | frame_hop_length=args.frame_hop_length, 86 | n_fft=args.n_fft, 87 | hop_length=args.hop_length, 88 | power=args.power, 89 | fmax=args.fmax, 90 | fmin=args.fmin, 91 | win_length=args.win_length, 92 | data_type=data_type, 93 | is_auto_download=args.is_auto_download, 94 | ) 95 | 96 | self.test_loader.append( 97 | torch.utils.data.DataLoader( 98 | _test_loader, 99 | batch_size=_test_loader.n_vectors_ea_file, shuffle=False 100 | ) 101 | ) 102 | self.mode = args.dev or _test_loader.mode 103 | 104 | 105 | class Datasets: 106 | DatasetsDic = { 107 | 'DCASE2025T2ToyRCCar':DCASE202XT2, 108 | 'DCASE2025T2ToyPet':DCASE202XT2, 109 | 'DCASE2025T2HomeCamera':DCASE202XT2, 110 | 'DCASE2025T2AutoTrash':DCASE202XT2, 111 | 'DCASE2025T2Polisher':DCASE202XT2, 112 | 'DCASE2025T2ScrewFeeder':DCASE202XT2, 113 | 'DCASE2025T2BandSealer':DCASE202XT2, 114 | 'DCASE2025T2CoffeeGrinder':DCASE202XT2, 115 | 'DCASE2025T2ToyCar':DCASE202XT2, 116 | 'DCASE2025T2ToyTrain':DCASE202XT2, 117 | 'DCASE2025T2bearing':DCASE202XT2, 118 | 'DCASE2025T2fan':DCASE202XT2, 119 | 'DCASE2025T2gearbox':DCASE202XT2, 120 | 'DCASE2025T2slider':DCASE202XT2, 121 | 'DCASE2025T2valve':DCASE202XT2, 122 | 'DCASE2024T23DPrinter':DCASE202XT2, 123 | 'DCASE2024T2AirCompressor':DCASE202XT2, 124 | 'DCASE2024T2Scanner':DCASE202XT2, 125 | 'DCASE2024T2ToyCircuit':DCASE202XT2, 126 | 'DCASE2024T2HoveringDrone':DCASE202XT2, 127 | 'DCASE2024T2HairDryer':DCASE202XT2, 128 | 'DCASE2024T2ToothBrush':DCASE202XT2, 129 | 'DCASE2024T2RoboticArm':DCASE202XT2, 130 | 'DCASE2024T2BrushlessMotor':DCASE202XT2, 131 | 'DCASE2024T2ToyCar':DCASE202XT2, 132 | 'DCASE2024T2ToyTrain':DCASE202XT2, 133 | 'DCASE2024T2bearing':DCASE202XT2, 134 | 'DCASE2024T2fan':DCASE202XT2, 135 | 'DCASE2024T2gearbox':DCASE202XT2, 136 | 'DCASE2024T2slider':DCASE202XT2, 137 | 'DCASE2024T2valve':DCASE202XT2, 138 | 'DCASE2023T2bandsaw':DCASE202XT2, 139 | 'DCASE2023T2bearing':DCASE202XT2, 140 | 'DCASE2023T2fan':DCASE202XT2, 141 | 'DCASE2023T2grinder':DCASE202XT2, 142 | 'DCASE2023T2gearbox':DCASE202XT2, 143 | 'DCASE2023T2shaker':DCASE202XT2, 144 | 'DCASE2023T2slider':DCASE202XT2, 145 | 'DCASE2023T2ToyCar':DCASE202XT2, 146 | 'DCASE2023T2ToyDrone':DCASE202XT2, 147 | 'DCASE2023T2ToyNscale':DCASE202XT2, 148 | 'DCASE2023T2ToyTank':DCASE202XT2, 149 | 'DCASE2023T2ToyTrain':DCASE202XT2, 150 | 'DCASE2023T2Vacuum':DCASE202XT2, 151 | 'DCASE2023T2valve':DCASE202XT2, 152 | 'DCASE2022T2bearing':DCASE202XT2, 153 | 'DCASE2022T2fan':DCASE202XT2, 154 | 'DCASE2022T2gearbox':DCASE202XT2, 155 | 'DCASE2022T2slider':DCASE202XT2, 156 | 'DCASE2022T2ToyCar':DCASE202XT2, 157 | 'DCASE2022T2ToyTrain':DCASE202XT2, 158 | 'DCASE2022T2valve':DCASE202XT2, 159 | 'DCASE2021T2fan':DCASE202XT2, 160 | 'DCASE2021T2gearbox':DCASE202XT2, 161 | 'DCASE2021T2pump':DCASE202XT2, 162 | 'DCASE2021T2slider':DCASE202XT2, 163 | 'DCASE2021T2ToyCar':DCASE202XT2, 164 | 'DCASE2021T2ToyTrain':DCASE202XT2, 165 | 'DCASE2021T2valve':DCASE202XT2, 166 | 'DCASE2020T2ToyCar':DCASE202XT2, 167 | 'DCASE2020T2ToyConveyor': DCASE202XT2, 168 | 'DCASE2020T2fan':DCASE202XT2, 169 | 'DCASE2020T2valve':DCASE202XT2, 170 | 'DCASE2020T2slider':DCASE202XT2, 171 | 'DCASE2020T2pump':DCASE202XT2, 172 | } 173 | 174 | def __init__(self,datasets_str): 175 | self.data = Datasets.DatasetsDic[datasets_str] 176 | 177 | def show_list(): 178 | return Datasets.DatasetsDic.keys() 179 | 180 | -------------------------------------------------------------------------------- /datasets/dcase_dcase202x_t2_loader.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pickle 3 | import torch 4 | from tqdm import tqdm 5 | import numpy as np 6 | import fasteners 7 | from pathlib import Path 8 | import time 9 | import datetime 10 | 11 | from datasets import loader_common as com 12 | 13 | class DCASE202XT2Loader(torch.utils.data.Dataset): 14 | def __init__(self, 15 | root:str, 16 | dataset_name, 17 | section_keyword, 18 | machine_type:str="ToyCar", 19 | section_ids=[], 20 | train=True, 21 | n_mels=128, 22 | frames=5, 23 | frame_hop_length=1, 24 | n_fft=1024, 25 | hop_length=512, 26 | fmax=None, 27 | fmin=None, 28 | win_length=None, 29 | power=2.0, 30 | data_type = "dev", 31 | source_domain="mix", 32 | use_id = [], 33 | is_auto_download=False, 34 | ): 35 | super().__init__() 36 | 37 | self.use_id = use_id 38 | self.section_ids = section_ids 39 | self.machine_type = machine_type 40 | 41 | target_dir = os.getcwd()+"/"+root+"raw/"+machine_type 42 | dir_name = "train" if train else "test" 43 | 44 | self.mode = data_type == "dev" 45 | if train: 46 | dir_name = "train" 47 | elif os.path.exists("{target_dir}/{dir_name}".format(target_dir=target_dir,dir_name="test_rename")): 48 | dir_name = "test_rename" 49 | self.mode = True 50 | else: 51 | dir_name = "test" 52 | 53 | self.pickle_dir = os.path.abspath( 54 | "{dir}/processed/{machine_type}/{dir_name}".format( 55 | dir=root, 56 | machine_type=machine_type, 57 | dir_name=dir_name 58 | ) 59 | ) 60 | if not (fmax or fmin): 61 | fmin_max = "" 62 | else: 63 | fmin_max = f"_f{fmin}-{fmax}" 64 | self.log_melspectrogram_dir = os.path.abspath( 65 | "{dir}/mels{n_mels}_fft{n_fft}_hop{hop_length}{fmin_max}".format( 66 | dir=self.pickle_dir, 67 | n_mels=n_mels, 68 | n_fft=n_fft, 69 | hop_length=hop_length, 70 | fmin_max=fmin_max 71 | ) 72 | ) 73 | 74 | target_dir = os.path.abspath("{}/".format(target_dir)) 75 | if is_auto_download: 76 | # download DCASE2022T2 dataset 77 | com.download_raw_data( 78 | target_dir=target_dir, 79 | dir_name=dir_name, 80 | machine_type=machine_type, 81 | data_type=data_type, 82 | dataset=dataset_name, 83 | root=root 84 | ) 85 | elif not os.path.exists(f"{target_dir}/{dir_name}"): 86 | raise FileNotFoundError(f"{target_dir}/{dir_name} is not directory and do not use auto download. \nplease download dataset or using auto download.") 87 | 88 | print("dataset dir is exists.") 89 | 90 | # get section names from wave file names 91 | section_names = [f"{section_keyword}_{section_id}" for section_id in section_ids] 92 | unique_section_names = np.unique(section_names) 93 | n_sections = len(unique_section_names) 94 | 95 | # generate dataset 96 | print("============== DATASET_GENERATOR ==============") 97 | if not os.path.exists(self.log_melspectrogram_dir): 98 | os.makedirs(self.log_melspectrogram_dir, exist_ok=True) 99 | pickle_name = section_keyword 100 | for section_id in section_ids: 101 | pickle_name = f"{pickle_name}_{section_id}" 102 | pickle_name = f"{pickle_name}_{source_domain}_TF{frames}-{frame_hop_length}_mel{n_fft}-{hop_length}" 103 | pickle_path = os.path.abspath(f"{self.log_melspectrogram_dir}/{pickle_name}.pickle") 104 | 105 | self.load_pre_process( 106 | pickle_name=pickle_name, 107 | target_dir=target_dir, 108 | pickle_path=pickle_path, 109 | n_sections=n_sections, 110 | unique_section_names=unique_section_names, 111 | dir_name=dir_name, 112 | train=train, 113 | n_mels=n_mels, 114 | frames=frames, 115 | frame_hop_length=frame_hop_length, 116 | n_fft=n_fft, 117 | hop_length=hop_length, 118 | power=power, 119 | fmax=fmax, 120 | fmin=fmin, 121 | win_length=win_length, 122 | ) 123 | if len(self.use_id) > 0: 124 | idx_list = [i for i, n in enumerate(np.argmax(self.condition, axis=1)) if int(section_ids[n]) in self.use_id] 125 | else: 126 | idx_list = list(range(len(self.condition))) 127 | idx_list_2 = [i//self.n_vectors_ea_file for i in idx_list[::self.n_vectors_ea_file]] 128 | self.data = self.data[idx_list] 129 | if len(self.y_true) > 0: 130 | self.y_true = self.y_true[idx_list_2] 131 | self.condition = self.condition[idx_list] 132 | self.basenames = [self.basenames[i] for i in idx_list_2] 133 | 134 | # getitem method setting 135 | self.frame_idx_list = list(range(len(self.data))) 136 | self.dataset_len = len(self.frame_idx_list) 137 | self.getitem_fn = self.default_item 138 | 139 | def load_pre_process( 140 | self, 141 | pickle_name, 142 | target_dir, 143 | pickle_path, 144 | n_sections, 145 | unique_section_names, 146 | dir_name, 147 | train, 148 | n_mels, 149 | frames, 150 | frame_hop_length, 151 | n_fft, 152 | hop_length, 153 | power, 154 | fmax, 155 | fmin, 156 | win_length, 157 | ): 158 | 159 | pickle_lockfile_path = os.path.abspath(f"{self.log_melspectrogram_dir}/{pickle_name}_lockfile") 160 | if os.path.isfile(pickle_path) and not os.path.isfile(pickle_lockfile_path): 161 | print("Setup has already been completed.") 162 | print(f"{pickle_path} is exists.") 163 | self.load_pickle(pickle_path=pickle_path) 164 | return 165 | else: 166 | pickle_lock = fasteners.InterProcessReaderWriterLock(pickle_lockfile_path) 167 | dataset_dir_lockfile_path = com.get_lockfile_path(target_dir=target_dir) 168 | is_enabled_dataset_dir_lock = os.path.isfile(dataset_dir_lockfile_path) 169 | if is_enabled_dataset_dir_lock: 170 | dataset_dir_lock = fasteners.InterProcessReaderWriterLock(dataset_dir_lockfile_path) 171 | try: 172 | pickle_lock.acquire_write_lock() 173 | except: 174 | print(f"{datetime.datetime.now()}\tcan not lock {pickle_lockfile_path}.") 175 | print(f"{pickle_path} is exists.") 176 | self.load_pickle(pickle_path=pickle_path) 177 | return 178 | 179 | if os.path.exists(pickle_path): 180 | print(f"{pickle_path} is exists.") 181 | com.release_write_lock( 182 | lock=pickle_lock, 183 | lock_file_path=pickle_lockfile_path 184 | ) 185 | self.load_pickle(pickle_path=pickle_path) 186 | return 187 | 188 | if is_enabled_dataset_dir_lock: 189 | try: 190 | dataset_dir_lock.acquire_read_lock() 191 | except: 192 | print(f"can not lock {dataset_dir_lockfile_path}.") 193 | is_enabled_dataset_dir_lock = False 194 | 195 | # number of wave files in each section 196 | # required for calculating y_pred for each wave file 197 | n_files_ea_section = [] 198 | 199 | self.data = np.empty((0, frames * n_mels), float) 200 | self.y_true = np.empty(0, float) 201 | self.condition = np.empty((0, n_sections), float) 202 | self.basenames = [] 203 | for section_idx, section_name in enumerate(unique_section_names): 204 | 205 | # get file list for all sections 206 | # all values of y_true are zero in training 207 | files, y_true, condition = com.file_list_generator(target_dir=target_dir, 208 | section_name=section_name, 209 | unique_section_names=unique_section_names, 210 | dir_name=dir_name, 211 | mode=self.mode, 212 | train=train) 213 | n_files_ea_section.append(len(files)) 214 | for file in files: 215 | self.basenames.append(os.path.basename(file)) 216 | 217 | data_ea_section = file_list_to_data(files, 218 | msg=f"generate {self.machine_type} section {self.section_ids[section_idx]} {dir_name} dataset", 219 | n_mels=n_mels, 220 | n_frames=frames, 221 | n_hop_frames=frame_hop_length, 222 | n_fft=n_fft, 223 | hop_length=hop_length, 224 | power=power, 225 | fmax=fmax, 226 | fmin=fmin, 227 | win_length=win_length) 228 | self.data = np.append(self.data, data_ea_section, axis=0) 229 | if self.mode or train: 230 | self.y_true = np.append(self.y_true, y_true, axis=0) 231 | for i in range(len(data_ea_section) // len(files)): 232 | self.condition = np.append(self.condition, condition, axis=0) 233 | 234 | if is_enabled_dataset_dir_lock: 235 | com.release_read_lock( 236 | lock=dataset_dir_lock, 237 | lock_file_path=dataset_dir_lockfile_path 238 | ) 239 | 240 | # number of all files 241 | n_all_files = sum(n_files_ea_section) 242 | # number of vectors for each wave file 243 | self.n_vectors_ea_file = int(self.data.shape[0] / n_all_files) 244 | 245 | # save dataset to pickle 246 | with open(pickle_path, 'wb') as f: 247 | pickle.dump(( 248 | self.data, 249 | self.y_true, 250 | self.condition, 251 | self.n_vectors_ea_file, 252 | self.basenames 253 | ), f, protocol=pickle.HIGHEST_PROTOCOL) 254 | 255 | count = 0 256 | while not com.is_enabled_pickle(pickle_path=pickle_path): 257 | assert count < 10 258 | print(f"{datetime.datetime.now()}\tpickle is not ready yet.") 259 | time.sleep(count+1) 260 | count+=1 261 | print(f"retry check pickle.\ncount : {count}") 262 | 263 | com.release_write_lock( 264 | lock=pickle_lock, 265 | lock_file_path=pickle_lockfile_path, 266 | ) 267 | 268 | def load_pickle(self, pickle_path, pickle_lock=None, pickle_lock_file=None, retry_count=0, retry_lim=20, retry_delay_time=1): 269 | assert retry_count < retry_lim 270 | if pickle_lock: 271 | try: 272 | print("wait setting dataset") 273 | pickle_lock.acquire_read_lock() 274 | except: 275 | self.load_pickle(pickle_path=pickle_path) 276 | return 277 | com.release_read_lock( 278 | lock=pickle_lock, 279 | lock_file_path=pickle_lock_file, 280 | ) 281 | print(f"load pickle : {pickle_path}") 282 | try: 283 | with open(pickle_path, 'rb') as f: 284 | self.data, self.y_true, self.condition, self.n_vectors_ea_file, self.basenames = pickle.load(f) 285 | except FileNotFoundError: 286 | print(f"{datetime.datetime.now()}\tFileNotFoundError: can not load pickle.") 287 | time.sleep(retry_delay_time) 288 | print(f"retry load pickle : {retry_count+1}/{retry_lim}") 289 | self.load_pickle( 290 | pickle_path=pickle_path, 291 | pickle_lock=pickle_lock, 292 | pickle_lock_file=pickle_lock_file, 293 | retry_count=retry_count+1, 294 | retry_lim=retry_lim, 295 | retry_delay_time=retry_delay_time+1, 296 | ) 297 | 298 | def __getitem__(self, index): 299 | """ 300 | Returns: 301 | Tensor: input data 302 | Tensor: anomaly label 303 | Tensor: one-hot vector for conditioning (section id) 304 | int: start index 305 | str: file basename 306 | """ 307 | return self.getitem_fn(index) 308 | 309 | def default_item(self, index): 310 | data = self.data[index] 311 | y_true = self.y_true[index//self.n_vectors_ea_file] if len(self.y_true) > 0 else -1 312 | condition = self.condition[index] 313 | basename = self.basenames[index//self.n_vectors_ea_file] 314 | return data, y_true, condition, basename, index 315 | 316 | def __len__(self): 317 | return self.dataset_len 318 | 319 | def file_list_to_data(file_list, 320 | msg="calc...", 321 | n_mels=64, 322 | n_frames=5, 323 | n_hop_frames=1, 324 | n_fft=1024, 325 | hop_length=512, 326 | power=2.0, 327 | fmax=None, 328 | fmin=None, 329 | win_length=None): 330 | """ 331 | convert the file_list to a vector array. 332 | file_to_vector_array() is iterated, and the output vector array is concatenated. 333 | 334 | file_list : list [ str ] 335 | .wav filename list of dataset 336 | msg : str ( default = "calc..." ) 337 | description for tqdm. 338 | this parameter will be input into "desc" param at tqdm. 339 | 340 | return : numpy.array( numpy.array( float ) ) 341 | data for training (this function is not used for test.) 342 | * dataset.shape = (number of feature vectors, dimensions of feature vectors) 343 | """ 344 | # calculate the number of dimensions 345 | dims = n_mels * n_frames 346 | 347 | # iterate file_to_vector_array() 348 | for idx in tqdm(range(len(file_list)), desc=msg): 349 | vectors = com.file_to_vectors(file_list[idx], 350 | n_mels=n_mels, 351 | n_frames=n_frames, 352 | n_fft=n_fft, 353 | hop_length=hop_length, 354 | power=power, 355 | fmax=fmax, 356 | fmin=fmin, 357 | win_length=win_length) 358 | vectors = vectors[: : n_hop_frames, :] 359 | if idx == 0: 360 | data = np.zeros((len(file_list) * vectors.shape[0], dims), float) 361 | if len(file_list) * vectors.shape[0] > data.shape[0]: 362 | tmp_data = np.zeros((len(file_list) * vectors.shape[0], dims), float) 363 | tmp_data[:data.shape[0], :] = data 364 | data = tmp_data 365 | data[vectors.shape[0] * idx : vectors.shape[0] * (idx + 1), :] = vectors 366 | 367 | return data 368 | -------------------------------------------------------------------------------- /datasets/download_path_2023.yaml: -------------------------------------------------------------------------------- 1 | DCASE2023T2: 2 | bearing: 3 | dev: 4 | - https://zenodo.org/record/7882613/files/dev_bearing.zip 5 | fan: 6 | dev: 7 | - https://zenodo.org/record/7882613/files/dev_fan.zip 8 | gearbox: 9 | dev: 10 | - https://zenodo.org/record/7882613/files/dev_gearbox.zip 11 | slider: 12 | dev: 13 | - https://zenodo.org/record/7882613/files/dev_slider.zip 14 | ToyCar: 15 | dev: 16 | - https://zenodo.org/record/7882613/files/dev_ToyCar.zip 17 | ToyTrain: 18 | dev: 19 | - https://zenodo.org/record/7882613/files/dev_ToyTrain.zip 20 | valve: 21 | dev: 22 | - https://zenodo.org/record/7882613/files/dev_valve.zip 23 | bandsaw: 24 | eval: 25 | - https://zenodo.org/record/7830345/files/eval_data_bandsaw_train.zip 26 | - https://zenodo.org/record/7860847/files/eval_data_bandsaw_test.zip 27 | grinder: 28 | eval: 29 | - https://zenodo.org/record/7830345/files/eval_data_grinder_train.zip 30 | - https://zenodo.org/record/7860847/files/eval_data_grinder_test.zip 31 | shaker: 32 | eval: 33 | - https://zenodo.org/record/7830345/files/eval_data_shaker_train.zip 34 | - https://zenodo.org/record/7860847/files/eval_data_shaker_test.zip 35 | ToyDrone: 36 | eval: 37 | - https://zenodo.org/record/7830345/files/eval_data_ToyDrone_train.zip 38 | - https://zenodo.org/record/7860847/files/eval_data_ToyDrone_test.zip 39 | ToyNscale: 40 | eval: 41 | - https://zenodo.org/record/7830345/files/eval_data_ToyNscale_train.zip 42 | - https://zenodo.org/record/7860847/files/eval_data_ToyNscale_test.zip 43 | ToyTank: 44 | eval: 45 | - https://zenodo.org/record/7830345/files/eval_data_ToyTank_train.zip 46 | - https://zenodo.org/record/7860847/files/eval_data_ToyTank_test.zip 47 | Vacuum: 48 | eval: 49 | - https://zenodo.org/record/7830345/files/eval_data_Vacuum_train.zip 50 | - https://zenodo.org/record/7860847/files/eval_data_Vacuum_test.zip -------------------------------------------------------------------------------- /datasets/download_path_2024.yaml: -------------------------------------------------------------------------------- 1 | DCASE2024T2: 2 | bearing: 3 | dev: 4 | - https://zenodo.org/record/10902294/files/dev_bearing.zip 5 | fan: 6 | dev: 7 | - https://zenodo.org/record/10902294/files/dev_fan.zip 8 | gearbox: 9 | dev: 10 | - https://zenodo.org/record/10902294/files/dev_gearbox.zip 11 | slider: 12 | dev: 13 | - https://zenodo.org/record/10902294/files/dev_slider.zip 14 | ToyCar: 15 | dev: 16 | - https://zenodo.org/record/10902294/files/dev_ToyCar.zip 17 | ToyTrain: 18 | dev: 19 | - https://zenodo.org/record/10902294/files/dev_ToyTrain.zip 20 | valve: 21 | dev: 22 | - https://zenodo.org/record/10902294/files/dev_valve.zip 23 | 3DPrinter: 24 | eval: 25 | - https://zenodo.org/records/11259435/files/eval_data_3DPrinter_train_r2.zip 26 | - https://zenodo.org/records/11363076/files/eval_data_3DPrinter_test.zip 27 | AirCompressor: 28 | eval: 29 | - https://zenodo.org/records/11259435/files/eval_data_AirCompressor_train.zip 30 | - https://zenodo.org/records/11363076/files/eval_data_AirCompressor_test.zip 31 | Scanner: 32 | eval: 33 | - https://zenodo.org/records/11259435/files/eval_data_Scanner_train.zip 34 | - https://zenodo.org/records/11363076/files/eval_data_Scanner_test.zip 35 | ToyCircuit: 36 | eval: 37 | - https://zenodo.org/records/11259435/files/eval_data_ToyCircuit_train.zip 38 | - https://zenodo.org/records/11363076/files/eval_data_ToyCircuit_test.zip 39 | HoveringDrone: 40 | eval: 41 | - https://zenodo.org/records/11259435/files/eval_data_HoveringDrone_train.zip 42 | - https://zenodo.org/records/11363076/files/eval_data_HoveringDrone_test.zip 43 | HairDryer: 44 | eval: 45 | - https://zenodo.org/records/11259435/files/eval_data_HairDryer_train.zip 46 | - https://zenodo.org/records/11363076/files/eval_data_HairDryer_test.zip 47 | ToothBrush: 48 | eval: 49 | - https://zenodo.org/records/11259435/files/eval_data_ToothBrush_train.zip 50 | - https://zenodo.org/records/11363076/files/eval_data_ToothBrush_test.zip 51 | RoboticArm: 52 | eval: 53 | - https://zenodo.org/records/11259435/files/eval_data_RoboticArm_train_r2.zip 54 | - https://zenodo.org/records/11363076/files/eval_data_RoboticArm_test.zip 55 | BrushlessMotor: 56 | eval: 57 | - https://zenodo.org/records/11259435/files/eval_data_BrushlessMotor_train.zip 58 | - https://zenodo.org/records/11363076/files/eval_data_BrushlessMotor_test.zip 59 | -------------------------------------------------------------------------------- /datasets/download_path_2025.yaml: -------------------------------------------------------------------------------- 1 | DCASE2025T2: 2 | ToyCar: 3 | dev: 4 | - https://zenodo.org/records/15097779/files/dev_ToyCar.zip 5 | ToyTrain: 6 | dev: 7 | - https://zenodo.org/records/15097779/files/dev_ToyTrain.zip 8 | bearing: 9 | dev: 10 | - https://zenodo.org/records/15097779/files/dev_bearing.zip 11 | fan: 12 | dev: 13 | - https://zenodo.org/records/15097779/files/dev_fan.zip 14 | gearbox: 15 | dev: 16 | - https://zenodo.org/records/15097779/files/dev_gearbox.zip 17 | slider: 18 | dev: 19 | - https://zenodo.org/records/15097779/files/dev_slider.zip 20 | valve: 21 | dev: 22 | - https://zenodo.org/records/15097779/files/dev_valve.zip 23 | ToyRCCar: 24 | eval: 25 | - https://zenodo.org/records/15392814/files/eval_data_ToyRCCar_train.zip 26 | - https://zenodo.org/records/15519362/files/eval_data_ToyRCCar_test.zip 27 | ToyPet: 28 | eval: 29 | - https://zenodo.org/records/15392814/files/eval_data_ToyPet_train.zip 30 | - https://zenodo.org/records/15519362/files/eval_data_ToyPet_test.zip 31 | HomeCamera: 32 | eval: 33 | - https://zenodo.org/records/15392814/files/eval_data_HomeCamera_train.zip 34 | - https://zenodo.org/records/15519362/files/eval_data_HomeCamera_test.zip 35 | AutoTrash: 36 | eval: 37 | - https://zenodo.org/records/15392814/files/eval_data_AutoTrash_train.zip 38 | - https://zenodo.org/records/15519362/files/eval_data_AutoTrash_test.zip 39 | Polisher: 40 | eval: 41 | - https://zenodo.org/records/15392814/files/eval_data_Polisher_train.zip 42 | - https://zenodo.org/records/15519362/files/eval_data_Polisher_test.zip 43 | ScrewFeeder: 44 | eval: 45 | - https://zenodo.org/records/15392814/files/eval_data_ScrewFeeder_train.zip 46 | - https://zenodo.org/records/15519362/files/eval_data_ScrewFeeder_test.zip 47 | BandSealer: 48 | eval: 49 | - https://zenodo.org/records/15392814/files/eval_data_BandSealer_train.zip 50 | - https://zenodo.org/records/15519362/files/eval_data_BandSealer_test.zip 51 | CoffeeGrinder: 52 | eval: 53 | - https://zenodo.org/records/15392814/files/eval_data_CoffeeGrinder_train.zip 54 | - https://zenodo.org/records/15519362/files/eval_data_CoffeeGrinder_test.zip -------------------------------------------------------------------------------- /datasets/download_path_legacy.yaml: -------------------------------------------------------------------------------- 1 | DCASE2020T2: 2 | ToyCar: 3 | dev: 4 | - https://zenodo.org/record/3678171/files/dev_data_ToyCar.zip 5 | eval: 6 | - https://zenodo.org/record/3727685/files/eval_data_train_ToyCar.zip 7 | - https://zenodo.org/record/3841772/files/eval_data_test_ToyCar.zip 8 | ToyConveyor: 9 | dev: 10 | - https://zenodo.org/record/3678171/files/dev_data_ToyConveyor.zip 11 | eval: 12 | - https://zenodo.org/record/3727685/files/eval_data_train_ToyConveyor.zip 13 | - https://zenodo.org/record/3841772/files/eval_data_test_ToyConveyor.zip 14 | fan: 15 | dev: 16 | - https://zenodo.org/record/3678171/files/dev_data_fan.zip 17 | eval: 18 | - https://zenodo.org/record/3727685/files/eval_data_train_fan.zip 19 | - https://zenodo.org/record/3841772/files/eval_data_test_fan.zip 20 | valve: 21 | dev: 22 | - https://zenodo.org/record/3678171/files/dev_data_valve.zip 23 | eval: 24 | - https://zenodo.org/record/3727685/files/eval_data_train_valve.zip 25 | - https://zenodo.org/record/3841772/files/eval_data_test_valve.zip 26 | slider: 27 | dev: 28 | - https://zenodo.org/record/3678171/files/dev_data_slider.zip 29 | eval: 30 | - https://zenodo.org/record/3727685/files/eval_data_train_slider.zip 31 | - https://zenodo.org/record/3841772/files/eval_data_test_slider.zip 32 | pump: 33 | dev: 34 | - https://zenodo.org/record/3678171/files/dev_data_pump.zip 35 | eval: 36 | - https://zenodo.org/record/3727685/files/eval_data_train_pump.zip 37 | - https://zenodo.org/record/3841772/files/eval_data_test_pump.zip 38 | 39 | DCASE2021T2: 40 | fan: 41 | dev: 42 | - https://zenodo.org/record/4562016/files/dev_data_fan.zip 43 | eval: 44 | - https://zenodo.org/record/4660992/files/eval_data_fan_train.zip 45 | - https://zenodo.org/record/4884786/files/eval_data_fan_test.zip 46 | gearbox: 47 | dev: 48 | - https://zenodo.org/record/4562016/files/dev_data_gearbox.zip 49 | eval: 50 | - https://zenodo.org/record/4660992/files/eval_data_gearbox_train.zip 51 | - https://zenodo.org/record/4884786/files/eval_data_gearbox_test.zip 52 | pump: 53 | dev: 54 | - https://zenodo.org/record/4562016/files/dev_data_pump.zip 55 | eval: 56 | - https://zenodo.org/record/4660992/files/eval_data_pump_train.zip 57 | - https://zenodo.org/record/4884786/files/eval_data_pump_test.zip 58 | slider: 59 | dev: 60 | - https://zenodo.org/record/4562016/files/dev_data_slider.zip 61 | eval: 62 | - https://zenodo.org/record/4660992/files/eval_data_slider_train.zip 63 | - https://zenodo.org/record/4884786/files/eval_data_slider_test.zip 64 | ToyCar: 65 | dev: 66 | - https://zenodo.org/record/4562016/files/dev_data_ToyCar.zip 67 | eval: 68 | - https://zenodo.org/record/4660992/files/eval_data_ToyCar_train.zip 69 | - https://zenodo.org/record/4884786/files/eval_data_ToyCar_test.zip 70 | ToyTrain: 71 | dev: 72 | - https://zenodo.org/record/4562016/files/dev_data_ToyTrain.zip 73 | eval: 74 | - https://zenodo.org/record/4660992/files/eval_data_ToyTrain_train.zip 75 | - https://zenodo.org/record/4884786/files/eval_data_ToyTrain_test.zip 76 | valve: 77 | dev: 78 | - https://zenodo.org/record/4562016/files/dev_data_valve.zip 79 | eval: 80 | - https://zenodo.org/record/4660992/files/eval_data_valve_train.zip 81 | - https://zenodo.org/record/4884786/files/eval_data_valve_test.zip 82 | 83 | DCASE2022T2: 84 | bearing: 85 | dev: 86 | - https://zenodo.org/record/6355122/files/dev_bearing.zip 87 | eval: 88 | - https://zenodo.org/record/6462969/files/eval_data_bearing_train.zip 89 | - https://zenodo.org/record/6586456/files/eval_data_bearing_test.zip 90 | fan: 91 | dev: 92 | - https://zenodo.org/record/6355122/files/dev_fan.zip 93 | eval: 94 | - https://zenodo.org/record/6462969/files/eval_data_fan_train.zip 95 | - https://zenodo.org/record/6586456/files/eval_data_fan_test.zip 96 | gearbox: 97 | dev: 98 | - https://zenodo.org/record/6355122/files/dev_gearbox.zip 99 | eval: 100 | - https://zenodo.org/record/6462969/files/eval_data_gearbox_train.zip 101 | - https://zenodo.org/record/6586456/files/eval_data_gearbox_test.zip 102 | slider: 103 | dev: 104 | - https://zenodo.org/record/6355122/files/dev_slider.zip 105 | eval: 106 | - https://zenodo.org/record/6462969/files/eval_data_slider_train.zip 107 | - https://zenodo.org/record/6586456/files/eval_data_slider_test.zip 108 | ToyCar: 109 | dev: 110 | - https://zenodo.org/record/6355122/files/dev_ToyCar.zip 111 | eval: 112 | - https://zenodo.org/record/6462969/files/eval_data_ToyCar_train.zip 113 | - https://zenodo.org/record/6586456/files/eval_data_ToyCar_test.zip 114 | ToyTrain: 115 | dev: 116 | - https://zenodo.org/record/6355122/files/dev_ToyTrain.zip 117 | eval: 118 | - https://zenodo.org/record/6462969/files/eval_data_ToyTrain_train.zip 119 | - https://zenodo.org/record/6586456/files/eval_data_ToyTrain_test.zip 120 | valve: 121 | dev: 122 | - https://zenodo.org/record/6355122/files/dev_valve.zip 123 | eval: 124 | - https://zenodo.org/record/6462969/files/eval_data_valve_train.zip 125 | - https://zenodo.org/record/6586456/files/eval_data_valve_test.zip 126 | -------------------------------------------------------------------------------- /datasets/ground_truth_attributes/dcase2024t2/dev_data/slider/attributes_00_test_correspondence.csv: -------------------------------------------------------------------------------- 1 | source_file_name,target_file_name 2 | section_00_source_test_anomaly_0001_ac_0.03_.wav,section_00_source_test_anomaly_0001_noAttribute.wav 3 | section_00_source_test_anomaly_0002_ac_0.03_.wav,section_00_source_test_anomaly_0002_noAttribute.wav 4 | section_00_source_test_anomaly_0003_ac_0.03_.wav,section_00_source_test_anomaly_0003_noAttribute.wav 5 | section_00_source_test_anomaly_0004_ac_0.03_.wav,section_00_source_test_anomaly_0004_noAttribute.wav 6 | section_00_source_test_anomaly_0005_ac_0.03_.wav,section_00_source_test_anomaly_0005_noAttribute.wav 7 | section_00_source_test_anomaly_0006_ac_0.05_.wav,section_00_source_test_anomaly_0006_noAttribute.wav 8 | section_00_source_test_anomaly_0007_ac_0.05_.wav,section_00_source_test_anomaly_0007_noAttribute.wav 9 | section_00_source_test_anomaly_0008_ac_0.05_.wav,section_00_source_test_anomaly_0008_noAttribute.wav 10 | section_00_source_test_anomaly_0009_ac_0.05_.wav,section_00_source_test_anomaly_0009_noAttribute.wav 11 | section_00_source_test_anomaly_0010_ac_0.05_.wav,section_00_source_test_anomaly_0010_noAttribute.wav 12 | section_00_source_test_anomaly_0011_ac_0.07_.wav,section_00_source_test_anomaly_0011_noAttribute.wav 13 | section_00_source_test_anomaly_0012_ac_0.07_.wav,section_00_source_test_anomaly_0012_noAttribute.wav 14 | section_00_source_test_anomaly_0013_ac_0.07_.wav,section_00_source_test_anomaly_0013_noAttribute.wav 15 | section_00_source_test_anomaly_0014_ac_0.07_.wav,section_00_source_test_anomaly_0014_noAttribute.wav 16 | section_00_source_test_anomaly_0015_ac_0.07_.wav,section_00_source_test_anomaly_0015_noAttribute.wav 17 | section_00_source_test_anomaly_0016_ac_0.09_.wav,section_00_source_test_anomaly_0016_noAttribute.wav 18 | section_00_source_test_anomaly_0017_ac_0.09_.wav,section_00_source_test_anomaly_0017_noAttribute.wav 19 | section_00_source_test_anomaly_0018_ac_0.09_.wav,section_00_source_test_anomaly_0018_noAttribute.wav 20 | section_00_source_test_anomaly_0019_ac_0.09_.wav,section_00_source_test_anomaly_0019_noAttribute.wav 21 | section_00_source_test_anomaly_0020_ac_0.09_.wav,section_00_source_test_anomaly_0020_noAttribute.wav 22 | section_00_source_test_anomaly_0021_ac_0.11_.wav,section_00_source_test_anomaly_0021_noAttribute.wav 23 | section_00_source_test_anomaly_0022_ac_0.11_.wav,section_00_source_test_anomaly_0022_noAttribute.wav 24 | section_00_source_test_anomaly_0023_ac_0.11_.wav,section_00_source_test_anomaly_0023_noAttribute.wav 25 | section_00_source_test_anomaly_0024_ac_0.11_.wav,section_00_source_test_anomaly_0024_noAttribute.wav 26 | section_00_source_test_anomaly_0025_ac_0.11_.wav,section_00_source_test_anomaly_0025_noAttribute.wav 27 | section_00_source_test_anomaly_0026_ac_0.03_.wav,section_00_source_test_anomaly_0026_noAttribute.wav 28 | section_00_source_test_anomaly_0027_ac_0.03_.wav,section_00_source_test_anomaly_0027_noAttribute.wav 29 | section_00_source_test_anomaly_0028_ac_0.03_.wav,section_00_source_test_anomaly_0028_noAttribute.wav 30 | section_00_source_test_anomaly_0029_ac_0.03_.wav,section_00_source_test_anomaly_0029_noAttribute.wav 31 | section_00_source_test_anomaly_0030_ac_0.03_.wav,section_00_source_test_anomaly_0030_noAttribute.wav 32 | section_00_source_test_anomaly_0031_ac_0.05_.wav,section_00_source_test_anomaly_0031_noAttribute.wav 33 | section_00_source_test_anomaly_0032_ac_0.05_.wav,section_00_source_test_anomaly_0032_noAttribute.wav 34 | section_00_source_test_anomaly_0033_ac_0.05_.wav,section_00_source_test_anomaly_0033_noAttribute.wav 35 | section_00_source_test_anomaly_0034_ac_0.05_.wav,section_00_source_test_anomaly_0034_noAttribute.wav 36 | section_00_source_test_anomaly_0035_ac_0.05_.wav,section_00_source_test_anomaly_0035_noAttribute.wav 37 | section_00_source_test_anomaly_0036_ac_0.07_.wav,section_00_source_test_anomaly_0036_noAttribute.wav 38 | section_00_source_test_anomaly_0037_ac_0.07_.wav,section_00_source_test_anomaly_0037_noAttribute.wav 39 | section_00_source_test_anomaly_0038_ac_0.07_.wav,section_00_source_test_anomaly_0038_noAttribute.wav 40 | section_00_source_test_anomaly_0039_ac_0.07_.wav,section_00_source_test_anomaly_0039_noAttribute.wav 41 | section_00_source_test_anomaly_0040_ac_0.07_.wav,section_00_source_test_anomaly_0040_noAttribute.wav 42 | section_00_source_test_anomaly_0041_ac_0.09_.wav,section_00_source_test_anomaly_0041_noAttribute.wav 43 | section_00_source_test_anomaly_0042_ac_0.09_.wav,section_00_source_test_anomaly_0042_noAttribute.wav 44 | section_00_source_test_anomaly_0043_ac_0.09_.wav,section_00_source_test_anomaly_0043_noAttribute.wav 45 | section_00_source_test_anomaly_0044_ac_0.09_.wav,section_00_source_test_anomaly_0044_noAttribute.wav 46 | section_00_source_test_anomaly_0045_ac_0.09_.wav,section_00_source_test_anomaly_0045_noAttribute.wav 47 | section_00_source_test_anomaly_0046_ac_0.11_.wav,section_00_source_test_anomaly_0046_noAttribute.wav 48 | section_00_source_test_anomaly_0047_ac_0.11_.wav,section_00_source_test_anomaly_0047_noAttribute.wav 49 | section_00_source_test_anomaly_0048_ac_0.11_.wav,section_00_source_test_anomaly_0048_noAttribute.wav 50 | section_00_source_test_anomaly_0049_ac_0.11_.wav,section_00_source_test_anomaly_0049_noAttribute.wav 51 | section_00_source_test_anomaly_0050_ac_0.11_.wav,section_00_source_test_anomaly_0050_noAttribute.wav 52 | section_00_source_test_normal_0001_ac_0.03.wav,section_00_source_test_normal_0001_noAttribute.wav 53 | section_00_source_test_normal_0002_ac_0.03.wav,section_00_source_test_normal_0002_noAttribute.wav 54 | section_00_source_test_normal_0003_ac_0.03.wav,section_00_source_test_normal_0003_noAttribute.wav 55 | section_00_source_test_normal_0004_ac_0.03.wav,section_00_source_test_normal_0004_noAttribute.wav 56 | section_00_source_test_normal_0005_ac_0.03.wav,section_00_source_test_normal_0005_noAttribute.wav 57 | section_00_source_test_normal_0006_ac_0.03.wav,section_00_source_test_normal_0006_noAttribute.wav 58 | section_00_source_test_normal_0007_ac_0.03.wav,section_00_source_test_normal_0007_noAttribute.wav 59 | section_00_source_test_normal_0008_ac_0.03.wav,section_00_source_test_normal_0008_noAttribute.wav 60 | section_00_source_test_normal_0009_ac_0.03.wav,section_00_source_test_normal_0009_noAttribute.wav 61 | section_00_source_test_normal_0010_ac_0.03.wav,section_00_source_test_normal_0010_noAttribute.wav 62 | section_00_source_test_normal_0011_ac_0.05.wav,section_00_source_test_normal_0011_noAttribute.wav 63 | section_00_source_test_normal_0012_ac_0.05.wav,section_00_source_test_normal_0012_noAttribute.wav 64 | section_00_source_test_normal_0013_ac_0.05.wav,section_00_source_test_normal_0013_noAttribute.wav 65 | section_00_source_test_normal_0014_ac_0.05.wav,section_00_source_test_normal_0014_noAttribute.wav 66 | section_00_source_test_normal_0015_ac_0.05.wav,section_00_source_test_normal_0015_noAttribute.wav 67 | section_00_source_test_normal_0016_ac_0.05.wav,section_00_source_test_normal_0016_noAttribute.wav 68 | section_00_source_test_normal_0017_ac_0.05.wav,section_00_source_test_normal_0017_noAttribute.wav 69 | section_00_source_test_normal_0018_ac_0.05.wav,section_00_source_test_normal_0018_noAttribute.wav 70 | section_00_source_test_normal_0019_ac_0.05.wav,section_00_source_test_normal_0019_noAttribute.wav 71 | section_00_source_test_normal_0020_ac_0.05.wav,section_00_source_test_normal_0020_noAttribute.wav 72 | section_00_source_test_normal_0021_ac_0.07.wav,section_00_source_test_normal_0021_noAttribute.wav 73 | section_00_source_test_normal_0022_ac_0.07.wav,section_00_source_test_normal_0022_noAttribute.wav 74 | section_00_source_test_normal_0023_ac_0.07.wav,section_00_source_test_normal_0023_noAttribute.wav 75 | section_00_source_test_normal_0024_ac_0.07.wav,section_00_source_test_normal_0024_noAttribute.wav 76 | section_00_source_test_normal_0025_ac_0.07.wav,section_00_source_test_normal_0025_noAttribute.wav 77 | section_00_source_test_normal_0026_ac_0.07.wav,section_00_source_test_normal_0026_noAttribute.wav 78 | section_00_source_test_normal_0027_ac_0.07.wav,section_00_source_test_normal_0027_noAttribute.wav 79 | section_00_source_test_normal_0028_ac_0.07.wav,section_00_source_test_normal_0028_noAttribute.wav 80 | section_00_source_test_normal_0029_ac_0.07.wav,section_00_source_test_normal_0029_noAttribute.wav 81 | section_00_source_test_normal_0030_ac_0.07.wav,section_00_source_test_normal_0030_noAttribute.wav 82 | section_00_source_test_normal_0031_ac_0.09.wav,section_00_source_test_normal_0031_noAttribute.wav 83 | section_00_source_test_normal_0032_ac_0.09.wav,section_00_source_test_normal_0032_noAttribute.wav 84 | section_00_source_test_normal_0033_ac_0.09.wav,section_00_source_test_normal_0033_noAttribute.wav 85 | section_00_source_test_normal_0034_ac_0.09.wav,section_00_source_test_normal_0034_noAttribute.wav 86 | section_00_source_test_normal_0035_ac_0.09.wav,section_00_source_test_normal_0035_noAttribute.wav 87 | section_00_source_test_normal_0036_ac_0.09.wav,section_00_source_test_normal_0036_noAttribute.wav 88 | section_00_source_test_normal_0037_ac_0.09.wav,section_00_source_test_normal_0037_noAttribute.wav 89 | section_00_source_test_normal_0038_ac_0.09.wav,section_00_source_test_normal_0038_noAttribute.wav 90 | section_00_source_test_normal_0039_ac_0.09.wav,section_00_source_test_normal_0039_noAttribute.wav 91 | section_00_source_test_normal_0040_ac_0.09.wav,section_00_source_test_normal_0040_noAttribute.wav 92 | section_00_source_test_normal_0041_ac_0.11.wav,section_00_source_test_normal_0041_noAttribute.wav 93 | section_00_source_test_normal_0042_ac_0.11.wav,section_00_source_test_normal_0042_noAttribute.wav 94 | section_00_source_test_normal_0043_ac_0.11.wav,section_00_source_test_normal_0043_noAttribute.wav 95 | section_00_source_test_normal_0044_ac_0.11.wav,section_00_source_test_normal_0044_noAttribute.wav 96 | section_00_source_test_normal_0045_ac_0.11.wav,section_00_source_test_normal_0045_noAttribute.wav 97 | section_00_source_test_normal_0046_ac_0.11.wav,section_00_source_test_normal_0046_noAttribute.wav 98 | section_00_source_test_normal_0047_ac_0.11.wav,section_00_source_test_normal_0047_noAttribute.wav 99 | section_00_source_test_normal_0048_ac_0.11.wav,section_00_source_test_normal_0048_noAttribute.wav 100 | section_00_source_test_normal_0049_ac_0.11.wav,section_00_source_test_normal_0049_noAttribute.wav 101 | section_00_source_test_normal_0050_ac_0.11.wav,section_00_source_test_normal_0050_noAttribute.wav 102 | section_00_target_test_anomaly_0001_ac_0.01_.wav,section_00_target_test_anomaly_0001_noAttribute.wav 103 | section_00_target_test_anomaly_0002_ac_0.01_.wav,section_00_target_test_anomaly_0002_noAttribute.wav 104 | section_00_target_test_anomaly_0003_ac_0.01_.wav,section_00_target_test_anomaly_0003_noAttribute.wav 105 | section_00_target_test_anomaly_0004_ac_0.01_.wav,section_00_target_test_anomaly_0004_noAttribute.wav 106 | section_00_target_test_anomaly_0005_ac_0.02_.wav,section_00_target_test_anomaly_0005_noAttribute.wav 107 | section_00_target_test_anomaly_0006_ac_0.02_.wav,section_00_target_test_anomaly_0006_noAttribute.wav 108 | section_00_target_test_anomaly_0007_ac_0.02_.wav,section_00_target_test_anomaly_0007_noAttribute.wav 109 | section_00_target_test_anomaly_0008_ac_0.04_.wav,section_00_target_test_anomaly_0008_noAttribute.wav 110 | section_00_target_test_anomaly_0009_ac_0.04_.wav,section_00_target_test_anomaly_0009_noAttribute.wav 111 | section_00_target_test_anomaly_0010_ac_0.04_.wav,section_00_target_test_anomaly_0010_noAttribute.wav 112 | section_00_target_test_anomaly_0011_ac_0.04_.wav,section_00_target_test_anomaly_0011_noAttribute.wav 113 | section_00_target_test_anomaly_0012_ac_0.06_.wav,section_00_target_test_anomaly_0012_noAttribute.wav 114 | section_00_target_test_anomaly_0013_ac_0.06_.wav,section_00_target_test_anomaly_0013_noAttribute.wav 115 | section_00_target_test_anomaly_0014_ac_0.06_.wav,section_00_target_test_anomaly_0014_noAttribute.wav 116 | section_00_target_test_anomaly_0015_ac_0.06_.wav,section_00_target_test_anomaly_0015_noAttribute.wav 117 | section_00_target_test_anomaly_0016_ac_0.08_.wav,section_00_target_test_anomaly_0016_noAttribute.wav 118 | section_00_target_test_anomaly_0017_ac_0.08_.wav,section_00_target_test_anomaly_0017_noAttribute.wav 119 | section_00_target_test_anomaly_0018_ac_0.08_.wav,section_00_target_test_anomaly_0018_noAttribute.wav 120 | section_00_target_test_anomaly_0019_ac_0.10_.wav,section_00_target_test_anomaly_0019_noAttribute.wav 121 | section_00_target_test_anomaly_0020_ac_0.10_.wav,section_00_target_test_anomaly_0020_noAttribute.wav 122 | section_00_target_test_anomaly_0021_ac_0.10_.wav,section_00_target_test_anomaly_0021_noAttribute.wav 123 | section_00_target_test_anomaly_0022_ac_0.12_.wav,section_00_target_test_anomaly_0022_noAttribute.wav 124 | section_00_target_test_anomaly_0023_ac_0.13_.wav,section_00_target_test_anomaly_0023_noAttribute.wav 125 | section_00_target_test_anomaly_0024_ac_0.13_.wav,section_00_target_test_anomaly_0024_noAttribute.wav 126 | section_00_target_test_anomaly_0025_ac_0.01_.wav,section_00_target_test_anomaly_0025_noAttribute.wav 127 | section_00_target_test_anomaly_0026_ac_0.01_.wav,section_00_target_test_anomaly_0026_noAttribute.wav 128 | section_00_target_test_anomaly_0027_ac_0.01_.wav,section_00_target_test_anomaly_0027_noAttribute.wav 129 | section_00_target_test_anomaly_0028_ac_0.02_.wav,section_00_target_test_anomaly_0028_noAttribute.wav 130 | section_00_target_test_anomaly_0029_ac_0.02_.wav,section_00_target_test_anomaly_0029_noAttribute.wav 131 | section_00_target_test_anomaly_0030_ac_0.02_.wav,section_00_target_test_anomaly_0030_noAttribute.wav 132 | section_00_target_test_anomaly_0031_ac_0.04_.wav,section_00_target_test_anomaly_0031_noAttribute.wav 133 | section_00_target_test_anomaly_0032_ac_0.04_.wav,section_00_target_test_anomaly_0032_noAttribute.wav 134 | section_00_target_test_anomaly_0033_ac_0.06_.wav,section_00_target_test_anomaly_0033_noAttribute.wav 135 | section_00_target_test_anomaly_0034_ac_0.06_.wav,section_00_target_test_anomaly_0034_noAttribute.wav 136 | section_00_target_test_anomaly_0035_ac_0.08_.wav,section_00_target_test_anomaly_0035_noAttribute.wav 137 | section_00_target_test_anomaly_0036_ac_0.08_.wav,section_00_target_test_anomaly_0036_noAttribute.wav 138 | section_00_target_test_anomaly_0037_ac_0.08_.wav,section_00_target_test_anomaly_0037_noAttribute.wav 139 | section_00_target_test_anomaly_0038_ac_0.10_.wav,section_00_target_test_anomaly_0038_noAttribute.wav 140 | section_00_target_test_anomaly_0039_ac_0.10_.wav,section_00_target_test_anomaly_0039_noAttribute.wav 141 | section_00_target_test_anomaly_0040_ac_0.10_.wav,section_00_target_test_anomaly_0040_noAttribute.wav 142 | section_00_target_test_anomaly_0041_ac_0.12_.wav,section_00_target_test_anomaly_0041_noAttribute.wav 143 | section_00_target_test_anomaly_0042_ac_0.12_.wav,section_00_target_test_anomaly_0042_noAttribute.wav 144 | section_00_target_test_anomaly_0043_ac_0.12_.wav,section_00_target_test_anomaly_0043_noAttribute.wav 145 | section_00_target_test_anomaly_0044_ac_0.12_.wav,section_00_target_test_anomaly_0044_noAttribute.wav 146 | section_00_target_test_anomaly_0045_ac_0.12_.wav,section_00_target_test_anomaly_0045_noAttribute.wav 147 | section_00_target_test_anomaly_0046_ac_0.13_.wav,section_00_target_test_anomaly_0046_noAttribute.wav 148 | section_00_target_test_anomaly_0047_ac_0.13_.wav,section_00_target_test_anomaly_0047_noAttribute.wav 149 | section_00_target_test_anomaly_0048_ac_0.13_.wav,section_00_target_test_anomaly_0048_noAttribute.wav 150 | section_00_target_test_anomaly_0049_ac_0.13_.wav,section_00_target_test_anomaly_0049_noAttribute.wav 151 | section_00_target_test_anomaly_0050_ac_0.13_.wav,section_00_target_test_anomaly_0050_noAttribute.wav 152 | section_00_target_test_normal_0001_ac_0.01.wav,section_00_target_test_normal_0001_noAttribute.wav 153 | section_00_target_test_normal_0002_ac_0.01.wav,section_00_target_test_normal_0002_noAttribute.wav 154 | section_00_target_test_normal_0003_ac_0.01.wav,section_00_target_test_normal_0003_noAttribute.wav 155 | section_00_target_test_normal_0004_ac_0.01.wav,section_00_target_test_normal_0004_noAttribute.wav 156 | section_00_target_test_normal_0005_ac_0.01.wav,section_00_target_test_normal_0005_noAttribute.wav 157 | section_00_target_test_normal_0006_ac_0.01.wav,section_00_target_test_normal_0006_noAttribute.wav 158 | section_00_target_test_normal_0007_ac_0.01.wav,section_00_target_test_normal_0007_noAttribute.wav 159 | section_00_target_test_normal_0008_ac_0.02.wav,section_00_target_test_normal_0008_noAttribute.wav 160 | section_00_target_test_normal_0009_ac_0.02.wav,section_00_target_test_normal_0009_noAttribute.wav 161 | section_00_target_test_normal_0010_ac_0.02.wav,section_00_target_test_normal_0010_noAttribute.wav 162 | section_00_target_test_normal_0011_ac_0.02.wav,section_00_target_test_normal_0011_noAttribute.wav 163 | section_00_target_test_normal_0012_ac_0.02.wav,section_00_target_test_normal_0012_noAttribute.wav 164 | section_00_target_test_normal_0013_ac_0.02.wav,section_00_target_test_normal_0013_noAttribute.wav 165 | section_00_target_test_normal_0014_ac_0.04.wav,section_00_target_test_normal_0014_noAttribute.wav 166 | section_00_target_test_normal_0015_ac_0.04.wav,section_00_target_test_normal_0015_noAttribute.wav 167 | section_00_target_test_normal_0016_ac_0.04.wav,section_00_target_test_normal_0016_noAttribute.wav 168 | section_00_target_test_normal_0017_ac_0.04.wav,section_00_target_test_normal_0017_noAttribute.wav 169 | section_00_target_test_normal_0018_ac_0.04.wav,section_00_target_test_normal_0018_noAttribute.wav 170 | section_00_target_test_normal_0019_ac_0.04.wav,section_00_target_test_normal_0019_noAttribute.wav 171 | section_00_target_test_normal_0020_ac_0.06.wav,section_00_target_test_normal_0020_noAttribute.wav 172 | section_00_target_test_normal_0021_ac_0.06.wav,section_00_target_test_normal_0021_noAttribute.wav 173 | section_00_target_test_normal_0022_ac_0.06.wav,section_00_target_test_normal_0022_noAttribute.wav 174 | section_00_target_test_normal_0023_ac_0.06.wav,section_00_target_test_normal_0023_noAttribute.wav 175 | section_00_target_test_normal_0024_ac_0.06.wav,section_00_target_test_normal_0024_noAttribute.wav 176 | section_00_target_test_normal_0025_ac_0.06.wav,section_00_target_test_normal_0025_noAttribute.wav 177 | section_00_target_test_normal_0026_ac_0.08.wav,section_00_target_test_normal_0026_noAttribute.wav 178 | section_00_target_test_normal_0027_ac_0.08.wav,section_00_target_test_normal_0027_noAttribute.wav 179 | section_00_target_test_normal_0028_ac_0.08.wav,section_00_target_test_normal_0028_noAttribute.wav 180 | section_00_target_test_normal_0029_ac_0.08.wav,section_00_target_test_normal_0029_noAttribute.wav 181 | section_00_target_test_normal_0030_ac_0.08.wav,section_00_target_test_normal_0030_noAttribute.wav 182 | section_00_target_test_normal_0031_ac_0.08.wav,section_00_target_test_normal_0031_noAttribute.wav 183 | section_00_target_test_normal_0032_ac_0.10.wav,section_00_target_test_normal_0032_noAttribute.wav 184 | section_00_target_test_normal_0033_ac_0.10.wav,section_00_target_test_normal_0033_noAttribute.wav 185 | section_00_target_test_normal_0034_ac_0.10.wav,section_00_target_test_normal_0034_noAttribute.wav 186 | section_00_target_test_normal_0035_ac_0.10.wav,section_00_target_test_normal_0035_noAttribute.wav 187 | section_00_target_test_normal_0036_ac_0.10.wav,section_00_target_test_normal_0036_noAttribute.wav 188 | section_00_target_test_normal_0037_ac_0.10.wav,section_00_target_test_normal_0037_noAttribute.wav 189 | section_00_target_test_normal_0038_ac_0.12.wav,section_00_target_test_normal_0038_noAttribute.wav 190 | section_00_target_test_normal_0039_ac_0.12.wav,section_00_target_test_normal_0039_noAttribute.wav 191 | section_00_target_test_normal_0040_ac_0.12.wav,section_00_target_test_normal_0040_noAttribute.wav 192 | section_00_target_test_normal_0041_ac_0.12.wav,section_00_target_test_normal_0041_noAttribute.wav 193 | section_00_target_test_normal_0042_ac_0.12.wav,section_00_target_test_normal_0042_noAttribute.wav 194 | section_00_target_test_normal_0043_ac_0.12.wav,section_00_target_test_normal_0043_noAttribute.wav 195 | section_00_target_test_normal_0044_ac_0.13.wav,section_00_target_test_normal_0044_noAttribute.wav 196 | section_00_target_test_normal_0045_ac_0.13.wav,section_00_target_test_normal_0045_noAttribute.wav 197 | section_00_target_test_normal_0046_ac_0.13.wav,section_00_target_test_normal_0046_noAttribute.wav 198 | section_00_target_test_normal_0047_ac_0.13.wav,section_00_target_test_normal_0047_noAttribute.wav 199 | section_00_target_test_normal_0048_ac_0.13.wav,section_00_target_test_normal_0048_noAttribute.wav 200 | section_00_target_test_normal_0049_ac_0.13.wav,section_00_target_test_normal_0049_noAttribute.wav 201 | section_00_target_test_normal_0050_ac_0.13.wav,section_00_target_test_normal_0050_noAttribute.wav 202 | -------------------------------------------------------------------------------- /datasets/ground_truth_attributes/dcase2024t2/eval_data/AirCompressor/attributes_00_test_correspondence.csv: -------------------------------------------------------------------------------- 1 | source_file_name,target_file_name 2 | section_00_source_test_anomaly_0011_fl_2_nos_0.wav,section_00_source_test_anomaly_0011_noAttribute.wav 3 | section_00_source_test_anomaly_0021_fl_0_nos_2.wav,section_00_source_test_anomaly_0021_noAttribute.wav 4 | section_00_source_test_anomaly_0022_fl_0_nos_2.wav,section_00_source_test_anomaly_0022_noAttribute.wav 5 | section_00_source_test_anomaly_0023_fl_2_nos_0.wav,section_00_source_test_anomaly_0023_noAttribute.wav 6 | section_00_source_test_anomaly_0024_fl_0_nos_2.wav,section_00_source_test_anomaly_0024_noAttribute.wav 7 | section_00_source_test_anomaly_0028_fl_0_nos_3.wav,section_00_source_test_anomaly_0028_noAttribute.wav 8 | section_00_source_test_anomaly_0033_fl_2_nos_2.wav,section_00_source_test_anomaly_0033_noAttribute.wav 9 | section_00_source_test_anomaly_0034_fl_0_nos_2.wav,section_00_source_test_anomaly_0034_noAttribute.wav 10 | section_00_source_test_anomaly_0039_fl_0_nos_2.wav,section_00_source_test_anomaly_0039_noAttribute.wav 11 | section_00_source_test_anomaly_0042_fl_2_nos_2.wav,section_00_source_test_anomaly_0042_noAttribute.wav 12 | section_00_source_test_anomaly_0049_fl_0_nos_2.wav,section_00_source_test_anomaly_0049_noAttribute.wav 13 | section_00_source_test_anomaly_0062_fl_0_nos_0.wav,section_00_source_test_anomaly_0062_noAttribute.wav 14 | section_00_source_test_anomaly_0066_fl_2_nos_3.wav,section_00_source_test_anomaly_0066_noAttribute.wav 15 | section_00_source_test_anomaly_0068_fl_0_nos_3.wav,section_00_source_test_anomaly_0068_noAttribute.wav 16 | section_00_source_test_anomaly_0069_fl_2_nos_3.wav,section_00_source_test_anomaly_0069_noAttribute.wav 17 | section_00_source_test_anomaly_0071_fl_2_nos_0.wav,section_00_source_test_anomaly_0071_noAttribute.wav 18 | section_00_source_test_anomaly_0078_fl_0_nos_2.wav,section_00_source_test_anomaly_0078_noAttribute.wav 19 | section_00_source_test_anomaly_0081_fl_2_nos_3.wav,section_00_source_test_anomaly_0081_noAttribute.wav 20 | section_00_source_test_anomaly_0086_fl_0_nos_3.wav,section_00_source_test_anomaly_0086_noAttribute.wav 21 | section_00_source_test_anomaly_0087_fl_0_nos_3.wav,section_00_source_test_anomaly_0087_noAttribute.wav 22 | section_00_source_test_anomaly_0089_fl_2_nos_3.wav,section_00_source_test_anomaly_0089_noAttribute.wav 23 | section_00_source_test_anomaly_0090_fl_0_nos_0.wav,section_00_source_test_anomaly_0090_noAttribute.wav 24 | section_00_source_test_anomaly_0091_fl_0_nos_2.wav,section_00_source_test_anomaly_0091_noAttribute.wav 25 | section_00_source_test_anomaly_0092_fl_0_nos_3.wav,section_00_source_test_anomaly_0092_noAttribute.wav 26 | section_00_source_test_anomaly_0093_fl_0_nos_0.wav,section_00_source_test_anomaly_0093_noAttribute.wav 27 | section_00_source_test_anomaly_0095_fl_2_nos_2.wav,section_00_source_test_anomaly_0095_noAttribute.wav 28 | section_00_source_test_anomaly_0099_fl_2_nos_2.wav,section_00_source_test_anomaly_0099_noAttribute.wav 29 | section_00_source_test_anomaly_0102_fl_2_nos_0.wav,section_00_source_test_anomaly_0102_noAttribute.wav 30 | section_00_source_test_anomaly_0107_fl_0_nos_0.wav,section_00_source_test_anomaly_0107_noAttribute.wav 31 | section_00_source_test_anomaly_0114_fl_0_nos_3.wav,section_00_source_test_anomaly_0114_noAttribute.wav 32 | section_00_source_test_anomaly_0125_fl_2_nos_2.wav,section_00_source_test_anomaly_0125_noAttribute.wav 33 | section_00_source_test_anomaly_0127_fl_2_nos_3.wav,section_00_source_test_anomaly_0127_noAttribute.wav 34 | section_00_source_test_anomaly_0129_fl_0_nos_0.wav,section_00_source_test_anomaly_0129_noAttribute.wav 35 | section_00_source_test_anomaly_0137_fl_2_nos_2.wav,section_00_source_test_anomaly_0137_noAttribute.wav 36 | section_00_source_test_anomaly_0141_fl_0_nos_0.wav,section_00_source_test_anomaly_0141_noAttribute.wav 37 | section_00_source_test_anomaly_0143_fl_0_nos_3.wav,section_00_source_test_anomaly_0143_noAttribute.wav 38 | section_00_source_test_anomaly_0146_fl_2_nos_3.wav,section_00_source_test_anomaly_0146_noAttribute.wav 39 | section_00_source_test_anomaly_0150_fl_2_nos_2.wav,section_00_source_test_anomaly_0150_noAttribute.wav 40 | section_00_source_test_anomaly_0156_fl_2_nos_2.wav,section_00_source_test_anomaly_0156_noAttribute.wav 41 | section_00_source_test_anomaly_0163_fl_0_nos_0.wav,section_00_source_test_anomaly_0163_noAttribute.wav 42 | section_00_source_test_anomaly_0165_fl_2_nos_2.wav,section_00_source_test_anomaly_0165_noAttribute.wav 43 | section_00_source_test_anomaly_0168_fl_2_nos_0.wav,section_00_source_test_anomaly_0168_noAttribute.wav 44 | section_00_source_test_anomaly_0169_fl_2_nos_3.wav,section_00_source_test_anomaly_0169_noAttribute.wav 45 | section_00_source_test_anomaly_0178_fl_2_nos_0.wav,section_00_source_test_anomaly_0178_noAttribute.wav 46 | section_00_source_test_anomaly_0180_fl_2_nos_0.wav,section_00_source_test_anomaly_0180_noAttribute.wav 47 | section_00_source_test_anomaly_0186_fl_2_nos_3.wav,section_00_source_test_anomaly_0186_noAttribute.wav 48 | section_00_source_test_anomaly_0192_fl_0_nos_3.wav,section_00_source_test_anomaly_0192_noAttribute.wav 49 | section_00_source_test_anomaly_0196_fl_2_nos_0.wav,section_00_source_test_anomaly_0196_noAttribute.wav 50 | section_00_source_test_anomaly_0197_fl_0_nos_0.wav,section_00_source_test_anomaly_0197_noAttribute.wav 51 | section_00_source_test_anomaly_0200_fl_0_nos_2.wav,section_00_source_test_anomaly_0200_noAttribute.wav 52 | section_00_source_test_normal_0001_fl_2_nos_3.wav,section_00_source_test_normal_0001_noAttribute.wav 53 | section_00_source_test_normal_0010_fl_2_nos_0.wav,section_00_source_test_normal_0010_noAttribute.wav 54 | section_00_source_test_normal_0013_fl_0_nos_2.wav,section_00_source_test_normal_0013_noAttribute.wav 55 | section_00_source_test_normal_0016_fl_2_nos_0.wav,section_00_source_test_normal_0016_noAttribute.wav 56 | section_00_source_test_normal_0017_fl_2_nos_3.wav,section_00_source_test_normal_0017_noAttribute.wav 57 | section_00_source_test_normal_0019_fl_2_nos_3.wav,section_00_source_test_normal_0019_noAttribute.wav 58 | section_00_source_test_normal_0026_fl_0_nos_0.wav,section_00_source_test_normal_0026_noAttribute.wav 59 | section_00_source_test_normal_0032_fl_0_nos_3.wav,section_00_source_test_normal_0032_noAttribute.wav 60 | section_00_source_test_normal_0037_fl_2_nos_0.wav,section_00_source_test_normal_0037_noAttribute.wav 61 | section_00_source_test_normal_0038_fl_0_nos_3.wav,section_00_source_test_normal_0038_noAttribute.wav 62 | section_00_source_test_normal_0054_fl_2_nos_2.wav,section_00_source_test_normal_0054_noAttribute.wav 63 | section_00_source_test_normal_0055_fl_0_nos_3.wav,section_00_source_test_normal_0055_noAttribute.wav 64 | section_00_source_test_normal_0056_fl_0_nos_0.wav,section_00_source_test_normal_0056_noAttribute.wav 65 | section_00_source_test_normal_0058_fl_2_nos_3.wav,section_00_source_test_normal_0058_noAttribute.wav 66 | section_00_source_test_normal_0059_fl_0_nos_0.wav,section_00_source_test_normal_0059_noAttribute.wav 67 | section_00_source_test_normal_0063_fl_0_nos_2.wav,section_00_source_test_normal_0063_noAttribute.wav 68 | section_00_source_test_normal_0072_fl_2_nos_2.wav,section_00_source_test_normal_0072_noAttribute.wav 69 | section_00_source_test_normal_0074_fl_0_nos_0.wav,section_00_source_test_normal_0074_noAttribute.wav 70 | section_00_source_test_normal_0080_fl_2_nos_2.wav,section_00_source_test_normal_0080_noAttribute.wav 71 | section_00_source_test_normal_0084_fl_2_nos_2.wav,section_00_source_test_normal_0084_noAttribute.wav 72 | section_00_source_test_normal_0088_fl_0_nos_2.wav,section_00_source_test_normal_0088_noAttribute.wav 73 | section_00_source_test_normal_0096_fl_2_nos_0.wav,section_00_source_test_normal_0096_noAttribute.wav 74 | section_00_source_test_normal_0097_fl_0_nos_3.wav,section_00_source_test_normal_0097_noAttribute.wav 75 | section_00_source_test_normal_0100_fl_0_nos_3.wav,section_00_source_test_normal_0100_noAttribute.wav 76 | section_00_source_test_normal_0103_fl_2_nos_2.wav,section_00_source_test_normal_0103_noAttribute.wav 77 | section_00_source_test_normal_0105_fl_2_nos_3.wav,section_00_source_test_normal_0105_noAttribute.wav 78 | section_00_source_test_normal_0108_fl_2_nos_2.wav,section_00_source_test_normal_0108_noAttribute.wav 79 | section_00_source_test_normal_0110_fl_2_nos_2.wav,section_00_source_test_normal_0110_noAttribute.wav 80 | section_00_source_test_normal_0120_fl_0_nos_2.wav,section_00_source_test_normal_0120_noAttribute.wav 81 | section_00_source_test_normal_0123_fl_2_nos_0.wav,section_00_source_test_normal_0123_noAttribute.wav 82 | section_00_source_test_normal_0124_fl_0_nos_0.wav,section_00_source_test_normal_0124_noAttribute.wav 83 | section_00_source_test_normal_0126_fl_0_nos_2.wav,section_00_source_test_normal_0126_noAttribute.wav 84 | section_00_source_test_normal_0128_fl_0_nos_0.wav,section_00_source_test_normal_0128_noAttribute.wav 85 | section_00_source_test_normal_0132_fl_0_nos_0.wav,section_00_source_test_normal_0132_noAttribute.wav 86 | section_00_source_test_normal_0135_fl_0_nos_2.wav,section_00_source_test_normal_0135_noAttribute.wav 87 | section_00_source_test_normal_0136_fl_2_nos_0.wav,section_00_source_test_normal_0136_noAttribute.wav 88 | section_00_source_test_normal_0147_fl_0_nos_3.wav,section_00_source_test_normal_0147_noAttribute.wav 89 | section_00_source_test_normal_0152_fl_0_nos_0.wav,section_00_source_test_normal_0152_noAttribute.wav 90 | section_00_source_test_normal_0153_fl_2_nos_2.wav,section_00_source_test_normal_0153_noAttribute.wav 91 | section_00_source_test_normal_0154_fl_2_nos_2.wav,section_00_source_test_normal_0154_noAttribute.wav 92 | section_00_source_test_normal_0158_fl_0_nos_2.wav,section_00_source_test_normal_0158_noAttribute.wav 93 | section_00_source_test_normal_0162_fl_0_nos_3.wav,section_00_source_test_normal_0162_noAttribute.wav 94 | section_00_source_test_normal_0164_fl_2_nos_3.wav,section_00_source_test_normal_0164_noAttribute.wav 95 | section_00_source_test_normal_0171_fl_0_nos_3.wav,section_00_source_test_normal_0171_noAttribute.wav 96 | section_00_source_test_normal_0172_fl_2_nos_0.wav,section_00_source_test_normal_0172_noAttribute.wav 97 | section_00_source_test_normal_0177_fl_2_nos_3.wav,section_00_source_test_normal_0177_noAttribute.wav 98 | section_00_source_test_normal_0184_fl_2_nos_3.wav,section_00_source_test_normal_0184_noAttribute.wav 99 | section_00_source_test_normal_0191_fl_0_nos_2.wav,section_00_source_test_normal_0191_noAttribute.wav 100 | section_00_source_test_normal_0193_fl_0_nos_2.wav,section_00_source_test_normal_0193_noAttribute.wav 101 | section_00_source_test_normal_0199_fl_2_nos_0.wav,section_00_source_test_normal_0199_noAttribute.wav 102 | section_00_target_test_anomaly_0003_fl_1_nos_2.wav,section_00_target_test_anomaly_0003_noAttribute.wav 103 | section_00_target_test_anomaly_0004_fl_0_nos_1.wav,section_00_target_test_anomaly_0004_noAttribute.wav 104 | section_00_target_test_anomaly_0006_fl_1_nos_2.wav,section_00_target_test_anomaly_0006_noAttribute.wav 105 | section_00_target_test_anomaly_0007_fl_2_nos_1.wav,section_00_target_test_anomaly_0007_noAttribute.wav 106 | section_00_target_test_anomaly_0015_fl_1_nos_3.wav,section_00_target_test_anomaly_0015_noAttribute.wav 107 | section_00_target_test_anomaly_0018_fl_2_nos_1.wav,section_00_target_test_anomaly_0018_noAttribute.wav 108 | section_00_target_test_anomaly_0020_fl_1_nos_3.wav,section_00_target_test_anomaly_0020_noAttribute.wav 109 | section_00_target_test_anomaly_0025_fl_2_nos_1.wav,section_00_target_test_anomaly_0025_noAttribute.wav 110 | section_00_target_test_anomaly_0027_fl_0_nos_1.wav,section_00_target_test_anomaly_0027_noAttribute.wav 111 | section_00_target_test_anomaly_0031_fl_1_nos_3.wav,section_00_target_test_anomaly_0031_noAttribute.wav 112 | section_00_target_test_anomaly_0043_fl_0_nos_1.wav,section_00_target_test_anomaly_0043_noAttribute.wav 113 | section_00_target_test_anomaly_0045_fl_1_nos_1.wav,section_00_target_test_anomaly_0045_noAttribute.wav 114 | section_00_target_test_anomaly_0046_fl_1_nos_2.wav,section_00_target_test_anomaly_0046_noAttribute.wav 115 | section_00_target_test_anomaly_0047_fl_2_nos_1.wav,section_00_target_test_anomaly_0047_noAttribute.wav 116 | section_00_target_test_anomaly_0048_fl_1_nos_0.wav,section_00_target_test_anomaly_0048_noAttribute.wav 117 | section_00_target_test_anomaly_0052_fl_1_nos_2.wav,section_00_target_test_anomaly_0052_noAttribute.wav 118 | section_00_target_test_anomaly_0053_fl_1_nos_1.wav,section_00_target_test_anomaly_0053_noAttribute.wav 119 | section_00_target_test_anomaly_0057_fl_1_nos_3.wav,section_00_target_test_anomaly_0057_noAttribute.wav 120 | section_00_target_test_anomaly_0067_fl_2_nos_1.wav,section_00_target_test_anomaly_0067_noAttribute.wav 121 | section_00_target_test_anomaly_0085_fl_1_nos_3.wav,section_00_target_test_anomaly_0085_noAttribute.wav 122 | section_00_target_test_anomaly_0094_fl_1_nos_2.wav,section_00_target_test_anomaly_0094_noAttribute.wav 123 | section_00_target_test_anomaly_0104_fl_2_nos_1.wav,section_00_target_test_anomaly_0104_noAttribute.wav 124 | section_00_target_test_anomaly_0109_fl_1_nos_3.wav,section_00_target_test_anomaly_0109_noAttribute.wav 125 | section_00_target_test_anomaly_0111_fl_0_nos_1.wav,section_00_target_test_anomaly_0111_noAttribute.wav 126 | section_00_target_test_anomaly_0113_fl_1_nos_0.wav,section_00_target_test_anomaly_0113_noAttribute.wav 127 | section_00_target_test_anomaly_0117_fl_1_nos_0.wav,section_00_target_test_anomaly_0117_noAttribute.wav 128 | section_00_target_test_anomaly_0119_fl_0_nos_1.wav,section_00_target_test_anomaly_0119_noAttribute.wav 129 | section_00_target_test_anomaly_0122_fl_1_nos_1.wav,section_00_target_test_anomaly_0122_noAttribute.wav 130 | section_00_target_test_anomaly_0130_fl_0_nos_1.wav,section_00_target_test_anomaly_0130_noAttribute.wav 131 | section_00_target_test_anomaly_0131_fl_1_nos_0.wav,section_00_target_test_anomaly_0131_noAttribute.wav 132 | section_00_target_test_anomaly_0138_fl_0_nos_1.wav,section_00_target_test_anomaly_0138_noAttribute.wav 133 | section_00_target_test_anomaly_0140_fl_1_nos_0.wav,section_00_target_test_anomaly_0140_noAttribute.wav 134 | section_00_target_test_anomaly_0142_fl_1_nos_0.wav,section_00_target_test_anomaly_0142_noAttribute.wav 135 | section_00_target_test_anomaly_0144_fl_1_nos_1.wav,section_00_target_test_anomaly_0144_noAttribute.wav 136 | section_00_target_test_anomaly_0145_fl_1_nos_0.wav,section_00_target_test_anomaly_0145_noAttribute.wav 137 | section_00_target_test_anomaly_0151_fl_2_nos_1.wav,section_00_target_test_anomaly_0151_noAttribute.wav 138 | section_00_target_test_anomaly_0155_fl_1_nos_1.wav,section_00_target_test_anomaly_0155_noAttribute.wav 139 | section_00_target_test_anomaly_0157_fl_1_nos_1.wav,section_00_target_test_anomaly_0157_noAttribute.wav 140 | section_00_target_test_anomaly_0159_fl_1_nos_3.wav,section_00_target_test_anomaly_0159_noAttribute.wav 141 | section_00_target_test_anomaly_0166_fl_1_nos_1.wav,section_00_target_test_anomaly_0166_noAttribute.wav 142 | section_00_target_test_anomaly_0170_fl_2_nos_1.wav,section_00_target_test_anomaly_0170_noAttribute.wav 143 | section_00_target_test_anomaly_0173_fl_1_nos_0.wav,section_00_target_test_anomaly_0173_noAttribute.wav 144 | section_00_target_test_anomaly_0176_fl_1_nos_2.wav,section_00_target_test_anomaly_0176_noAttribute.wav 145 | section_00_target_test_anomaly_0181_fl_1_nos_2.wav,section_00_target_test_anomaly_0181_noAttribute.wav 146 | section_00_target_test_anomaly_0182_fl_1_nos_2.wav,section_00_target_test_anomaly_0182_noAttribute.wav 147 | section_00_target_test_anomaly_0183_fl_1_nos_2.wav,section_00_target_test_anomaly_0183_noAttribute.wav 148 | section_00_target_test_anomaly_0185_fl_1_nos_1.wav,section_00_target_test_anomaly_0185_noAttribute.wav 149 | section_00_target_test_anomaly_0187_fl_0_nos_1.wav,section_00_target_test_anomaly_0187_noAttribute.wav 150 | section_00_target_test_anomaly_0188_fl_1_nos_3.wav,section_00_target_test_anomaly_0188_noAttribute.wav 151 | section_00_target_test_anomaly_0194_fl_1_nos_1.wav,section_00_target_test_anomaly_0194_noAttribute.wav 152 | section_00_target_test_normal_0002_fl_0_nos_1.wav,section_00_target_test_normal_0002_noAttribute.wav 153 | section_00_target_test_normal_0005_fl_2_nos_1.wav,section_00_target_test_normal_0005_noAttribute.wav 154 | section_00_target_test_normal_0008_fl_1_nos_2.wav,section_00_target_test_normal_0008_noAttribute.wav 155 | section_00_target_test_normal_0009_fl_1_nos_1.wav,section_00_target_test_normal_0009_noAttribute.wav 156 | section_00_target_test_normal_0012_fl_1_nos_0.wav,section_00_target_test_normal_0012_noAttribute.wav 157 | section_00_target_test_normal_0014_fl_1_nos_3.wav,section_00_target_test_normal_0014_noAttribute.wav 158 | section_00_target_test_normal_0029_fl_1_nos_1.wav,section_00_target_test_normal_0029_noAttribute.wav 159 | section_00_target_test_normal_0030_fl_0_nos_1.wav,section_00_target_test_normal_0030_noAttribute.wav 160 | section_00_target_test_normal_0035_fl_2_nos_1.wav,section_00_target_test_normal_0035_noAttribute.wav 161 | section_00_target_test_normal_0036_fl_1_nos_2.wav,section_00_target_test_normal_0036_noAttribute.wav 162 | section_00_target_test_normal_0040_fl_1_nos_0.wav,section_00_target_test_normal_0040_noAttribute.wav 163 | section_00_target_test_normal_0041_fl_1_nos_0.wav,section_00_target_test_normal_0041_noAttribute.wav 164 | section_00_target_test_normal_0044_fl_1_nos_1.wav,section_00_target_test_normal_0044_noAttribute.wav 165 | section_00_target_test_normal_0050_fl_1_nos_1.wav,section_00_target_test_normal_0050_noAttribute.wav 166 | section_00_target_test_normal_0051_fl_1_nos_2.wav,section_00_target_test_normal_0051_noAttribute.wav 167 | section_00_target_test_normal_0060_fl_0_nos_1.wav,section_00_target_test_normal_0060_noAttribute.wav 168 | section_00_target_test_normal_0061_fl_1_nos_1.wav,section_00_target_test_normal_0061_noAttribute.wav 169 | section_00_target_test_normal_0064_fl_1_nos_1.wav,section_00_target_test_normal_0064_noAttribute.wav 170 | section_00_target_test_normal_0065_fl_1_nos_2.wav,section_00_target_test_normal_0065_noAttribute.wav 171 | section_00_target_test_normal_0070_fl_0_nos_1.wav,section_00_target_test_normal_0070_noAttribute.wav 172 | section_00_target_test_normal_0073_fl_1_nos_0.wav,section_00_target_test_normal_0073_noAttribute.wav 173 | section_00_target_test_normal_0075_fl_1_nos_0.wav,section_00_target_test_normal_0075_noAttribute.wav 174 | section_00_target_test_normal_0076_fl_1_nos_3.wav,section_00_target_test_normal_0076_noAttribute.wav 175 | section_00_target_test_normal_0077_fl_1_nos_0.wav,section_00_target_test_normal_0077_noAttribute.wav 176 | section_00_target_test_normal_0079_fl_1_nos_0.wav,section_00_target_test_normal_0079_noAttribute.wav 177 | section_00_target_test_normal_0082_fl_0_nos_1.wav,section_00_target_test_normal_0082_noAttribute.wav 178 | section_00_target_test_normal_0083_fl_1_nos_3.wav,section_00_target_test_normal_0083_noAttribute.wav 179 | section_00_target_test_normal_0098_fl_2_nos_1.wav,section_00_target_test_normal_0098_noAttribute.wav 180 | section_00_target_test_normal_0101_fl_0_nos_1.wav,section_00_target_test_normal_0101_noAttribute.wav 181 | section_00_target_test_normal_0106_fl_2_nos_1.wav,section_00_target_test_normal_0106_noAttribute.wav 182 | section_00_target_test_normal_0112_fl_2_nos_1.wav,section_00_target_test_normal_0112_noAttribute.wav 183 | section_00_target_test_normal_0115_fl_0_nos_1.wav,section_00_target_test_normal_0115_noAttribute.wav 184 | section_00_target_test_normal_0116_fl_1_nos_1.wav,section_00_target_test_normal_0116_noAttribute.wav 185 | section_00_target_test_normal_0118_fl_2_nos_1.wav,section_00_target_test_normal_0118_noAttribute.wav 186 | section_00_target_test_normal_0121_fl_1_nos_2.wav,section_00_target_test_normal_0121_noAttribute.wav 187 | section_00_target_test_normal_0133_fl_1_nos_1.wav,section_00_target_test_normal_0133_noAttribute.wav 188 | section_00_target_test_normal_0134_fl_1_nos_2.wav,section_00_target_test_normal_0134_noAttribute.wav 189 | section_00_target_test_normal_0139_fl_1_nos_3.wav,section_00_target_test_normal_0139_noAttribute.wav 190 | section_00_target_test_normal_0148_fl_1_nos_1.wav,section_00_target_test_normal_0148_noAttribute.wav 191 | section_00_target_test_normal_0149_fl_0_nos_1.wav,section_00_target_test_normal_0149_noAttribute.wav 192 | section_00_target_test_normal_0160_fl_1_nos_0.wav,section_00_target_test_normal_0160_noAttribute.wav 193 | section_00_target_test_normal_0161_fl_2_nos_1.wav,section_00_target_test_normal_0161_noAttribute.wav 194 | section_00_target_test_normal_0167_fl_1_nos_2.wav,section_00_target_test_normal_0167_noAttribute.wav 195 | section_00_target_test_normal_0174_fl_1_nos_3.wav,section_00_target_test_normal_0174_noAttribute.wav 196 | section_00_target_test_normal_0175_fl_1_nos_2.wav,section_00_target_test_normal_0175_noAttribute.wav 197 | section_00_target_test_normal_0179_fl_1_nos_3.wav,section_00_target_test_normal_0179_noAttribute.wav 198 | section_00_target_test_normal_0189_fl_1_nos_2.wav,section_00_target_test_normal_0189_noAttribute.wav 199 | section_00_target_test_normal_0190_fl_1_nos_3.wav,section_00_target_test_normal_0190_noAttribute.wav 200 | section_00_target_test_normal_0195_fl_1_nos_3.wav,section_00_target_test_normal_0195_noAttribute.wav 201 | section_00_target_test_normal_0198_fl_2_nos_1.wav,section_00_target_test_normal_0198_noAttribute.wav 202 | -------------------------------------------------------------------------------- /datasets/loader_common.py: -------------------------------------------------------------------------------- 1 | ######################################################################## 2 | # import python-library 3 | ######################################################################## 4 | # default 5 | import glob 6 | import argparse 7 | import random 8 | import sys 9 | import os 10 | import itertools 11 | import re 12 | import pathlib 13 | 14 | # additional 15 | import numpy as np 16 | import librosa 17 | import librosa.core 18 | import librosa.feature 19 | import yaml 20 | import urllib.request 21 | import urllib.error 22 | import zipfile 23 | import shutil 24 | import time 25 | import fasteners 26 | import pickle 27 | import pickletools 28 | import time 29 | import datetime 30 | from enum import Enum, auto 31 | from tools.rename_eval_wav import copy_wav as rename_wav 32 | ######################################################################## 33 | 34 | 35 | ######################################################################## 36 | # setup STD I/O 37 | ######################################################################## 38 | """ 39 | Standard output is logged in "baseline.log". 40 | """ 41 | import logging 42 | 43 | logging.basicConfig(level=logging.DEBUG, filename="baseline.log") 44 | logger = logging.getLogger(' ') 45 | handler = logging.StreamHandler() 46 | formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') 47 | handler.setFormatter(formatter) 48 | logger.addHandler(handler) 49 | 50 | 51 | ######################################################################## 52 | 53 | 54 | ######################################################################## 55 | # version 56 | ######################################################################## 57 | __versions__ = "1.0.0" 58 | ######################################################################## 59 | 60 | 61 | ######################################################################## 62 | # download dataset parameter 63 | ######################################################################## 64 | DOWNLOAD_PATH_YAML_DICT = { 65 | "DCASE2025T2":"datasets/download_path_2025.yaml", 66 | "DCASE2024T2":"datasets/download_path_2024.yaml", 67 | "DCASE2023T2":"datasets/download_path_2023.yaml", 68 | "legacy":"datasets/download_path_legacy.yaml", 69 | } 70 | ######################################################################## 71 | 72 | 73 | ######################################################################## 74 | # load parameter.yaml 75 | ######################################################################## 76 | # def yaml_load(): 77 | # with open("baseline.yaml") as stream: 78 | # param = yaml.safe_load(stream) 79 | # return param 80 | 81 | ######################################################################## 82 | 83 | 84 | ######################################################################## 85 | # file I/O 86 | ######################################################################## 87 | # wav file input 88 | def file_load(wav_name, mono=False): 89 | """ 90 | load .wav file. 91 | 92 | wav_name : str 93 | target .wav file 94 | mono : boolean 95 | When load a multi channels file and this param True, the returned data will be merged for mono data 96 | 97 | return : numpy.array( float ) 98 | """ 99 | try: 100 | return librosa.load(wav_name, sr=None, mono=mono) 101 | except: 102 | logger.error("file_broken or not exists!! : {}".format(wav_name)) 103 | 104 | 105 | ######################################################################## 106 | 107 | 108 | ######################################################################## 109 | # feature extractor 110 | ######################################################################## 111 | def file_to_vectors(file_name, 112 | n_mels=64, 113 | n_frames=5, 114 | n_fft=1024, 115 | hop_length=512, 116 | power=2.0, 117 | fmax=None, 118 | fmin=None, 119 | win_length=None): 120 | """ 121 | convert file_name to a vector array. 122 | 123 | file_name : str 124 | target .wav file 125 | 126 | return : numpy.array( numpy.array( float ) ) 127 | vector array 128 | * dataset.shape = (dataset_size, feature_vector_length) 129 | """ 130 | # calculate the number of dimensions 131 | dims = n_mels * n_frames 132 | 133 | # generate melspectrogram using librosa 134 | y, sr = file_load(file_name, mono=True) 135 | mel_spectrogram = librosa.feature.melspectrogram(y=y, 136 | sr=sr, 137 | n_fft=n_fft, 138 | hop_length=hop_length, 139 | n_mels=n_mels, 140 | power=power, 141 | fmax=fmax, 142 | fmin=fmin, 143 | win_length=win_length) 144 | 145 | # convert melspectrogram to log mel energies 146 | log_mel_spectrogram = 20.0 / power * np.log10(np.maximum(mel_spectrogram, sys.float_info.epsilon)) 147 | 148 | # calculate total vector size 149 | n_vectors = len(log_mel_spectrogram[0, :]) - n_frames + 1 150 | 151 | # skip too short clips 152 | if n_vectors < 1: 153 | return np.empty((0, dims)) 154 | 155 | # generate feature vectors by concatenating multi frames 156 | vectors = np.zeros((n_vectors, dims)) 157 | for t in range(n_frames): 158 | vectors[:, n_mels * t : n_mels * (t + 1)] = log_mel_spectrogram[:, t : t + n_vectors].T 159 | 160 | return vectors 161 | 162 | 163 | ######################################################################## 164 | 165 | 166 | ######################################################################## 167 | # get directory paths according to mode 168 | ######################################################################## 169 | def select_dirs(param, mode): 170 | """ 171 | param : dict 172 | baseline.yaml data 173 | 174 | return : 175 | if active type the development : 176 | dirs : list [ str ] 177 | load base directory list of dev_data 178 | if active type the evaluation : 179 | dirs : list [ str ] 180 | load base directory list of eval_data 181 | """ 182 | if mode: 183 | logger.info("load_directory <- development") 184 | query = os.path.abspath("{base}/*".format(base=param["dev_directory"])) 185 | else: 186 | logger.info("load_directory <- evaluation") 187 | query = os.path.abspath("{base}/*".format(base=param["eval_directory"])) 188 | dirs = sorted(glob.glob(query)) 189 | dirs = [f for f in dirs if os.path.isdir(f)] 190 | return dirs 191 | 192 | 193 | ######################################################################## 194 | 195 | 196 | ######################################################################## 197 | # get machine IDs 198 | ######################################################################## 199 | def get_section_names(target_dir, 200 | dir_name, 201 | ext="wav"): 202 | """ 203 | target_dir : str 204 | base directory path 205 | dir_name : str 206 | sub directory name 207 | ext : str (default="wav) 208 | file extension of audio files 209 | 210 | return : 211 | section_names : list [ str ] 212 | list of section names extracted from the names of audio files 213 | """ 214 | # create test files 215 | query = os.path.abspath("{target_dir}/{dir_name}/*.{ext}".format(target_dir=target_dir, dir_name=dir_name, ext=ext)) 216 | file_paths = sorted(glob.glob(query)) 217 | # extract section names 218 | section_names = sorted(list(set(itertools.chain.from_iterable( 219 | [re.findall('section_[0-9][0-9]', ext_id) for ext_id in file_paths])))) 220 | return section_names 221 | 222 | 223 | ######################################################################## 224 | 225 | 226 | ######################################################################## 227 | # get the list of wave file paths 228 | ######################################################################## 229 | def file_list_generator(target_dir, 230 | section_name, 231 | unique_section_names, 232 | dir_name, 233 | mode, 234 | train, 235 | prefix_normal="normal", 236 | prefix_anomaly="anomaly", 237 | ext="wav"): 238 | """ 239 | target_dir : str 240 | base directory path 241 | section_name : str 242 | section name of audio file in <> directory 243 | dir_name : str 244 | sub directory name 245 | prefix_normal : str (default="normal") 246 | normal directory name 247 | prefix_anomaly : str (default="anomaly") 248 | anomaly directory name 249 | ext : str (default="wav") 250 | file extension of audio files 251 | 252 | return : 253 | if the mode is "development": 254 | files : list [ str ] 255 | audio file list 256 | labels : list [ boolean ] 257 | label info. list 258 | * normal/anomaly = 0/1 259 | if the mode is "evaluation": 260 | files : list [ str ] 261 | audio file list 262 | """ 263 | logger.info("target_dir : {}".format(target_dir + "_" + section_name)) 264 | condition_array = np.eye(len(unique_section_names)) 265 | 266 | # development 267 | if mode: 268 | query = os.path.abspath("{target_dir}/{dir_name}/{section_name}_*_{prefix_normal}_*.{ext}".format(target_dir=target_dir, 269 | dir_name=dir_name, 270 | section_name=section_name, 271 | prefix_normal=prefix_normal, 272 | ext=ext)) 273 | normal_files = sorted(glob.glob(query)) 274 | if len(normal_files) == 0: 275 | normal_files = sorted( 276 | glob.glob("{dir}/{dir_name}/{prefix_normal}_{id_name}*.{ext}".format(dir=target_dir, 277 | dir_name=dir_name, 278 | prefix_normal=prefix_normal, 279 | id_name=section_name, 280 | ext=ext))) 281 | normal_labels = np.zeros(len(normal_files)) 282 | 283 | query = os.path.abspath("{target_dir}/{dir_name}/{section_name}_*_{prefix_normal}_*.{ext}".format(target_dir=target_dir, 284 | dir_name=dir_name, 285 | section_name=section_name, 286 | prefix_normal=prefix_anomaly, 287 | ext=ext)) 288 | anomaly_files = sorted(glob.glob(query)) 289 | if len(anomaly_files) == 0: 290 | anomaly_files = sorted( 291 | glob.glob("{dir}/{dir_name}/{prefix_anomaly}_{id_name}*.{ext}".format(dir=target_dir, 292 | dir_name=dir_name, 293 | prefix_anomaly=prefix_anomaly, 294 | id_name=section_name, 295 | ext=ext))) 296 | anomaly_labels = np.ones(len(anomaly_files)) 297 | 298 | files = np.concatenate((normal_files, anomaly_files), axis=0) 299 | labels = np.concatenate((normal_labels, anomaly_labels), axis=0) 300 | 301 | logger.info("#files : {num}".format(num=len(files))) 302 | if len(files) == 0: 303 | logger.exception("no_wav_file!!") 304 | print("\n========================================") 305 | 306 | # evaluation 307 | else: 308 | query = os.path.abspath("{target_dir}/{dir_name}/*{section_name}_*.{ext}".format(target_dir=target_dir, 309 | dir_name=dir_name, 310 | section_name=section_name, 311 | ext=ext)) 312 | files = sorted(glob.glob(query)) 313 | if train: 314 | normal_files = sorted(glob.glob(query)) 315 | labels = np.zeros(len(normal_files)) 316 | else: 317 | labels = None 318 | logger.info("#files : {num}".format(num=len(files))) 319 | if len(files) == 0: 320 | logger.exception("no_wav_file!!") 321 | print("\n=========================================") 322 | 323 | condition = [] 324 | for _, file in enumerate(files): 325 | for j, unique_section_name in enumerate(unique_section_names): 326 | if unique_section_name in file: 327 | condition.append(condition_array[j]) 328 | 329 | return files, labels, condition 330 | ######################################################################## 331 | 332 | def download_raw_data( 333 | target_dir, 334 | dir_name, 335 | machine_type, 336 | data_type, 337 | dataset, 338 | root 339 | ): 340 | if dataset == "DCASE2025T2": 341 | download_path_yaml = DOWNLOAD_PATH_YAML_DICT["DCASE2025T2"] 342 | elif dataset == "DCASE2024T2": 343 | download_path_yaml = DOWNLOAD_PATH_YAML_DICT["DCASE2024T2"] 344 | elif dataset == "DCASE2023T2": 345 | download_path_yaml = DOWNLOAD_PATH_YAML_DICT["DCASE2023T2"] 346 | else: 347 | download_path_yaml = DOWNLOAD_PATH_YAML_DICT["legacy"] 348 | 349 | if not os.path.exists(target_dir): 350 | os.makedirs(target_dir, exist_ok=True) 351 | 352 | with open(download_path_yaml, "r") as f: 353 | file_url = yaml.safe_load(f)[dataset] 354 | 355 | lock_file_path = get_lockfile_path(target_dir=target_dir) 356 | if os.path.exists(f"{target_dir}/{dir_name}") and not os.path.isfile(lock_file_path): 357 | print(f"{target_dir}/{dir_name} is already downloaded") 358 | return 359 | print(f"{target_dir}/{dir_name} is not directory.\nperform dataset download.") 360 | 361 | lock = fasteners.InterProcessReaderWriterLock(lock_file_path) 362 | try: 363 | lock.acquire_write_lock() 364 | except: 365 | print(f"{target_dir}/{dir_name} is already downloaded") 366 | return 367 | 368 | if os.path.exists(f"{target_dir}/{dir_name}"): 369 | print(f"{target_dir}/{dir_name} is already downloaded") 370 | release_write_lock( 371 | lock=lock, 372 | lock_file_path=lock_file_path, 373 | ) 374 | return 375 | 376 | for i in np.arange(len(file_url[machine_type][data_type])): 377 | zip_file_basename = os.path.basename(file_url[machine_type][data_type][i]) 378 | zip_file_path = f"{target_dir}/../{zip_file_basename}" 379 | try: 380 | if not zipfile.is_zipfile(zip_file_path): 381 | print(f"Downloading...\n\tURL: {file_url[machine_type][data_type][i]}\r\tDownload: {zip_file_path}") 382 | urllib.request.urlretrieve( 383 | file_url[machine_type][data_type][i], 384 | zip_file_path, 385 | urllib_progress 386 | ) 387 | except urllib.error.URLError as e: 388 | print(e) 389 | print("retry dataset download") 390 | download_raw_data( 391 | target_dir, 392 | dir_name, 393 | machine_type, 394 | data_type, 395 | dataset, 396 | root 397 | ) 398 | return 399 | 400 | with zipfile.ZipFile(zip_file_path, "r") as obj_zip: 401 | zip_infos = obj_zip.infolist() 402 | for zip_info in zip_infos: 403 | if zip_info.is_dir(): 404 | os.makedirs(f"{target_dir}/../{zip_info.filename}", exist_ok=True) 405 | elif not os.path.exists(f"{target_dir}/../{zip_info.filename}"): 406 | sys.stdout.write(f"\runzip: {target_dir}/../{zip_info.filename}") 407 | obj_zip.extract(zip_info, f"{target_dir}/../") 408 | print("\n") 409 | 410 | if dataset == "DCASE2021T2": 411 | test_data_path = f"{target_dir}/test" 412 | split_data_path_list = [ 413 | f"{target_dir}/source_test", 414 | f"{target_dir}/target_test", 415 | ] 416 | os.makedirs(test_data_path, exist_ok=True) 417 | for split_data_path in split_data_path_list: 418 | shutil.copytree(split_data_path, test_data_path, dirs_exist_ok=True) 419 | 420 | if data_type == "eval" and dataset != "DCASE2025T2": 421 | rename_wav( 422 | dataset_parent_dir=root, 423 | dataset_type=dataset, 424 | ) 425 | 426 | release_write_lock( 427 | lock=lock, 428 | lock_file_path=lock_file_path 429 | ) 430 | return 431 | 432 | def urllib_progress (block_count, block_size, total_size): 433 | progress_value = block_count * block_size / total_size * 100 434 | sys.stdout.write(f"\r{block_count*block_size/(1024**2):.2f}MB / {total_size/(1024**2):.2f}MB ({progress_value:.2f}%%)") 435 | 436 | def get_lockfile_path(target_dir): 437 | return f"{target_dir}/lockfile" 438 | 439 | def release_write_lock(lock, lock_file_path): 440 | print(f"{datetime.datetime.now()}\trelease write lock : {lock_file_path}") 441 | lock.release_write_lock() 442 | if os.path.isfile(lock_file_path): 443 | try: 444 | os.remove(lock_file_path) 445 | except OSError: 446 | print(f"can not remove {lock_file_path}") 447 | 448 | def release_read_lock(lock, lock_file_path): 449 | print(f"{datetime.datetime.now()}\trelease read lock : {lock_file_path}") 450 | lock.release_read_lock() 451 | if os.path.isfile(lock_file_path): 452 | try: 453 | os.remove(lock_file_path) 454 | except OSError: 455 | print(f"can not remove {lock_file_path}") 456 | 457 | def is_enabled_pickle(pickle_path): 458 | opcodes = [] 459 | with open(pickle_path, "rb") as f: 460 | pickle = f.read() 461 | output = pickletools.genops(pickle=pickle) 462 | for opcode in output: 463 | opcodes.append(opcode[0]) 464 | return ("PROTO","STOP") == (opcodes[0].name, opcodes[-1].name) 465 | 466 | ######################################################################## 467 | # get machine type and section id in yaml 468 | ######################################################################## 469 | YAML_PATH = { 470 | "legacy":"datasets/machine_type_legacy.yaml", 471 | "DCASE2023T2_dev":"datasets/machine_type_2023_dev.yaml", 472 | "DCASE2023T2_eval":"datasets/machine_type_2023_eval.yaml", 473 | "DCASE2024T2_dev":"datasets/machine_type_2024_dev.yaml", 474 | "DCASE2024T2_eval":"datasets/machine_type_2024_eval.yaml", 475 | "DCASE2025T2_dev":"datasets/machine_type_2025_dev.yaml", 476 | "DCASE2025T2_eval":"datasets/machine_type_2025_eval.yaml", 477 | } 478 | 479 | def get_machine_type_dict(dataset_name, mode=True): 480 | if dataset_name in ["DCASE2020T2", "DCASE2021T2", "DCASE2022T2"]: 481 | yaml_path = YAML_PATH["legacy"] 482 | elif dataset_name == "DCASE2023T2" and mode: 483 | yaml_path = YAML_PATH["DCASE2023T2_dev"] 484 | elif dataset_name == "DCASE2023T2" and not mode: 485 | yaml_path = YAML_PATH["DCASE2023T2_eval"] 486 | elif dataset_name == "DCASE2024T2" and mode: 487 | yaml_path = YAML_PATH["DCASE2024T2_dev"] 488 | elif dataset_name == "DCASE2024T2" and not mode: 489 | yaml_path = YAML_PATH["DCASE2024T2_eval"] 490 | elif dataset_name == "DCASE2025T2" and mode: 491 | yaml_path = YAML_PATH["DCASE2025T2_dev"] 492 | elif dataset_name == "DCASE2025T2" and not mode: 493 | yaml_path = YAML_PATH["DCASE2025T2_eval"] 494 | else: 495 | raise KeyError() 496 | 497 | with open(yaml_path, "r") as f: 498 | machine_type_dict = yaml.safe_load(f) 499 | return machine_type_dict[dataset_name] -------------------------------------------------------------------------------- /datasets/machine_type_2023_dev.yaml: -------------------------------------------------------------------------------- 1 | DCASE2023T2: 2 | machine_type: 3 | ToyCar: 4 | dev: 5 | - "00" 6 | ToyTrain: 7 | dev: 8 | - "00" 9 | fan: 10 | dev: 11 | - "00" 12 | gearbox: 13 | dev: 14 | - "00" 15 | bearing: 16 | dev: 17 | - "00" 18 | slider: 19 | dev: 20 | - "00" 21 | valve: 22 | dev: 23 | - "00" 24 | section_keyword: section -------------------------------------------------------------------------------- /datasets/machine_type_2023_eval.yaml: -------------------------------------------------------------------------------- 1 | DCASE2023T2: 2 | machine_type: 3 | ToyDrone: 4 | eval: 5 | - "00" 6 | ToyNscale: 7 | eval: 8 | - "00" 9 | ToyTank: 10 | eval: 11 | - "00" 12 | Vacuum: 13 | eval: 14 | - "00" 15 | bandsaw: 16 | eval: 17 | - "00" 18 | grinder: 19 | eval: 20 | - "00" 21 | shaker: 22 | eval: 23 | - "00" 24 | section_keyword: section -------------------------------------------------------------------------------- /datasets/machine_type_2024_dev.yaml: -------------------------------------------------------------------------------- 1 | DCASE2024T2: 2 | machine_type: 3 | ToyCar: 4 | dev: 5 | - "00" 6 | ToyTrain: 7 | dev: 8 | - "00" 9 | fan: 10 | dev: 11 | - "00" 12 | gearbox: 13 | dev: 14 | - "00" 15 | bearing: 16 | dev: 17 | - "00" 18 | slider: 19 | dev: 20 | - "00" 21 | valve: 22 | dev: 23 | - "00" 24 | section_keyword: section -------------------------------------------------------------------------------- /datasets/machine_type_2024_eval.yaml: -------------------------------------------------------------------------------- 1 | DCASE2024T2: 2 | machine_type: 3 | 3DPrinter: 4 | eval: 5 | - "00" 6 | AirCompressor: 7 | eval: 8 | - "00" 9 | Scanner: 10 | eval: 11 | - "00" 12 | ToyCircuit: 13 | eval: 14 | - "00" 15 | HoveringDrone: 16 | eval: 17 | - "00" 18 | HairDryer: 19 | eval: 20 | - "00" 21 | ToothBrush: 22 | eval: 23 | - "00" 24 | RoboticArm: 25 | eval: 26 | - "00" 27 | BrushlessMotor: 28 | eval: 29 | - "00" 30 | section_keyword: section 31 | -------------------------------------------------------------------------------- /datasets/machine_type_2025_dev.yaml: -------------------------------------------------------------------------------- 1 | DCASE2025T2: 2 | machine_type: 3 | ToyCar: 4 | dev: 5 | - "00" 6 | ToyTrain: 7 | dev: 8 | - "00" 9 | bearing: 10 | dev: 11 | - "00" 12 | fan: 13 | dev: 14 | - "00" 15 | gearbox: 16 | dev: 17 | - "00" 18 | slider: 19 | dev: 20 | - "00" 21 | valve: 22 | dev: 23 | - "00" 24 | section_keyword: section -------------------------------------------------------------------------------- /datasets/machine_type_2025_eval.yaml: -------------------------------------------------------------------------------- 1 | DCASE2025T2: 2 | machine_type: 3 | ToyRCCar: 4 | eval: 5 | - "00" 6 | ToyPet: 7 | eval: 8 | - "00" 9 | HomeCamera: 10 | eval: 11 | - "00" 12 | AutoTrash: 13 | eval: 14 | - "00" 15 | Polisher: 16 | eval: 17 | - "00" 18 | ScrewFeeder: 19 | eval: 20 | - "00" 21 | BandSealer: 22 | eval: 23 | - "00" 24 | CoffeeGrinder: 25 | eval: 26 | - "00" 27 | section_keyword: section -------------------------------------------------------------------------------- /datasets/machine_type_legacy.yaml: -------------------------------------------------------------------------------- 1 | DCASE2020T2: 2 | machine_type: 3 | fan: 4 | dev: 5 | - "00" 6 | - "02" 7 | - "04" 8 | - "06" 9 | eval: 10 | - "01" 11 | - "03" 12 | - "05" 13 | pump: 14 | dev: 15 | - "00" 16 | - "02" 17 | - "04" 18 | - "06" 19 | eval: 20 | - "01" 21 | - "03" 22 | - "05" 23 | slider: 24 | dev: 25 | - "00" 26 | - "02" 27 | - "04" 28 | - "06" 29 | eval: 30 | - "01" 31 | - "03" 32 | - "05" 33 | valve: 34 | dev: 35 | - "00" 36 | - "02" 37 | - "04" 38 | - "06" 39 | eval: 40 | - "01" 41 | - "03" 42 | - "05" 43 | ToyCar: 44 | dev: 45 | - "01" 46 | - "02" 47 | - "03" 48 | - "04" 49 | eval: 50 | - "05" 51 | - "06" 52 | - "07" 53 | ToyConveyor: 54 | dev: 55 | - "01" 56 | - "02" 57 | - "03" 58 | eval: 59 | - "04" 60 | - "05" 61 | - "06" 62 | section_keyword: id 63 | 64 | DCASE2021T2: 65 | machine_type: 66 | ToyCar: 67 | dev: 68 | - "00" 69 | - "01" 70 | - "02" 71 | eval: 72 | - "03" 73 | - "04" 74 | - "05" 75 | ToyTrain: 76 | dev: 77 | - "00" 78 | - "01" 79 | - "02" 80 | eval: 81 | - "03" 82 | - "04" 83 | - "05" 84 | fan: 85 | dev: 86 | - "00" 87 | - "01" 88 | - "02" 89 | eval: 90 | - "03" 91 | - "04" 92 | - "05" 93 | gearbox: 94 | dev: 95 | - "00" 96 | - "01" 97 | - "02" 98 | eval: 99 | - "03" 100 | - "04" 101 | - "05" 102 | slider: 103 | dev: 104 | - "00" 105 | - "01" 106 | - "02" 107 | eval: 108 | - "03" 109 | - "04" 110 | - "05" 111 | pump: 112 | dev: 113 | - "00" 114 | - "01" 115 | - "02" 116 | eval: 117 | - "03" 118 | - "04" 119 | - "05" 120 | valve: 121 | dev: 122 | - "00" 123 | - "01" 124 | - "02" 125 | eval: 126 | - "03" 127 | - "04" 128 | - "05" 129 | section_keyword: section 130 | 131 | DCASE2022T2: 132 | machine_type: 133 | ToyCar: 134 | dev: 135 | - "00" 136 | - "01" 137 | - "02" 138 | eval: 139 | - "03" 140 | - "04" 141 | - "05" 142 | ToyTrain: 143 | dev: 144 | - "00" 145 | - "01" 146 | - "02" 147 | eval: 148 | - "03" 149 | - "04" 150 | - "05" 151 | fan: 152 | dev: 153 | - "00" 154 | - "01" 155 | - "02" 156 | eval: 157 | - "03" 158 | - "04" 159 | - "05" 160 | gearbox: 161 | dev: 162 | - "00" 163 | - "01" 164 | - "02" 165 | eval: 166 | - "03" 167 | - "04" 168 | - "05" 169 | bearing: 170 | dev: 171 | - "00" 172 | - "01" 173 | - "02" 174 | eval: 175 | - "03" 176 | - "04" 177 | - "05" 178 | slider: 179 | dev: 180 | - "00" 181 | - "01" 182 | - "02" 183 | eval: 184 | - "03" 185 | - "04" 186 | - "05" 187 | valve: 188 | dev: 189 | - "00" 190 | - "01" 191 | - "02" 192 | eval: 193 | - "03" 194 | - "04" 195 | - "05" 196 | section_keyword: section 197 | -------------------------------------------------------------------------------- /dockerfile: -------------------------------------------------------------------------------- 1 | FROM pytorch/pytorch:2.6.0-cuda11.8-cudnn9-runtime 2 | 3 | ARG DEBIAN_FRONTEND=noninteractive 4 | 5 | RUN apt update && apt-get --yes install libsndfile1 6 | 7 | ADD requirements.txt ./ 8 | RUN pip install -U pip 9 | RUN pip install -r requirements.txt 10 | 11 | ARG USERNAME 12 | ARG GROUPNAME 13 | ARG UID 14 | ARG GID 15 | RUN groupadd -g $GID $GROUPNAME && \ 16 | useradd -m -s /bin/bash -u $UID -g $GID $USERNAME 17 | USER $USERNAME 18 | -------------------------------------------------------------------------------- /logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /models/checkpoint/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /models/saved_model/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /networks/base_model.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import os 3 | from pathlib import Path 4 | import scipy 5 | import torch 6 | import sys 7 | import numpy as np 8 | import json 9 | import pandas as pd 10 | import shutil 11 | 12 | from tools.plot_time_frequency import TimeFrequencyFigData 13 | from datasets.datasets import Datasets 14 | 15 | class BaseModel(object): 16 | def __init__(self, args, train, test): 17 | self.args = args 18 | print("selected gpu id:{}".format(args.gpu_id)) 19 | self.device = torch.device("cuda" if args.cuda else "cpu",args.gpu_id[0]) 20 | print(self.device) 21 | try: 22 | self.data = Datasets(self.args.dataset).data(self.args) 23 | except Exception as e: 24 | print('dataset "{}" is not supported'.format(self.args.dataset)) 25 | print("please set another name \n{}".format(Datasets.show_list())) 26 | raise e 27 | self.train_loader = self.data.train_loader 28 | self.valid_loader = self.data.valid_loader 29 | self.test_loader = self.data.test_loader 30 | 31 | self.epoch = 0 32 | self.model = self.init_model() 33 | 34 | self.export_dir = f"{self.args.export_dir}" if self.args.export_dir else "" 35 | self.result_dir = Path(f"{args.result_directory}/dev_data/{self.export_dir}_{args.score}/") 36 | self.result_dir.mkdir(parents=True, exist_ok=True) 37 | self.eval_data_result_dir = Path(f"{args.result_directory}/eval_data/{self.export_dir}_{args.score}/") 38 | self.eval_data_result_dir.mkdir(parents=True, exist_ok=True) 39 | self.model_name_suffix = "_"+self.args.model_name_suffix if self.args.model_name_suffix else "" 40 | self.eval_suffix = "_Eval" if self.args.eval else "" 41 | base_name = f"{self.export_dir}/{self.args.model}_{self.args.dataset}{self.model_name_suffix}{self.eval_suffix}_seed{self.args.seed}" 42 | self.checkpoint_dir = f"models/checkpoint/{base_name}" 43 | Path(self.checkpoint_dir).mkdir(parents=True, exist_ok=True) 44 | self.checkpoint_path = f"{self.checkpoint_dir}/checkpoint.tar" 45 | Path(f"models/checkpoint/{self.export_dir}").mkdir(parents=True, exist_ok=True) 46 | self.logs_dir = Path(f"logs/{base_name}") 47 | self.logs_dir.mkdir(parents=True, exist_ok=True) 48 | self.log_path = self.logs_dir / "log.csv" 49 | 50 | log_data = self.get_log_header() 51 | if (train and not self.args.restart): 52 | print(f"Generate blank log -> {self.log_path}") 53 | np.savetxt(self.log_path,[log_data],fmt="%s") 54 | 55 | # select using checkpoint file 56 | if self.args.checkpoint_path: 57 | checkpoint_path = self.args.checkpoint_path 58 | saved_log_path = Path(f"logs") 59 | for dir in Path(os.path.dirname(checkpoint_path)).parts[2:]: 60 | saved_log_path /= dir 61 | saved_log_path /= "log.csv" 62 | if os.path.exists(saved_log_path): 63 | print(f"copy log: {saved_log_path}\n\t->{self.log_path}") 64 | shutil.copyfile(saved_log_path, self.log_path) 65 | else: 66 | print(f"Generate blank log: {self.log_path}") 67 | np.savetxt(self.log_path,[log_data],fmt="%s") 68 | else: 69 | checkpoint_path = self.checkpoint_path 70 | 71 | # load checkpoint 72 | self.optim_state_dict = None 73 | if self.args.restart: 74 | if os.path.exists(checkpoint_path): 75 | print(f"load checkpoint -> {checkpoint_path}") 76 | checkpoint = torch.load(checkpoint_path) 77 | self.load_state_dict(checkpoint=checkpoint) 78 | self.optim_state_dict = self.load_optim_state_dict(checkpoint=checkpoint) 79 | if os.path.exists(self.log_path): 80 | print(f"log reindex: {self.log_path}") 81 | log_data = pd.read_csv(self.log_path).reindex(columns=log_data.split(',')).fillna(0) 82 | log_data.to_csv(self.log_path, index=False) 83 | else : 84 | print(f"not found -> {checkpoint_path}") 85 | np.savetxt(self.log_path,[log_data],fmt="%s") 86 | 87 | self.model.to(self.device) 88 | self.model_dir = Path(f"models/saved_model/{self.export_dir}/") 89 | self.model_dir.mkdir(parents=True, exist_ok=True) 90 | self.model_path = self.model_dir/f"{self.args.model}_{self.args.dataset}{self.model_name_suffix}{self.eval_suffix}_seed{self.args.seed}.pth" 91 | self.score_distr_file_path = self.model_dir/f"score_distr_{self.args.model}_{self.args.dataset}{self.model_name_suffix}{self.eval_suffix}_seed{self.args.seed}.pickle" 92 | self.history_img = self.model_dir/f"history_{self.args.model}_{self.args.dataset}{self.model_name_suffix}{self.eval_suffix}_seed{self.args.seed}.png" 93 | 94 | self.tf_figdata = TimeFrequencyFigData( 95 | max_imgs=4, 96 | max_extract=1, 97 | frames=args.frames, 98 | frame_hop_length=args.frame_hop_length, 99 | shape=(self.data.channel, self.data.width, self.data.height) 100 | ) 101 | 102 | self.result_column_dict = { 103 | "single_domain":["section", "AUC", "pAUC", "precision", "recall", "F1 score"], 104 | "source_target":["section", "AUC (source)", "AUC (target)", "pAUC", "pAUC (source)", "pAUC (target)", 105 | "precision (source)", "precision (target)", "recall (source)", "recall (target)", 106 | "F1 score (source)", "F1 score (target)"] 107 | } 108 | 109 | # output parameter to json 110 | self.args_path = f"{self.checkpoint_dir}/args.json" 111 | tf = open(self.args_path, "w") 112 | json.dump(vars(self.args), tf, indent=2, ensure_ascii=False) 113 | print(f"save args -> {self.args_path}") 114 | tf.close() 115 | 116 | def init_model(self): 117 | pass 118 | 119 | def get_log_header(self): 120 | return "loss,loss_var,time" 121 | 122 | def load_state_dict(self, checkpoint): 123 | pretrain_net_dict = checkpoint['model_state_dict'] 124 | net_dict = self.model.state_dict() 125 | net_dict.update(pretrain_net_dict) 126 | self.model.load_state_dict(net_dict) 127 | self.epoch = checkpoint['epoch'] 128 | self.loss = checkpoint['loss'] 129 | 130 | def load_optim_state_dict(self, checkpoint, key='optimizer_state_dict'): 131 | return checkpoint[key] 132 | 133 | def fit_anomaly_score_distribution(self, y_pred, score_distr_file_path=None): 134 | if not score_distr_file_path: 135 | score_distr_file_path = self.score_distr_file_path 136 | shape_hat, loc_hat, scale_hat = scipy.stats.gamma.fit(y_pred) 137 | gamma_params = [shape_hat, loc_hat, scale_hat] 138 | with open(score_distr_file_path, "wb") as f: 139 | pickle.dump(gamma_params, f, protocol=pickle.HIGHEST_PROTOCOL) 140 | 141 | def calc_decision_threshold(self, score_distr_file_path=None): 142 | if not score_distr_file_path: 143 | score_distr_file_path = self.score_distr_file_path 144 | # load anomaly score distribution for determining threshold 145 | with open(score_distr_file_path, "rb") as f: 146 | shape_hat, loc_hat, scale_hat = pickle.load(f) 147 | 148 | # determine threshold for decision 149 | return scipy.stats.gamma.ppf(q=self.args.decision_threshold, a=shape_hat, loc=loc_hat, scale=scale_hat) 150 | 151 | def train(self, epoch): 152 | pass 153 | 154 | def test(self): 155 | pass 156 | 157 | def copy_eval_data_score(self, decision_result_csv_path, anomaly_score_csv_path): 158 | eval_data_decision_result_csv_path = self.eval_data_result_dir / os.path.basename(decision_result_csv_path).replace(self.model_name_suffix, "") 159 | print(f"copy decision result: {decision_result_csv_path}\n\t->{eval_data_decision_result_csv_path}") 160 | shutil.copyfile(decision_result_csv_path, eval_data_decision_result_csv_path) 161 | 162 | eval_data_anomaly_score_csv_path = self.eval_data_result_dir / os.path.basename(anomaly_score_csv_path).replace(self.model_name_suffix, "") 163 | print(f"copy anomaly score: {anomaly_score_csv_path}\n\t->{eval_data_anomaly_score_csv_path}") 164 | shutil.copyfile(anomaly_score_csv_path, eval_data_anomaly_score_csv_path) 165 | -------------------------------------------------------------------------------- /networks/criterion/mahala.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | def cov_v_diff(in_v): 4 | in_v_tmp = in_v.clone() 5 | mu = torch.mean(in_v_tmp.t(), 1) 6 | diff = torch.sub(in_v, mu) 7 | 8 | return diff, mu 9 | 10 | def cov_v(diff, num): 11 | var = torch.matmul(diff.t(), diff) / num 12 | return var 13 | 14 | def mahalanobis(u, v, cov_x, use_precision=False, reduction=True): 15 | num, dim = v.size() 16 | if use_precision == True: 17 | inv_cov = cov_x 18 | else: 19 | inv_cov = torch.inverse(cov_x) 20 | delta = torch.sub(u, v) 21 | m_loss = torch.matmul(torch.matmul(delta, inv_cov), delta.t()) 22 | 23 | if reduction: 24 | return torch.sum(m_loss)/num 25 | else: 26 | return m_loss, num 27 | 28 | def loss_function_mahala(recon_x, x, block_size, cov=None, is_source_list=None, is_target_list=None, update_cov=False, use_precision=False, reduction=True): 29 | ### Modified mahalanobis loss### 30 | if update_cov == False: 31 | loss = mahalanobis(recon_x.view(-1, block_size), x.view(-1, block_size), cov, use_precision, reduction=reduction) 32 | return loss 33 | else: 34 | diff = x - recon_x 35 | cov_diff_source, _ = cov_v_diff(in_v=diff[is_source_list].view(-1, block_size)) 36 | 37 | cov_diff_target = None 38 | is_calc_cov_target = any(is_target_list) 39 | if is_calc_cov_target: 40 | cov_diff_target, _ = cov_v_diff(in_v=diff[is_target_list].view(-1, block_size)) 41 | 42 | loss = diff**2 43 | if reduction: 44 | loss = torch.mean(loss, dim=1) 45 | 46 | return loss, cov_diff_source, cov_diff_target 47 | 48 | def loss_reduction_mahala(loss): 49 | return torch.mean(loss) 50 | 51 | def calc_inv_cov(model, device="cpu"): 52 | inv_cov_source=None 53 | inv_cov_target=None 54 | 55 | cov_x_source = model.cov_source.data 56 | cov_x_source = cov_x_source.to(device).float() 57 | inv_cov_source = torch.inverse(cov_x_source) 58 | inv_cov_source = inv_cov_source.to(device).float() 59 | 60 | cov_x_target = model.cov_target.data 61 | cov_x_target = cov_x_target.to(device).float() 62 | inv_cov_target = torch.inverse(cov_x_target) 63 | inv_cov_target = inv_cov_target.to(device).float() 64 | 65 | return inv_cov_source, inv_cov_target 66 | -------------------------------------------------------------------------------- /networks/dcase2023t2_ae/network.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch import nn 3 | 4 | class AENet(nn.Module): 5 | def __init__(self,input_dim, block_size): 6 | super(AENet,self).__init__() 7 | self.input_dim = input_dim 8 | self.cov_source = nn.Parameter(torch.zeros(block_size, block_size), requires_grad=False) 9 | self.cov_target = nn.Parameter(torch.zeros(block_size, block_size), requires_grad=False) 10 | 11 | self.encoder = nn.Sequential( 12 | nn.Linear(self.input_dim,128), 13 | nn.BatchNorm1d(128,momentum=0.01, eps=1e-03), 14 | nn.ReLU(), 15 | nn.Linear(128,128), 16 | nn.BatchNorm1d(128,momentum=0.01, eps=1e-03), 17 | nn.ReLU(), 18 | nn.Linear(128,128), 19 | nn.BatchNorm1d(128,momentum=0.01, eps=1e-03), 20 | nn.ReLU(), 21 | nn.Linear(128,128), 22 | nn.BatchNorm1d(128,momentum=0.01, eps=1e-03), 23 | nn.ReLU(), 24 | nn.Linear(128,8), 25 | nn.BatchNorm1d(8,momentum=0.01, eps=1e-03), 26 | nn.ReLU(), 27 | ) 28 | 29 | self.decoder = nn.Sequential( 30 | nn.Linear(8,128), 31 | nn.BatchNorm1d(128,momentum=0.01, eps=1e-03), 32 | nn.ReLU(), 33 | nn.Linear(128,128), 34 | nn.BatchNorm1d(128,momentum=0.01, eps=1e-03), 35 | nn.ReLU(), 36 | nn.Linear(128,128), 37 | nn.BatchNorm1d(128,momentum=0.01, eps=1e-03), 38 | nn.ReLU(), 39 | nn.Linear(128,128), 40 | nn.BatchNorm1d(128,momentum=0.01, eps=1e-03), 41 | nn.ReLU(), 42 | nn.Linear(128,self.input_dim) 43 | ) 44 | 45 | def forward(self, x): 46 | z = self.encoder(x.view(-1,self.input_dim)) 47 | return self.decoder(z), z 48 | -------------------------------------------------------------------------------- /networks/models.py: -------------------------------------------------------------------------------- 1 | from networks.dcase2023t2_ae.dcase2023t2_ae import DCASE2023T2AE 2 | 3 | class Models: 4 | ModelsDic = { 5 | "DCASE2023T2-AE":DCASE2023T2AE, 6 | } 7 | 8 | def __init__(self,models_str): 9 | self.net = Models.ModelsDic[models_str] 10 | 11 | def show_list(self): 12 | return Models.ModelsDic.keys() 13 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | scipy 2 | librosa 3 | matplotlib 4 | tqdm 5 | seaborn 6 | fasteners 7 | 8 | # Included in docker image 9 | torch==2.6.0+cu118 10 | torchvision==0.21.0+cu118 11 | PyYAML==6.0.2 12 | -------------------------------------------------------------------------------- /results/dev_data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /results/eval_data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /test_ae.sh: -------------------------------------------------------------------------------- 1 | echo $* 2 | 3 | dataset=$1 4 | dev_eval=$2 5 | score=$3 6 | id_1=$4 7 | id_2=$5 8 | id_3=$6 9 | id_4=$7 10 | 11 | id="$id_1 $id_2 $id_3 $id_4" 12 | 13 | echo dataset ${dataset} 14 | echo dev_eval ${dev_eval} 15 | echo score ${score} 16 | echo id ${id} 17 | 18 | tag="id(" 19 | for i in ${id}; do 20 | tag="${tag}${i}_" 21 | done 22 | tag="${tag})" 23 | 24 | python3 train.py \ 25 | --dataset=${dataset} \ 26 | ${dev_eval} \ 27 | -tag=${tag} \ 28 | --use_ids ${id} \ 29 | --score ${score} \ 30 | --test_only \ 31 | -------------------------------------------------------------------------------- /tools/01_train_legacy.sh: -------------------------------------------------------------------------------- 1 | TZ=JST-9 date 2 | 3 | echo $0 $* 4 | 5 | ROOT_DIR=$(cd $(dirname $0); pwd)/../ 6 | cd $ROOT_DIR 7 | 8 | dataset=$1 9 | dev_eval=$2 10 | echo -e "\tdataset = '$dataset'" 11 | echo -e "\tdev_eval = '$dev_eval'" 12 | echo 13 | 14 | base_job="bash" 15 | 16 | # check args 17 | args_flag=0 18 | args_flag_dataset=0 19 | if [ "${dataset}" != "DCASE2020T2" ] \ 20 | && [ "${dataset}" != "DCASE2021T2" ] \ 21 | && [ "${dataset}" != "DCASE2022T2" ] \ 22 | && [ "${dataset}" != "DCASE2023T2" ] \ 23 | && [ "${dataset}" != "DCASE2024T2" ] 24 | then 25 | args_flag=1 26 | args_flag_dataset=1 27 | fi 28 | 29 | args_flag_dev_eval=0 30 | if [ "${dev_eval}" != "-d" ] \ 31 | && [ "${dev_eval}" != "-e" ] \ 32 | && [ "${dev_eval}" != "--dev" ] \ 33 | && [ "${dev_eval}" != "--eval" ] 34 | then 35 | args_flag=1 36 | args_flag_dev_eval=1 37 | fi 38 | 39 | if [ $args_flag -eq 1 ] 40 | then 41 | echo "$0: argument error" 42 | echo -e "usage\t: $0 ['DCASE2020T2' | 'DCASE2021T2' | 'DCASE2022T2' | 'DCASE2023T2' | 'DCASE2024T2'] ['-d' | '--dev' | '-e' | '--eval']" 43 | 44 | if [ $args_flag_dataset -eq 1 ] 45 | then 46 | echo -e "\tdataset: invalid choice '$dataset'" 47 | echo -e "\tchoice from ['DCASE2020T2' | 'DCASE2021T2' | 'DCASE2022T2' | 'DCASE2023T2' | 'DCASE2023T2']." 48 | echo -e "\t\tDCASE2020T2\t: Use DCASE2020 Task2 datasets. " 49 | echo -e "\t\tDCASE2021T2\t: Use DCASE2021 Task2 datasets. " 50 | echo -e "\t\tDCASE2022T2\t: Use DCASE2022 Task2 datasets. " 51 | echo -e "\t\tDCASE2023T2\t: Use DCASE2023 Task2 datasets. " 52 | echo -e "\t\tDCASE2024T2\t: Use DCASE2024 Task2 datasets. " 53 | echo 54 | fi 55 | 56 | if [ $args_flag_dev_eval -eq 1 ] 57 | then 58 | echo -e "\tdev_eval: invalid choice '$dev_eval'" 59 | echo -e "\tchoice from ['-d' | '--dev' | '-e' | '--eval']." 60 | echo -e "\t\t-d, --dev\t: Using Development dataset. " 61 | echo -e "\t\t-e, --eval\t: Using Additional training dataset and Evaluation dataset. " 62 | echo 63 | fi 64 | 65 | echo -e "example\t: $ bash $0 DCASE2020T2 -d" 66 | exit 1 67 | fi 68 | 69 | # main process 70 | for job in "train_ae.sh"; do 71 | if [ $dataset = "DCASE2024T2" ]; then 72 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 73 | for machine_type in DCASE2024T2bearing DCASE2024T2fan DCASE2024T2gearbox DCASE2024T2slider DCASE2024T2ToyCar DCASE2024T2ToyTrain DCASE2024T2valve; do 74 | ${base_job} $job ${machine_type} ${dev_eval} 0 75 | done 76 | else # $dev_eval = "-e" || $dev_eval = "--eval" 77 | for machine_type in \ 78 | DCASE2024T23DPrinter \ 79 | DCASE2024T2AirCompressor \ 80 | DCASE2024T2Scanner \ 81 | DCASE2024T2ToyCircuit \ 82 | DCASE2024T2HoveringDrone \ 83 | DCASE2024T2HairDryer \ 84 | DCASE2024T2ToothBrush \ 85 | DCASE2024T2RoboticArm \ 86 | DCASE2024T2BrushlessMotor \ 87 | ; do 88 | ${base_job} $job ${machine_type} ${dev_eval} 0 89 | done 90 | fi 91 | elif [ $dataset = "DCASE2023T2" ]; then 92 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 93 | for machine_type in DCASE2023T2bearing DCASE2023T2fan DCASE2023T2gearbox DCASE2023T2slider DCASE2023T2ToyCar DCASE2023T2ToyTrain DCASE2023T2valve; do 94 | ${base_job} $job ${machine_type} ${dev_eval} 0 95 | done 96 | else # $dev_eval = "-e" || $dev_eval = "--eval" 97 | for machine_type in DCASE2023T2ToyDrone DCASE2023T2ToyNscale DCASE2023T2ToyTank DCASE2023T2Vacuum DCASE2023T2bandsaw DCASE2023T2grinder DCASE2023T2shaker; do 98 | ${base_job} $job ${machine_type} ${dev_eval} 0 99 | done 100 | fi 101 | elif [ $dataset = "DCASE2022T2" ]; then 102 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 103 | for machine_type in DCASE2022T2bearing DCASE2022T2fan DCASE2022T2gearbox DCASE2022T2slider DCASE2022T2ToyCar DCASE2022T2ToyTrain DCASE2022T2valve; do 104 | ${base_job} $job ${machine_type} ${dev_eval} 0 105 | ${base_job} $job ${machine_type} ${dev_eval} 1 106 | ${base_job} $job ${machine_type} ${dev_eval} 2 107 | done 108 | else # $dev_eval = "-e" || $dev_eval = "--eval" 109 | for machine_type in DCASE2022T2bearing DCASE2022T2fan DCASE2022T2gearbox DCASE2022T2slider DCASE2022T2ToyCar DCASE2022T2ToyTrain DCASE2022T2valve; do 110 | ${base_job} $job ${machine_type} ${dev_eval} 3 111 | ${base_job} $job ${machine_type} ${dev_eval} 4 112 | ${base_job} $job ${machine_type} ${dev_eval} 5 113 | done 114 | fi 115 | elif [ $dataset = "DCASE2021T2" ]; then 116 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 117 | for machine_type in DCASE2021T2fan DCASE2021T2gearbox DCASE2021T2pump DCASE2021T2slider DCASE2021T2ToyCar DCASE2021T2ToyTrain DCASE2021T2valve; do 118 | ${base_job} $job ${machine_type} ${dev_eval} 0 119 | ${base_job} $job ${machine_type} ${dev_eval} 1 120 | ${base_job} $job ${machine_type} ${dev_eval} 2 121 | done 122 | else # $dev_eval = "-e" || $dev_eval = "--eval" 123 | for machine_type in DCASE2021T2fan DCASE2021T2gearbox DCASE2021T2pump DCASE2021T2slider DCASE2021T2ToyCar DCASE2021T2ToyTrain DCASE2021T2valve; do 124 | ${base_job} $job ${machine_type} ${dev_eval} 3 125 | ${base_job} $job ${machine_type} ${dev_eval} 4 126 | ${base_job} $job ${machine_type} ${dev_eval} 5 127 | done 128 | fi 129 | else # DCASE2020T2 130 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 131 | machine_type=DCASE2020T2ToyCar 132 | ${base_job} $job ${machine_type} ${dev_eval} 1 133 | ${base_job} $job ${machine_type} ${dev_eval} 2 134 | ${base_job} $job ${machine_type} ${dev_eval} 3 135 | ${base_job} $job ${machine_type} ${dev_eval} 4 136 | 137 | machine_type=DCASE2020T2ToyConveyor 138 | ${base_job} $job ${machine_type} ${dev_eval} 1 139 | ${base_job} $job ${machine_type} ${dev_eval} 2 140 | ${base_job} $job ${machine_type} ${dev_eval} 3 141 | 142 | for machine_type in DCASE2020T2fan DCASE2020T2valve DCASE2020T2slider DCASE2020T2pump; do 143 | ${base_job} $job ${machine_type} ${dev_eval} 0 144 | ${base_job} $job ${machine_type} ${dev_eval} 2 145 | ${base_job} $job ${machine_type} ${dev_eval} 4 146 | ${base_job} $job ${machine_type} ${dev_eval} 6 147 | done 148 | else # $dev_eval = "-e" || $dev_eval = "--eval" 149 | machine_type=DCASE2020T2ToyCar 150 | ${base_job} $job ${machine_type} ${dev_eval} 5 151 | ${base_job} $job ${machine_type} ${dev_eval} 6 152 | ${base_job} $job ${machine_type} ${dev_eval} 7 153 | 154 | machine_type=DCASE2020T2ToyConveyor 155 | ${base_job} $job ${machine_type} ${dev_eval} 4 156 | ${base_job} $job ${machine_type} ${dev_eval} 5 157 | ${base_job} $job ${machine_type} ${dev_eval} 6 158 | 159 | for machine_type in DCASE2020T2fan DCASE2020T2valve DCASE2020T2slider DCASE2020T2pump; do 160 | ${base_job} $job ${machine_type} ${dev_eval} 1 161 | ${base_job} $job ${machine_type} ${dev_eval} 3 162 | ${base_job} $job ${machine_type} ${dev_eval} 5 163 | done 164 | fi 165 | fi 166 | done 167 | -------------------------------------------------------------------------------- /tools/02a_test_legacy.sh: -------------------------------------------------------------------------------- 1 | TZ=JST-9 date 2 | 3 | echo $0 $* 4 | 5 | ROOT_DIR=$(cd $(dirname $0); pwd)/../ 6 | cd $ROOT_DIR 7 | 8 | dataset=$1 9 | dev_eval=$2 10 | echo -e "\tdataset = '$dataset'" 11 | echo -e "\tdev_eval = '$dev_eval'" 12 | echo 13 | 14 | base_job="bash" 15 | score="MSE" 16 | 17 | # check args 18 | args_flag=0 19 | args_flag_dataset=0 20 | if [ "${dataset}" != "DCASE2020T2" ] \ 21 | && [ "${dataset}" != "DCASE2021T2" ] \ 22 | && [ "${dataset}" != "DCASE2022T2" ] \ 23 | && [ "${dataset}" != "DCASE2023T2" ] \ 24 | && [ "${dataset}" != "DCASE2024T2" ] 25 | then 26 | args_flag=1 27 | args_flag_dataset=1 28 | fi 29 | 30 | args_flag_dev_eval=0 31 | if [ "${dev_eval}" != "-d" ] \ 32 | && [ "${dev_eval}" != "-e" ] \ 33 | && [ "${dev_eval}" != "--dev" ] \ 34 | && [ "${dev_eval}" != "--eval" ] 35 | then 36 | args_flag=1 37 | args_flag_dev_eval=1 38 | fi 39 | 40 | if [ $args_flag -eq 1 ] 41 | then 42 | echo "$0: argument error" 43 | echo -e "usage\t: $0 ['DCASE2020T2' | 'DCASE2021T2' | 'DCASE2022T2' | 'DCASE2023T2' | 'DCASE2024T2'] ['-d' | '--dev' | '-e' | '--eval']" 44 | 45 | if [ $args_flag_dataset -eq 1 ] 46 | then 47 | echo -e "\tdataset: invalid choice '$dataset'" 48 | echo -e "\tchoice from ['DCASE2020T2' | 'DCASE2021T2' | 'DCASE2022T2' | 'DCASE2023T2' | 'DCASE2024T2']." 49 | echo -e "\t\tDCASE2020T2\t: Use DCASE2020 Task2 datasets. " 50 | echo -e "\t\tDCASE2021T2\t: Use DCASE2021 Task2 datasets. " 51 | echo -e "\t\tDCASE2022T2\t: Use DCASE2022 Task2 datasets. " 52 | echo -e "\t\tDCASE2023T2\t: Use DCASE2023 Task2 datasets. " 53 | echo -e "\t\tDCASE2024T2\t: Use DCASE2024 Task2 datasets. " 54 | echo 55 | fi 56 | 57 | if [ $args_flag_dev_eval -eq 1 ] 58 | then 59 | echo -e "\tdev_eval: invalid choice '$dev_eval'" 60 | echo -e "\tchoice from ['-d' | '--dev' | '-e' | '--eval']." 61 | echo -e "\t\t-d, --dev\t: Using Development dataset. " 62 | echo -e "\t\t-e, --eval\t: Using Additional training dataset and Evaluation dataset. " 63 | echo 64 | fi 65 | 66 | echo -e "example\t: $ bash $0 DCASE2020T2 -d" 67 | exit 1 68 | fi 69 | 70 | # main process 71 | for job in "test_ae.sh"; do 72 | 73 | if [ $dataset = "DCASE2024T2" ]; then 74 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 75 | for machine_type in DCASE2024T2bearing DCASE2024T2fan DCASE2024T2gearbox DCASE2024T2slider DCASE2024T2ToyCar DCASE2024T2ToyTrain DCASE2024T2valve; do 76 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 0 77 | done 78 | else # $dev_eval = "-e" || $dev_eval = "--eval" 79 | for machine_type in \ 80 | DCASE2024T23DPrinter \ 81 | DCASE2024T2AirCompressor \ 82 | DCASE2024T2Scanner \ 83 | DCASE2024T2ToyCircuit \ 84 | DCASE2024T2HoveringDrone \ 85 | DCASE2024T2HairDryer \ 86 | DCASE2024T2ToothBrush \ 87 | DCASE2024T2RoboticArm \ 88 | DCASE2024T2BrushlessMotor \ 89 | ; do 90 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 0 91 | done 92 | fi 93 | elif [ $dataset = "DCASE2023T2" ]; then 94 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 95 | for machine_type in DCASE2023T2bearing DCASE2023T2fan DCASE2023T2gearbox DCASE2023T2slider DCASE2023T2ToyCar DCASE2023T2ToyTrain DCASE2023T2valve; do 96 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 0 97 | done 98 | else # $dev_eval = "-e" || $dev_eval = "--eval" 99 | for machine_type in DCASE2023T2ToyDrone DCASE2023T2ToyNscale DCASE2023T2ToyTank DCASE2023T2Vacuum DCASE2023T2bandsaw DCASE2023T2grinder DCASE2023T2shaker; do 100 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 0 101 | done 102 | fi 103 | elif [ $dataset = "DCASE2022T2" ]; then 104 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 105 | for machine_type in DCASE2022T2bearing DCASE2022T2fan DCASE2022T2gearbox DCASE2022T2slider DCASE2022T2ToyCar DCASE2022T2ToyTrain DCASE2022T2valve; do 106 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 0 107 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 1 108 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 2 109 | done 110 | else # $dev_eval = "-e" || $dev_eval = "--eval" 111 | for machine_type in DCASE2022T2bearing DCASE2022T2fan DCASE2022T2gearbox DCASE2022T2slider DCASE2022T2ToyCar DCASE2022T2ToyTrain DCASE2022T2valve; do 112 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 3 113 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 4 114 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 5 115 | done 116 | fi 117 | elif [ $dataset = "DCASE2021T2" ]; then 118 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 119 | for machine_type in DCASE2021T2fan DCASE2021T2gearbox DCASE2021T2pump DCASE2021T2slider DCASE2021T2ToyCar DCASE2021T2ToyTrain DCASE2021T2valve; do 120 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 0 121 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 1 122 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 2 123 | done 124 | else # $dev_eval = "-e" || $dev_eval = "--eval" 125 | for machine_type in DCASE2021T2fan DCASE2021T2gearbox DCASE2021T2pump DCASE2021T2slider DCASE2021T2ToyCar DCASE2021T2ToyTrain DCASE2021T2valve; do 126 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 3 127 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 4 128 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 5 129 | done 130 | fi 131 | else # DCASE2020T2 132 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 133 | machine_type=DCASE2020T2ToyCar 134 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 1 135 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 2 136 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 3 137 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 4 138 | 139 | machine_type=DCASE2020T2ToyConveyor 140 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 1 141 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 2 142 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 3 143 | 144 | for machine_type in DCASE2020T2fan DCASE2020T2valve DCASE2020T2slider DCASE2020T2pump; do 145 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 0 146 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 2 147 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 4 148 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 6 149 | done 150 | else # $dev_eval = "-e" || $dev_eval = "--eval" 151 | machine_type=DCASE2020T2ToyCar 152 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 5 153 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 6 154 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 7 155 | 156 | machine_type=DCASE2020T2ToyConveyor 157 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 4 158 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 5 159 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 6 160 | 161 | for machine_type in DCASE2020T2fan DCASE2020T2valve DCASE2020T2slider DCASE2020T2pump; do 162 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 1 163 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 3 164 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 5 165 | done 166 | fi 167 | fi 168 | done 169 | -------------------------------------------------------------------------------- /tools/02b_test_legacy.sh: -------------------------------------------------------------------------------- 1 | TZ=JST-9 date 2 | 3 | echo $0 $* 4 | 5 | ROOT_DIR=$(cd $(dirname $0); pwd)/../ 6 | cd $ROOT_DIR 7 | 8 | dataset=$1 9 | dev_eval=$2 10 | echo -e "\tdataset = '$dataset'" 11 | echo -e "\tdev_eval = '$dev_eval'" 12 | echo 13 | 14 | base_job="bash" 15 | score="MAHALA" 16 | 17 | # check args 18 | args_flag=0 19 | args_flag_dataset=0 20 | if [ "${dataset}" != "DCASE2020T2" ] \ 21 | && [ "${dataset}" != "DCASE2021T2" ] \ 22 | && [ "${dataset}" != "DCASE2022T2" ] \ 23 | && [ "${dataset}" != "DCASE2023T2" ] \ 24 | && [ "${dataset}" != "DCASE2024T2" ] 25 | then 26 | args_flag=1 27 | args_flag_dataset=1 28 | fi 29 | 30 | args_flag_dev_eval=0 31 | if [ "${dev_eval}" != "-d" ] \ 32 | && [ "${dev_eval}" != "-e" ] \ 33 | && [ "${dev_eval}" != "--dev" ] \ 34 | && [ "${dev_eval}" != "--eval" ] 35 | then 36 | args_flag=1 37 | args_flag_dev_eval=1 38 | fi 39 | 40 | if [ $args_flag -eq 1 ] 41 | then 42 | echo "$0: argument error" 43 | echo -e "usage\t: $0 ['DCASE2020T2' | 'DCASE2021T2' | 'DCASE2022T2' | 'DCASE2023T2' | 'DCASE2024T2'] ['-d' | '--dev' | '-e' | '--eval']" 44 | 45 | if [ $args_flag_dataset -eq 1 ] 46 | then 47 | echo -e "\tdataset: invalid choice '$dataset'" 48 | echo -e "\tchoice from ['DCASE2020T2' | 'DCASE2021T2' | 'DCASE2022T2' | 'DCASE2023T2']." 49 | echo -e "\t\tDCASE2020T2\t: Use DCASE2020 Task2 datasets. " 50 | echo -e "\t\tDCASE2021T2\t: Use DCASE2021 Task2 datasets. " 51 | echo -e "\t\tDCASE2022T2\t: Use DCASE2022 Task2 datasets. " 52 | echo -e "\t\tDCASE2023T2\t: Use DCASE2023 Task2 datasets. " 53 | echo -e "\t\tDCASE2024T2\t: Use DCASE2024 Task2 datasets. " 54 | echo 55 | fi 56 | 57 | if [ $args_flag_dev_eval -eq 1 ] 58 | then 59 | echo -e "\tdev_eval: invalid choice '$dev_eval'" 60 | echo -e "\tchoice from ['-d' | '--dev' | '-e' | '--eval']." 61 | echo -e "\t\t-d, --dev\t: Using Development dataset. " 62 | echo -e "\t\t-e, --eval\t: Using Additional training dataset and Evaluation dataset. " 63 | echo 64 | fi 65 | 66 | echo -e "example\t: $ bash $0 DCASE2020T2 -d" 67 | exit 1 68 | fi 69 | 70 | # main process 71 | for job in "test_ae.sh"; do 72 | 73 | if [ $dataset = "DCASE2024T2" ]; then 74 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 75 | for machine_type in DCASE2024T2bearing DCASE2024T2fan DCASE2024T2gearbox DCASE2024T2slider DCASE2024T2ToyCar DCASE2024T2ToyTrain DCASE2024T2valve; do 76 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 0 77 | done 78 | else # $dev_eval = "-e" || $dev_eval = "--eval" 79 | for machine_type in \ 80 | DCASE2024T23DPrinter \ 81 | DCASE2024T2AirCompressor \ 82 | DCASE2024T2Scanner \ 83 | DCASE2024T2ToyCircuit \ 84 | DCASE2024T2HoveringDrone \ 85 | DCASE2024T2HairDryer \ 86 | DCASE2024T2ToothBrush \ 87 | DCASE2024T2RoboticArm \ 88 | DCASE2024T2BrushlessMotor \ 89 | ; do 90 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 0 91 | done 92 | fi 93 | elif [ $dataset = "DCASE2023T2" ]; then 94 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 95 | for machine_type in DCASE2022T2bearing DCASE2022T2fan DCASE2022T2gearbox DCASE2022T2slider DCASE2022T2ToyCar DCASE2022T2ToyTrain DCASE2022T2valve; do 96 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 0 97 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 1 98 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 2 99 | done 100 | else # $dev_eval = "-e" || $dev_eval = "--eval" 101 | for machine_type in DCASE2022T2bearing DCASE2022T2fan DCASE2022T2gearbox DCASE2022T2slider DCASE2022T2ToyCar DCASE2022T2ToyTrain DCASE2022T2valve; do 102 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 3 103 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 4 104 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 5 105 | done 106 | fi 107 | elif [ $dataset = "DCASE2021T2" ]; then 108 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 109 | for machine_type in DCASE2021T2fan DCASE2021T2gearbox DCASE2021T2pump DCASE2021T2slider DCASE2021T2ToyCar DCASE2021T2ToyTrain DCASE2021T2valve; do 110 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 0 111 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 1 112 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 2 113 | done 114 | else # $dev_eval = "-e" || $dev_eval = "--eval" 115 | for machine_type in DCASE2021T2fan DCASE2021T2gearbox DCASE2021T2pump DCASE2021T2slider DCASE2021T2ToyCar DCASE2021T2ToyTrain DCASE2021T2valve; do 116 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 3 117 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 4 118 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 5 119 | done 120 | fi 121 | else # DCASE2020T2 122 | if [ $dev_eval = "-d" ] || [ $dev_eval = "--dev" ]; then 123 | machine_type=DCASE2020T2ToyCar 124 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 1 125 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 2 126 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 3 127 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 4 128 | 129 | machine_type=DCASE2020T2ToyConveyor 130 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 1 131 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 2 132 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 3 133 | 134 | for machine_type in DCASE2020T2fan DCASE2020T2valve DCASE2020T2slider DCASE2020T2pump; do 135 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 0 136 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 2 137 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 4 138 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 6 139 | done 140 | else # $dev_eval = "-e" || $dev_eval = "--eval" 141 | machine_type=DCASE2020T2ToyCar 142 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 5 143 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 6 144 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 7 145 | 146 | machine_type=DCASE2020T2ToyConveyor 147 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 4 148 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 5 149 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 6 150 | 151 | for machine_type in DCASE2020T2fan DCASE2020T2valve DCASE2020T2slider DCASE2020T2pump; do 152 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 1 153 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 3 154 | ${base_job} $job ${machine_type} ${dev_eval} ${score} 5 155 | done 156 | fi 157 | fi 158 | done 159 | -------------------------------------------------------------------------------- /tools/README.md: -------------------------------------------------------------------------------- 1 | # Utility tools 2 | 3 | ## Description 4 | 5 | - concat_divided_roc.py 6 | - This script is called by export_results.sh. 7 | - Integrate results for each sectionID into results for each machine ID. 8 | - data_download_2020.sh 9 | - Download DCASE2020 Challenge Task 2 data. 10 | - data_download_2022.sh 11 | - Download DCASE2022 Challenge Task 2 data. 12 | - export_results.py 13 | - This script is called by export_result.sh. 14 | - Summarize the results in a CSV file. 15 | - export_results.sh 16 | - This scriput is called by 03_summarize_results.sh. 17 | - Integrate, summarize, and extract results. 18 | - extract_results.py 19 | - This script is called by export_results.sh 20 | - This is used after export_results.py to extract arithmetic mean and harmonic mean results and summarize all results into a csv. 21 | - job_ae.sh 22 | - Run DCASE2020T2 and DCASE2022T2 for training and evaluation. 23 | - plot_anm_score.py 24 | - Export boxplots of anomaly scores. 25 | - plot_common.py 26 | - Plot figure utility. 27 | - plot_loss_curve.py 28 | - Plot loss curve in trainning. 29 | - plot_time_frequency.py 30 | - Export time frequency image. 31 | -------------------------------------------------------------------------------- /tools/concat_divided_roc.py: -------------------------------------------------------------------------------- 1 | from copy import copy 2 | import os 3 | import numpy as np 4 | import re 5 | import argparse 6 | import glob 7 | import statistics 8 | from pathlib import Path 9 | from scipy import stats 10 | import sys 11 | import csv 12 | 13 | if __name__ == "__main__": 14 | sys.path.append(os.path.join(os.path.dirname(__file__), '..')) 15 | from datasets.loader_common import get_machine_type_dict 16 | 17 | def csv_read(file_list): 18 | auc_list = [] 19 | pauc_list = [] 20 | pauc_s_list = [] 21 | pauc_t_list = [] 22 | auc_s_list = [] 23 | auc_t_list = [] 24 | column_list=[] 25 | for file in file_list: 26 | with open(file) as f:# list form 27 | reader = csv.DictReader(f) 28 | row_auc = [] 29 | row_pauc = [] 30 | row_pauc_s = [] 31 | row_pauc_t = [] 32 | row_auc_s = [] 33 | row_auc_t = [] 34 | for row in reader: 35 | if "AUC" in row.keys(): 36 | row_auc.append(float(row["AUC"])) 37 | if "pAUC" in row.keys(): 38 | row_pauc.append(float(row["pAUC"])) 39 | if "pAUC (source)" in row.keys(): 40 | row_pauc_s.append(float(row["pAUC (source)"])) 41 | if "pAUC (target)" in row.keys(): 42 | row_pauc_t.append(float(row["pAUC (target)"])) 43 | if "AUC (source)" in row.keys(): 44 | row_auc_s.append(float(row["AUC (source)"])) 45 | if "AUC (target)" in row.keys(): 46 | row_auc_t.append(float(row["AUC (target)"])) 47 | auc_list.append(row_auc) 48 | pauc_list.append(row_pauc) 49 | pauc_s_list.append(row_pauc_s) 50 | pauc_t_list.append(row_pauc_t) 51 | auc_s_list.append(row_auc_s) 52 | auc_t_list.append(row_auc_t) 53 | if all(auc_list): 54 | column_list.append("AUC") 55 | if all(pauc_list): 56 | column_list.append("pAUC") 57 | if all(pauc_s_list): 58 | column_list.append("pAUC (source)") 59 | if all(pauc_t_list): 60 | column_list.append("pAUC (target)") 61 | if all(auc_s_list): 62 | column_list.append("AUC (source)") 63 | if all(auc_t_list): 64 | column_list.append("AUC (target)") 65 | return [ 66 | [list(x) for x in zip(*auc_list)], 67 | [list(x) for x in zip(*pauc_list)], 68 | [list(x) for x in zip(*pauc_s_list)], 69 | [list(x) for x in zip(*pauc_t_list)], 70 | [list(x) for x in zip(*auc_s_list)], 71 | [list(x) for x in zip(*auc_t_list)], 72 | ], column_list 73 | 74 | def get_use_index_list(file_list,keyword): 75 | use_id_list = [] 76 | for file in file_list: 77 | use_id = re.findall(keyword,file) 78 | use_id = use_id[0].split("_") 79 | use_id = list(filter(None, use_id)) 80 | use_id = sorted(map(int,use_id)) 81 | use_id_list.append(use_id) 82 | all_id = list(set(sum(use_id_list, []))) 83 | 84 | return all_id, use_id_list 85 | 86 | def concat_auc_pauc(auc_list, all_id_list, nml_id_list): 87 | concat_auc_dict = {} 88 | if len(auc_list) == 0: 89 | return None 90 | 91 | for i in range(len(nml_id_list)): 92 | for nml_id in nml_id_list[i]: 93 | idx = all_id_list.index(nml_id) 94 | if len(auc_list) <= 2: 95 | concat_auc_dict[idx]=(auc_list[0][i]) 96 | else: 97 | concat_auc_dict[idx]=(auc_list[idx][i]) 98 | 99 | return [x[1] for x in sorted(concat_auc_dict.items())] 100 | 101 | def export_csv(file_path, auc_list, column_header, machine_id_list): 102 | csv_lines = [] 103 | csv_lines.append(["id"] + column_header) 104 | for idx, auc_row in zip(machine_id_list, zip(*auc_list)): 105 | csv_lines.append([idx] + list(auc_row)) 106 | csv_lines.append(["arithmetic mean"] + np.mean(auc_list, axis=1).tolist()) 107 | csv_lines.append(["harmonic mean"] + stats.hmean(auc_list, axis=1).tolist()) 108 | np.savetxt(file_path, csv_lines,fmt="%s", delimiter=",") 109 | print(f"\tSave ROC -> {file_path}") 110 | 111 | 112 | if __name__ == "__main__": 113 | parser = argparse.ArgumentParser( 114 | description='Main function to call training for different AutoEncoders') 115 | parser.add_argument("--parent_dir", type=str, default='', metavar='N', 116 | help='') 117 | parser.add_argument("--export_dir", type=str, default='', metavar='N', 118 | help='') 119 | parser.add_argument("--keyword", type=str, default='_id\((.+)\)', metavar='N', 120 | help='') 121 | parser.add_argument("--machine_type", type=str, default='all', metavar='N', 122 | help='') 123 | parser.add_argument("--file_name", type=str, default='*roc.csv', metavar='N', 124 | help='') 125 | parser.add_argument('--dataset',type=str, default="DCASE2020T2", 126 | choices=[ 127 | "DCASE2020T2", 128 | "DCASE2021T2", 129 | "DCASE2022T2", 130 | "DCASE2023T2", 131 | "DCASE2024T2", 132 | "DCASE2025T2", 133 | ]) 134 | parser.add_argument('-d', '--dev', action='store_true', 135 | help='Use Development dataset') 136 | parser.add_argument('-e', '--eval', action='store_true', 137 | help='Use Evaluation dataset') 138 | args = parser.parse_args() 139 | 140 | if args.eval: 141 | dev_mode = False 142 | elif args.dev: 143 | dev_mode = True 144 | else: 145 | print("incorrect argument") 146 | print("please set option argument '--dev' or '--eval'") 147 | sys.exit() 148 | 149 | machine_type_dict = get_machine_type_dict(dataset_name=args.dataset, mode=dev_mode)["machine_type"] 150 | all_types = list(machine_type_dict.keys()) 151 | 152 | if args.machine_type == "all": 153 | types = all_types 154 | else: 155 | types = args.machine_type.split(",") 156 | 157 | export_dir = os.path.basename(args.parent_dir) 158 | if args.export_dir: 159 | export_dir = f"{args.export_dir}/{export_dir}" 160 | else: 161 | export_dir = f"{args.parent_dir}/{export_dir}" 162 | Path(export_dir).mkdir(parents=True, exist_ok=True) 163 | 164 | for machine_type in types: 165 | eval_figdata_target_list = [] 166 | dev_figdata_target_list = [] 167 | eval_figdata_list_tmp = [] 168 | dev_figdata_list_tmp = [] 169 | files = sorted(glob.glob(f"{args.parent_dir}/*{args.dataset}{machine_type}*{args.file_name}")) 170 | 171 | # print(files) 172 | # print(dev_file_list) 173 | # print(eval_file_list) 174 | file_list = { 175 | "dev":[file for file in files if "Eval" not in file], 176 | "eval":[file for file in files if "Eval" in file], 177 | } 178 | for dev_eval in ["dev", "eval"]: 179 | if len(file_list[dev_eval]) > 0: 180 | auc_list, column_list = csv_read(file_list=file_list[dev_eval]) 181 | all_id_list, nml_id_list = get_use_index_list(file_list[dev_eval], args.keyword) 182 | print(f"{machine_type}\t({dev_eval}_data)\t: {len(nml_id_list)}/{len(all_id_list)}") 183 | if len(nml_id_list) == len(all_id_list): 184 | for i in range(len(auc_list)): 185 | auc_list[i] = concat_auc_pauc( 186 | auc_list=auc_list[i], 187 | all_id_list=all_id_list, 188 | nml_id_list=nml_id_list 189 | ) 190 | auc_list = [auc for auc in auc_list if auc is not None] 191 | file_path = os.path.splitext(os.path.basename(file_list[dev_eval][0]))[0] 192 | file_path = re.sub(args.keyword, "", file_path) 193 | file_path = f"{export_dir}/{file_path}.csv" 194 | export_csv( 195 | file_path=file_path, 196 | auc_list=auc_list, 197 | column_header=column_list, 198 | machine_id_list=machine_type_dict[machine_type][dev_eval] 199 | ) 200 | else: 201 | print(f"\t{machine_type} ROC did not concat.") -------------------------------------------------------------------------------- /tools/data_download_2020.sh: -------------------------------------------------------------------------------- 1 | parent_dir=data 2 | ROOT_DIR=$(cd $(dirname $0); pwd)/../ 3 | mkdir -p "${ROOT_DIR}/${parent_dir}/dcase2020t2/dev_data/raw" 4 | mkdir -p "${ROOT_DIR}/${parent_dir}/dcase2020t2/eval_data/raw" 5 | 6 | # download dev data 7 | cd "${ROOT_DIR}/${parent_dir}/dcase2020t2/dev_data/raw" 8 | for machine_type in ToyCar ToyConveyor fan valve slider pump; do 9 | wget "https://zenodo.org/record/3678171/files/dev_data_${machine_type}.zip" 10 | unzip "dev_data_${machine_type}.zip" 11 | done 12 | 13 | # download eval data 14 | cd - 15 | cd "${ROOT_DIR}/${parent_dir}/dcase2020t2/eval_data/raw" 16 | for machine_type in ToyCar ToyConveyor fan valve slider pump; do 17 | wget "https://zenodo.org/record/3727685/files/eval_data_train_${machine_type}.zip" 18 | unzip "eval_data_train_${machine_type}.zip" 19 | 20 | wget "https://zenodo.org/record/3841772/files/eval_data_test_${machine_type}.zip" 21 | unzip "eval_data_test_${machine_type}.zip" 22 | done 23 | 24 | # Adds reference labels to test data. 25 | python ${ROOT_DIR}/tools/rename_eval_wav.py --dataset_parent_dir=${parent_dir} --dataset_type=DCASE2020T2 26 | -------------------------------------------------------------------------------- /tools/data_download_2021.sh: -------------------------------------------------------------------------------- 1 | parent_dir=data 2 | ROOT_DIR=$(cd $(dirname $0); pwd)/../ 3 | mkdir -p "${ROOT_DIR}/${parent_dir}/dcase2021t2/dev_data/raw" 4 | mkdir -p "${ROOT_DIR}/${parent_dir}/dcase2021t2/eval_data/raw" 5 | 6 | # download dev data 7 | cd "${ROOT_DIR}/${parent_dir}/dcase2021t2/dev_data/raw" 8 | for machine_type in fan gearbox pump slider ToyCar ToyTrain valve; do 9 | wget "https://zenodo.org/record/4562016/files/dev_data_${machine_type}.zip" 10 | unzip "dev_data_${machine_type}.zip" 11 | mkdir -p ${ROOT_DIR}/data/dcase2021t2/dev_data/raw/${machine_type}/test 12 | tsp scp -C ${ROOT_DIR}/data/dcase2021t2/dev_data/raw/${machine_type}/source_test/* data/dcase2021t2/dev_data/raw/${machine_type}/test/ 13 | tsp scp -C ${ROOT_DIR}/data/dcase2021t2/dev_data/raw/${machine_type}/target_test/* data/dcase2021t2/dev_data/raw/${machine_type}/test/ 14 | done 15 | 16 | # download eval data 17 | cd - 18 | cd "${ROOT_DIR}/${parent_dir}/dcase2021t2/eval_data/raw" 19 | for machine_type in fan gearbox pump slider ToyCar ToyTrain valve; do 20 | wget "https://zenodo.org/record/4660992/files/eval_data_${machine_type}_train.zip" 21 | unzip "eval_data_${machine_type}_train.zip" 22 | 23 | wget "https://zenodo.org/record/4884786/files/eval_data_${machine_type}_test.zip" 24 | unzip "eval_data_${machine_type}_test.zip" 25 | mkdir -p ${ROOT_DIR}/data/dcase2021t2/eval_data/raw/${machine_type}/test 26 | cp -r ${ROOT_DIR}/data/dcase2021t2/eval_data/raw/${machine_type}/source_test/* ${ROOT_DIR}/data/dcase2021t2/eval_data/raw/${machine_type}/test/ 27 | cp -r ${ROOT_DIR}/data/dcase2021t2/eval_data/raw/${machine_type}/target_test/* ${ROOT_DIR}/data/dcase2021t2/eval_data/raw/${machine_type}/test/ 28 | done 29 | 30 | # Adds reference labels to test data. 31 | python ${ROOT_DIR}/tools/rename_eval_wav.py --dataset_parent_dir=${parent_dir} --dataset_type=DCASE2021T2 32 | -------------------------------------------------------------------------------- /tools/data_download_2022.sh: -------------------------------------------------------------------------------- 1 | parent_dir=data 2 | ROOT_DIR=$(cd $(dirname $0); pwd)/../ 3 | mkdir -p "${ROOT_DIR}/${parent_dir}/dcase2022t2/dev_data/raw" 4 | mkdir -p "${ROOT_DIR}/${parent_dir}/dcase2022t2/eval_data/raw" 5 | 6 | # download dev data 7 | cd "${ROOT_DIR}/data/dcase2022t2/dev_data/raw" 8 | for machine_type in bearing fan gearbox slider ToyCar ToyTrain valve; do 9 | wget "https://zenodo.org/record/6355122/files/dev_${machine_type}.zip" 10 | unzip "dev_${machine_type}.zip" 11 | done 12 | 13 | # download eval data 14 | cd - 15 | cd "${ROOT_DIR}/data/dcase2022t2/eval_data/raw" 16 | for machine_type in bearing fan gearbox slider ToyCar ToyTrain valve; do 17 | wget "https://zenodo.org/record/6462969/files/eval_data_${machine_type}_train.zip" 18 | unzip "eval_data_${machine_type}_train.zip" 19 | 20 | wget "https://zenodo.org/record/6586456/files/eval_data_${machine_type}_test.zip" 21 | unzip "eval_data_${machine_type}_test.zip" 22 | done 23 | 24 | # Adds reference labels to test data. 25 | python ${ROOT_DIR}/tools/rename_eval_wav.py --dataset_parent_dir=${parent_dir} --dataset_type=DCASE2022T2 26 | -------------------------------------------------------------------------------- /tools/data_download_2023.sh: -------------------------------------------------------------------------------- 1 | parent_dir=data 2 | ROOT_DIR=$(cd $(dirname $0); pwd)/../ 3 | mkdir -p "${ROOT_DIR}/${parent_dir}/dcase2023t2/dev_data/raw" 4 | mkdir -p "${ROOT_DIR}/${parent_dir}/dcase2023t2/eval_data/raw" 5 | 6 | # download dev data 7 | cd "${ROOT_DIR}/data/dcase2023t2/dev_data/raw" 8 | for machine_type in bearing fan gearbox slider ToyCar ToyTrain valve; do 9 | wget "https://zenodo.org/record/7882613/files/dev_${machine_type}.zip" 10 | unzip "dev_${machine_type}.zip" 11 | done 12 | 13 | # download eval data 14 | cd - 15 | cd "${ROOT_DIR}/data/dcase2023t2/eval_data/raw" 16 | for machine_type in bandsaw grinder shaker ToyDrone ToyNscale ToyTank Vacuum; do 17 | wget "https://zenodo.org/record/7830345/files/eval_data_${machine_type}_train.zip" 18 | unzip "eval_data_${machine_type}_train.zip" 19 | 20 | wget "https://zenodo.org/record/7860847/files/eval_data_${machine_type}_test.zip" 21 | unzip "eval_data_${machine_type}_test.zip" 22 | done 23 | 24 | # Adds reference labels to test data. 25 | python ${ROOT_DIR}/tools/rename_eval_wav.py --dataset_parent_dir=${parent_dir} --dataset_type=DCASE2023T2 26 | -------------------------------------------------------------------------------- /tools/data_download_2024.sh: -------------------------------------------------------------------------------- 1 | parent_dir=data 2 | ROOT_DIR=$(cd $(dirname $0); pwd)/../ 3 | mkdir -p "${ROOT_DIR}/${parent_dir}/dcase2024t2/dev_data/raw" 4 | mkdir -p "${ROOT_DIR}/${parent_dir}/dcase2024t2/eval_data/raw" 5 | 6 | # download dev data 7 | cd "data/dcase2024t2/dev_data/raw" 8 | for machine_type in bearing fan gearbox slider ToyCar ToyTrain valve; do 9 | wget "https://zenodo.org/record/10902294/files/dev_${machine_type}.zip" 10 | unzip "dev_${machine_type}.zip" 11 | done 12 | 13 | # download eval data 14 | cd - 15 | cd "data/dcase2024t2/eval_data/raw" 16 | for machine_type in \ 17 | 3DPrinter_train_r2 \ 18 | AirCompressor_train \ 19 | Scanner_train \ 20 | ToyCircuit_train \ 21 | HoveringDrone_train \ 22 | HairDryer_train \ 23 | ToothBrush_train \ 24 | RoboticArm_train_r2 \ 25 | BrushlessMotor_train \ 26 | ; do 27 | wget "https://zenodo.org/records/11259435/files/eval_data_${machine_type}.zip" 28 | unzip "eval_data_${machine_type}.zip" 29 | done 30 | 31 | for machine_type in \ 32 | 3DPrinter \ 33 | AirCompressor \ 34 | Scanner \ 35 | ToyCircuit \ 36 | HoveringDrone \ 37 | HairDryer \ 38 | ToothBrush \ 39 | RoboticArm \ 40 | BrushlessMotor \ 41 | ; do 42 | wget "https://zenodo.org/records/11363076/files/eval_data_${machine_type}_test.zip" 43 | unzip "eval_data_${machine_type}_test.zip" 44 | done 45 | 46 | # Adds reference labels to test data. 47 | python ${ROOT_DIR}/tools/rename_eval_wav.py --dataset_parent_dir=${parent_dir} --dataset_type=DCASE2024T2 48 | -------------------------------------------------------------------------------- /tools/export_results.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import csv 3 | import numpy as np 4 | import pandas as pd 5 | import glob 6 | import sys 7 | import os 8 | from scipy import stats 9 | 10 | if __name__ == "__main__": 11 | sys.path.append(os.path.join(os.path.dirname(__file__), '..')) 12 | from datasets.loader_common import get_machine_type_dict 13 | 14 | def load_target_dir_list(parent_dir): 15 | files = os.listdir(parent_dir) 16 | target_dirs = [dir for dir in files if os.path.isdir(os.path.join(parent_dir,dir))] 17 | return target_dirs 18 | 19 | def get_column_basename(machine_type, dev_eval, index, column, tag): 20 | return f"{machine_type}_{dev_eval}_{index}_{column}{tag}" 21 | 22 | def column_to_1d(columns_header, indices, machine_type_dict): 23 | new_columns_header = [] 24 | tag_list = ["_ave", "_std", "_hmean"] 25 | for machine_type in machine_type_dict: 26 | for dev_eval in machine_type_dict[machine_type]: 27 | for column in columns_header: 28 | for index in machine_type_dict[machine_type][dev_eval]: 29 | for tag in tag_list: 30 | basename = get_column_basename( 31 | machine_type=machine_type, 32 | dev_eval=dev_eval, 33 | column=column, 34 | index=index, 35 | tag=tag 36 | ) 37 | new_columns_header.append(basename) 38 | for index in indices: 39 | basename = get_column_basename( 40 | machine_type=machine_type, 41 | dev_eval=dev_eval, 42 | column=column, 43 | index=index, 44 | tag="" 45 | ) 46 | new_columns_header.append(basename) 47 | 48 | for column in columns_header: 49 | for tag in tag_list: 50 | new_columns_header.append(f"ALL_{column}_{tag}") 51 | return new_columns_header 52 | 53 | def df_to_1d(df, machine_type, dev_eval, file_name): 54 | columns = df.columns.values 55 | indices = df.index.values 56 | summarize_df = pd.DataFrame(index=[file_name]) 57 | for column in columns: 58 | for index in indices: 59 | base_name = get_column_basename( 60 | machine_type=machine_type, 61 | dev_eval=dev_eval, 62 | index=index, 63 | column=column, 64 | tag="" 65 | ) 66 | summarize_df[base_name] = df.at[index, column] 67 | return summarize_df 68 | 69 | def describe_df(df, df_1d, columns, file_name): 70 | describe_1d = df_1d.describe() 71 | describe_1d.loc["hmean"] = stats.hmean(np.maximum(df_1d, sys.float_info.epsilon),axis=0) 72 | describe_df = pd.DataFrame(index=[file_name]) 73 | describe = df.describe() 74 | describe.loc["hmean"] = stats.hmean(np.maximum(df, sys.float_info.epsilon),axis=0) 75 | for column_1d in columns: 76 | if column_1d in describe_1d.columns: 77 | describe_df[f"{column_1d}_ave"] = describe_1d.at["mean", column_1d] 78 | describe_df[f"{column_1d}_std"] = describe_1d.at["std", column_1d] 79 | describe_df[f"{column_1d}_hmean"] = describe_1d.at["hmean", column_1d] 80 | else: 81 | for column in describe.columns: 82 | if "_"+column in column_1d: 83 | if "arithmetic mean" in column_1d: 84 | describe_df[f"{column_1d}"] = describe.at["mean", column] 85 | break 86 | if "harmonic mean" in column_1d: 87 | describe_df[f"{column_1d}"] = describe.at["hmean", column] 88 | break 89 | return describe_df 90 | 91 | def calc_all_mean(df, columns_header, machine_type_dict, df_mean): 92 | for column in columns_header: 93 | new_column_header = [] 94 | for machine_type in machine_type_dict: 95 | for dev_eval in machine_type_dict[machine_type]: 96 | new_column_header.append(f"{machine_type}_{dev_eval}_arithmetic mean_{column}") 97 | new_column_header = [new_column for new_column in new_column_header if new_column in df.columns.values.tolist()] 98 | df_tmp = df.loc[:, new_column_header] 99 | df[f"ALL_{column}_ave"] = df_tmp.mean(axis=1) 100 | df[f"ALL_{column}_std"] = df_tmp.std(axis=1) 101 | df[f"ALL_{column}_hmean"] = df_mean[column] 102 | df["ALL_AUC_ave"] = df_mean["AUC_ave"] 103 | df["ALL_AUC_std"] = df_mean["AUC_std"] 104 | df["ALL_AUC_hmean"] = df_mean["AUC_hmean"] 105 | df["TOTAL_score_ave"] = df_mean["TOTAL_ave"] 106 | df["TOTAL_score_std"] = df_mean["TOTAL_std"] 107 | df["TOTAL_score_hmean"] = df_mean["TOTAL_hmean"] 108 | return df 109 | 110 | def main(parent_dir, dataset, machine_type_dict, row_index=["arithmetic mean", "harmonic mean"]): 111 | target_dir_list = sorted(load_target_dir_list(parent_dir)) 112 | auc_dict = {} 113 | summarize_df = pd.DataFrame() 114 | 115 | df_mean = pd.DataFrame() 116 | all_columns_header = set() 117 | for target_dir in target_dir_list: 118 | auc_dict[target_dir] = {} 119 | df_target = pd.DataFrame() 120 | columns_header = set() 121 | for machine_name in machine_type_dict.keys(): 122 | auc_dict[target_dir][machine_name] = {} 123 | files = sorted(glob.glob(f"{args.parent_dir}/{target_dir}/*{dataset}{machine_name}*roc.csv")) 124 | file_dict = { 125 | "eval":[file for file in files if "Eval" in file], 126 | "dev":[file for file in files if "Eval" not in file] 127 | } 128 | 129 | for dev_eval in file_dict: 130 | df_machine_type_1d = pd.DataFrame() 131 | df_machine_type = pd.DataFrame() 132 | for file in file_dict[dev_eval]: 133 | df = pd.read_csv(file, index_col=0) 134 | columns_header = columns_header.union(df.columns.values.tolist()) 135 | columns = df_to_1d( 136 | df=df, 137 | machine_type=machine_name, 138 | dev_eval=dev_eval, 139 | file_name=file 140 | ).columns.values.tolist() 141 | df_extract = df.drop(row_index,axis=0) 142 | df_1d_extract = df_to_1d( 143 | df=df_extract, 144 | machine_type=machine_name, 145 | dev_eval=dev_eval, 146 | file_name=file 147 | ) 148 | df_machine_type_1d = pd.concat([df_machine_type_1d, df_1d_extract]) 149 | df_machine_type = pd.concat([df_machine_type, df_extract]) 150 | df_target = pd.concat([df_target, df_machine_type]) 151 | if len(df_machine_type_1d.index) > 0: 152 | df_describe = describe_df( 153 | df=df_machine_type, 154 | df_1d=df_machine_type_1d, 155 | file_name=target_dir, 156 | columns=columns, 157 | ) 158 | for column in df_describe.columns.values: 159 | summarize_df.at[target_dir, column] = df_describe.at[target_dir, column] 160 | auc_header = [column for column in columns_header if "AUC" in column] 161 | if "pAUC" in auc_header: 162 | auc_header = [column for column in auc_header if "pAUC" not in column or column == "pAUC"] 163 | df_mean.loc[target_dir, list(columns_header)] = stats.hmean(np.maximum(df_target.loc[:,list(columns_header)], sys.float_info.epsilon),axis=0) 164 | df_mean.loc[target_dir, "TOTAL_hmean"] = stats.hmean(np.maximum(df_target.loc[:,auc_header], sys.float_info.epsilon),axis=None) 165 | df_mean.loc[target_dir, "TOTAL_ave"] = df_target.loc[:,auc_header].to_numpy().mean() 166 | df_mean.loc[target_dir, "TOTAL_std"] = df_target.loc[:,auc_header].to_numpy().std() 167 | auc_header = [column for column in auc_header if "pAUC" not in column] 168 | df_mean.loc[target_dir, "AUC_hmean"] = stats.hmean(np.maximum(df_target.loc[:,auc_header], sys.float_info.epsilon),axis=None) 169 | df_mean.loc[target_dir, "AUC_ave"] = df_target.loc[:,auc_header].to_numpy().mean() 170 | df_mean.loc[target_dir, "AUC_std"] = df_target.loc[:,auc_header].to_numpy().std() 171 | all_columns_header = all_columns_header.union(columns_header) 172 | summarize_df = calc_all_mean( 173 | df=summarize_df, 174 | columns_header=list(all_columns_header), 175 | machine_type_dict=machine_type_dict, 176 | df_mean = df_mean 177 | ) 178 | export_file_path = f"{parent_dir}/{dataset}_auc_pauc.csv" 179 | summarize_df.to_csv(export_file_path) 180 | print(f"export concat results -> {export_file_path}") 181 | 182 | if __name__=="__main__": 183 | parser = argparse.ArgumentParser( 184 | description='Main function to call training for different AutoEncoders') 185 | parser.add_argument("parent_dir", type=str) 186 | parser.add_argument("--dataset", type=str, default="DCASE2020T2", 187 | choices=[ 188 | "DCASE2020T2", 189 | "DCASE2021T2", 190 | "DCASE2022T2", 191 | "DCASE2023T2", 192 | "DCASE2024T2", 193 | "DCASE2025T2", 194 | ]) 195 | parser.add_argument('-d', '--dev', action='store_true', 196 | help='Use Development dataset') 197 | parser.add_argument('-e', '--eval', action='store_true', 198 | help='Use Evaluation dataset') 199 | args = parser.parse_args() 200 | 201 | if args.eval: 202 | dev_mode = False 203 | elif args.dev: 204 | dev_mode = True 205 | else: 206 | print("incorrect argument") 207 | print("please set option argument '--dev' or '--eval'") 208 | sys.exit() 209 | 210 | machine_type_dict = get_machine_type_dict(dataset_name=args.dataset, mode=dev_mode) 211 | 212 | main( 213 | parent_dir=args.parent_dir, 214 | machine_type_dict=machine_type_dict["machine_type"], 215 | dataset=args.dataset, 216 | ) -------------------------------------------------------------------------------- /tools/export_results.sh: -------------------------------------------------------------------------------- 1 | # results output dir 2 | arg=("$@") 3 | dataset=${arg[0]} 4 | export_dir=${arg[1]} 5 | float_format=${arg[2]} 6 | dev_eval=${arg[3]} 7 | 8 | echo "export_dir : ${export_dir}" 9 | 10 | for ((i=4; i<$#; i++)) do 11 | id_single_dirs="${id_single_dirs} ${arg[i]}" 12 | done 13 | 14 | # aggregate results by machine type 15 | for dir in $id_single_dirs 16 | do 17 | echo $dir 18 | python3 tools/concat_divided_roc.py \ 19 | --parent_dir ${dir} \ 20 | --export_dir ${export_dir} \ 21 | --dataset ${dataset} \ 22 | ${dev_eval} \ 23 | 24 | done 25 | 26 | # summarize all results 27 | python3 tools/export_results.py "${export_dir}/" --dataset=${dataset} ${dev_eval} 28 | # extract the AUC mean 29 | python3 tools/extract_results.py "${export_dir}/" --dataset=${dataset} --float_format=${float_format} ${dev_eval} 30 | echo "====================================================" -------------------------------------------------------------------------------- /tools/extract_results.py: -------------------------------------------------------------------------------- 1 | 2 | import argparse 3 | import csv 4 | import numpy as np 5 | import sys 6 | import os 7 | import pandas as pd 8 | if __name__ == "__main__": 9 | sys.path.append(os.path.join(os.path.dirname(__file__), '..')) 10 | from datasets.loader_common import get_machine_type_dict 11 | 12 | SCORE_COLUMNS = ["h-mean", "a-mean"] 13 | SCORE_INDEXES = ["AUC (source)", "AUC (target)", "pAUC (source, target)", "pAUC (source)", "pAUC (target)", "AUC", "pAUC", "TOTAL score"] 14 | 15 | if __name__ == "__main__": 16 | parser = argparse.ArgumentParser( 17 | description='Main function to call training for different AutoEncoders') 18 | parser.add_argument("parent_dir", type=str) 19 | parser.add_argument("--file_name", type=str, default="auc_pauc") 20 | parser.add_argument("--ext", type=str, default=".csv") 21 | parser.add_argument("--dataset", type=str, default="DCASE2020T2", 22 | choices=[ 23 | "DCASE2020T2", 24 | "DCASE2021T2", 25 | "DCASE2022T2", 26 | "DCASE2023T2", 27 | "DCASE2024T2", 28 | "DCASE2025T2", 29 | ]) 30 | parser.add_argument("--float_format", type=str, default="%.4f") 31 | parser.add_argument('-d', '--dev', action='store_true', 32 | help='Use Development dataset') 33 | parser.add_argument('-e', '--eval', action='store_true', 34 | help='Use Evaluation dataset') 35 | args = parser.parse_args() 36 | 37 | if args.eval: 38 | dev_mode = False 39 | dev_eval = "eval" 40 | elif args.dev: 41 | dev_mode = True 42 | dev_eval="dev" 43 | else: 44 | print("incorrect argument") 45 | print("please set option argument '--dev' or '--eval'") 46 | sys.exit() 47 | 48 | float_format = args.float_format 49 | if float_format in ["None", "none", "", " "]: 50 | float_format = None 51 | 52 | file_path = f"{args.parent_dir}/{args.dataset}_{args.file_name}{args.ext}" 53 | machine_type_dict = get_machine_type_dict(dataset_name=args.dataset, mode=dev_mode) 54 | machine_type_list = list(machine_type_dict["machine_type"].keys()) 55 | 56 | all_summarize_df = pd.read_csv(file_path, index_col=0) 57 | 58 | index_df = pd.DataFrame({ 59 | "System":all_summarize_df.index.values.tolist(), 60 | "metric":["TOTAL score"] * len(all_summarize_df.index) 61 | }) 62 | multi_index = pd.MultiIndex.from_frame(index_df) 63 | extract_df = pd.DataFrame( 64 | index=multi_index, 65 | columns=SCORE_COLUMNS + machine_type_list 66 | ) 67 | 68 | # source and target domain results 69 | use_source_target = False 70 | for domain in ["source", "target"]: 71 | is_pick_mean = False 72 | for machine_type in machine_type_list: 73 | loc_column = f"{machine_type}_{dev_eval}_arithmetic mean_AUC ({domain})" 74 | if loc_column in all_summarize_df.columns.values.tolist(): 75 | is_pick_mean = True 76 | for index in all_summarize_df.index: 77 | extract_df.at[(index, f"AUC ({domain})"), machine_type] = all_summarize_df.loc[index, loc_column] 78 | if is_pick_mean: 79 | use_source_target = True 80 | for index in all_summarize_df.index: 81 | extract_df.at[(index, f"AUC ({domain})"), "a-mean"] = all_summarize_df.loc[index, f"ALL_AUC ({domain})_ave"] 82 | extract_df.at[(index, f"AUC ({domain})"), "h-mean"] = all_summarize_df.loc[index, f"ALL_AUC ({domain})_hmean"] 83 | 84 | # single domain results 85 | loc_column_list = [] 86 | is_pick_mean = False 87 | if not use_source_target: 88 | for machine_type in machine_type_list: 89 | loc_column = f"{machine_type}_{dev_eval}_arithmetic mean_AUC" 90 | if loc_column in all_summarize_df.columns.values.tolist(): 91 | is_pick_mean = True 92 | for index in all_summarize_df.index: 93 | extract_df.at[(index, "AUC"), machine_type] = all_summarize_df.loc[index, loc_column] 94 | if is_pick_mean: 95 | for index in all_summarize_df.index: 96 | extract_df.at[(index, "AUC"), "a-mean"] = all_summarize_df.loc[index, f"ALL_AUC_ave"] 97 | extract_df.at[(index, "AUC"), "h-mean"] = all_summarize_df.loc[index, f"ALL_AUC_hmean"] 98 | 99 | # pAUC 100 | is_pick_mean = False 101 | extract_columns = ["pAUC (source, target)"] if use_source_target else ["pAUC"] 102 | pickup_columns = ["pAUC"] 103 | if use_source_target and not any([pickup_columns[0] in c for c in all_summarize_df.columns]): 104 | extract_columns = ["pAUC (source)", "pAUC (target)"] 105 | pickup_columns = ["pAUC (source)", "pAUC (target)"] 106 | for pickup_column, extract_column in zip(pickup_columns, extract_columns): 107 | for machine_type in machine_type_list: 108 | loc_column = f"{machine_type}_{dev_eval}_arithmetic mean_{pickup_column}" 109 | if loc_column in all_summarize_df.columns.values.tolist(): 110 | is_pick_mean = True 111 | for index in all_summarize_df.index: 112 | extract_df.at[(index, extract_column), machine_type] = all_summarize_df.loc[index, loc_column] 113 | if is_pick_mean: 114 | for index in all_summarize_df.index: 115 | extract_df.at[(index, extract_column), "a-mean"] = all_summarize_df.loc[index, f"ALL_{pickup_column}_ave"] 116 | extract_df.at[(index, extract_column), "h-mean"] = all_summarize_df.loc[index, f"ALL_{pickup_column}_hmean"] 117 | 118 | # Total score 119 | for index in all_summarize_df.index: 120 | extract_df.at[(index, "TOTAL score"), "a-mean"] = all_summarize_df.loc[index, f"TOTAL_score_ave"] 121 | extract_df.at[(index, "TOTAL score"), "h-mean"] = all_summarize_df.loc[index, f"TOTAL_score_hmean"] 122 | 123 | # Sort results 124 | extract_df["order"] = [SCORE_INDEXES.index(metric) for _, metric in extract_df.index] 125 | extract_df = extract_df.sort_values("order") 126 | extract_df = extract_df.sort_index(level="System", sort_remaining=False) 127 | extract_df = extract_df.drop("order", axis=1) 128 | 129 | export_file_path = f"{args.parent_dir}/{args.dataset}_{args.file_name}_extract{args.ext}" 130 | extract_df.astype(np.float64).to_csv(export_file_path, float_format=float_format) 131 | print(f"export extract results -> {export_file_path}") 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /tools/plot_anm_score.py: -------------------------------------------------------------------------------- 1 | from tools.plot_common import Figdata, show_figs 2 | 3 | class AnmScoreFigData(): 4 | def __init__(self): 5 | self.figdatas = [] 6 | 7 | def anm_score_to_figdata(self, scores, title=""): 8 | nml_scores = [x[1] for x in scores if x[0]==0] 9 | anm_scores = [x[1] for x in scores if x[0]==1] 10 | 11 | figdata = Figdata( 12 | data=nml_scores, 13 | data2=anm_scores, 14 | type="boxplot", 15 | labels=["nml","anm"], 16 | ylabel="score", 17 | title=title 18 | ) 19 | 20 | return figdata 21 | 22 | 23 | def append_figdata(self, figdata): 24 | self.figdatas.append(figdata) 25 | 26 | 27 | def show_fig(self, title="anm_score", export_dir="results", is_display_console=False): 28 | show_figs( 29 | *self.figdatas, 30 | fold_interval=len(self.figdatas), 31 | sup_title=title, 32 | export_path=f"{export_dir}/{title}.png", 33 | is_display_console=is_display_console 34 | ) 35 | -------------------------------------------------------------------------------- /tools/plot_common.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | import sys 5 | import os 6 | import matplotlib.pyplot as plt 7 | import matplotlib.ticker as ticker # to use Formatter and Locator 8 | import matplotlib.patches as patches 9 | import numpy as np 10 | import librosa 11 | import math 12 | import seaborn as sns 13 | import pandas as pd 14 | #import soundfile as sf 15 | #import scipy.io.wavfile as wio 16 | 17 | 18 | font_scalings = { 19 | 'xx-small' : 0.579, 20 | 'x-small' : 0.694, 21 | 'small' : 0.833, 22 | 'medium' : 1.0, 23 | 'large' : 1.200, 24 | 'x-large' : 1.440, 25 | 'xx-large' : 1.728, 26 | 'larger' : 1.2, 27 | 'smaller' : 0.833, 28 | None : 1.0 29 | } 30 | 31 | plot_type = { 32 | 'plot', 33 | 'boxplot', 34 | 'scatter', 35 | 'bar', 36 | 'barth', 37 | 'hist', 38 | 'image', 39 | 'confusion_matrix', 40 | None 41 | } 42 | 43 | class Figdata: 44 | def __init__(self, data, data2=[], type=None, labels=None, title=None, xlabel=None, ylabel=None, xticks=None, yticks=None, xlim=None, ylim=None, color=None, color2=None, mask=None, highlight_label=[]): 45 | self.data = data 46 | self.data2 = data2 47 | self.type = type 48 | self.title = title 49 | self.xlabel = xlabel 50 | self.ylabel = ylabel 51 | self.xticks = xticks 52 | self.yticks = yticks 53 | self.xlim = xlim 54 | self.ylim = ylim 55 | self.color = color 56 | self.color2 = color2 57 | self.labels = labels 58 | self.highlight_label = highlight_label 59 | 60 | 61 | def show_figs(*args, sup_title=None, sup_titlesize=None, dpi=100, width_mm=120, height_mm=30, 62 | margin_top_mm=15, margin_bottom_mm=15, margin_left_mm=25, margin_right_mm=15, margin_middle_mm=15, 63 | fold_interval=0, export_path="fig.png", is_display_console=False): 64 | num_figs_x = math.ceil(len(args)/fold_interval) 65 | num_figs_y = fold_interval 66 | #print('In show_figure(*args, sup_title=None, dpi=100, width_mm=120, height_mm=30)') 67 | #print("args: %d" % (num_figs)) 68 | #print("figsize: ", (plt.rcParams["figure.figsize"])) 69 | #print("dpi: ", (plt.rcParams["figure.dpi"])) 70 | #print("fontsize:", plt.rcParams["font.size"]) 71 | #print("supsize:", plt.rcParams["figure.titlesize"]) 72 | 73 | font_size = plt.rcParams["font.size"] 74 | font_scale = font_scalings[plt.rcParams["axes.titlesize"]] 75 | title_size = font_size * font_scale 76 | if sup_titlesize: 77 | #print(sup_titlesize) 78 | if sup_titlesize in font_scalings: 79 | font_scale = font_scalings[sup_titlesize] 80 | title_size = font_size * font_scale 81 | else: 82 | title_size = sup_titlesize 83 | #print(title_size) 84 | 85 | #print("title fontsize: ", font_size) 86 | #print("title font scale: ", font_scale) 87 | #print("title size: ", title_size) 88 | 89 | plt.style.use('dark_background') 90 | #width_mm = 120 91 | #height_mm = 30 92 | #margin_top_mm = 15 93 | #margin_bottom_mm = 15 94 | #margin_left_mm = 25 95 | #margin_right_mm = 10 96 | #margin_middle_mm = 15 97 | mm_per_inch = 25.4 98 | total_height_mm = margin_top_mm + margin_bottom_mm + (margin_middle_mm + height_mm)*(num_figs_y-1) + height_mm 99 | total_width_mm = width_mm + margin_left_mm + margin_right_mm + (margin_middle_mm + width_mm)*(num_figs_x-1) 100 | 101 | width_inch = width_mm / mm_per_inch 102 | height_inch = height_mm / mm_per_inch 103 | margin_top_inch = margin_top_mm / mm_per_inch 104 | margin_bottom_inch = margin_bottom_mm / mm_per_inch 105 | margin_left_inch = margin_left_mm / mm_per_inch 106 | margin_middle_inch = margin_middle_mm / mm_per_inch 107 | total_height_inch = total_height_mm / mm_per_inch 108 | total_width_inch = total_width_mm / mm_per_inch 109 | 110 | fig = plt.figure(figsize=(total_width_inch, total_height_inch), dpi=dpi) 111 | ax = [] 112 | for idx in range(len(args)): 113 | height = height_inch / total_height_inch 114 | width = width_inch / total_width_inch 115 | x0 = (margin_left_inch + (width_inch + margin_middle_inch)*(num_figs_x - 1 - idx//fold_interval)) / total_width_inch 116 | y0 = (margin_bottom_inch + (height_inch + margin_middle_inch)*(num_figs_y - 1 - idx%fold_interval)) / total_height_inch 117 | ax.append(fig.add_axes((x0, y0, width, height))) 118 | if type(args[idx]) is Figdata: 119 | if args[idx].type == None or args[idx].type == 'plot': 120 | if args[idx].color: 121 | ax[idx].plot(args[idx].data, color=args[idx].color) 122 | else: 123 | ax[idx].plot(args[idx].data) 124 | data2 = np.array(args[idx].data2) 125 | if len(data2.shape) != 0: 126 | if len(data2.shape) == 2: 127 | for d in data2: 128 | if args[idx].color2: 129 | ax[idx].plot(d, color=args[idx].color2) 130 | else: 131 | ax[idx].plot(d) 132 | else: 133 | if args[idx].color2: 134 | ax[idx].plot(data2, color=args[idx].color2) 135 | else: 136 | ax[idx].plot(data2) 137 | if args[idx].labels: 138 | ax[idx].legend(args[idx].labels) 139 | elif args[idx].type == 'boxplot': 140 | if len(np.shape(args[idx].data2)) > 1: 141 | ax[idx].boxplot((args[idx].data, *args[idx].data2), vert=False, showmeans=True, widths=0.7, labels=args[idx].labels) 142 | else: 143 | if len(args[idx].data2) != 0: 144 | ax[idx].boxplot((args[idx].data, args[idx].data2), vert=False, showmeans=True, widths=0.7, labels=args[idx].labels) 145 | else: 146 | ax[idx].boxplot(args[idx].data, vert=False, showmeans=True, widths=0.7, labels=args[idx].labels) 147 | elif args[idx].type == 'image' : 148 | im = plt.imshow(args[idx].data) 149 | if args[idx].data.shape[2] == 1: 150 | plt.colorbar(im) 151 | elif args[idx].type == 'confusion_matrix' : 152 | heatmap = sns.heatmap( 153 | args[idx].data, 154 | annot=True, 155 | xticklabels=args[idx].xticks, 156 | yticklabels=args[idx].yticks, 157 | fmt="d" 158 | ) 159 | for i in range(len(args[idx].highlight_label)): 160 | if args[idx].highlight_label[i] >= 0: 161 | heatmap.get_xticklabels()[args[idx].highlight_label[i]].set_weight("bold") 162 | heatmap.get_xticklabels()[args[idx].highlight_label[i]].set_color("#00ff00") 163 | heatmap.get_yticklabels()[i].set_weight("bold") 164 | heatmap.get_yticklabels()[i].set_color("#00ff00") 165 | heatmap.add_patch(patches.Rectangle(xy=(args[idx].highlight_label[i], i), width=1, height=1, ec='#00ff00', fill=False, linewidth=3)) 166 | if args[idx].xlabel: 167 | ax[idx].set_xlabel(args[idx].xlabel) 168 | if args[idx].ylabel: 169 | ax[idx].set_ylabel(args[idx].ylabel) 170 | if args[idx].title: 171 | ax[idx].set_title(args[idx].title, loc='left') 172 | if args[idx].xlim: 173 | ax[idx].set_xlim(args[idx].xlim) 174 | if args[idx].ylim: 175 | ax[idx].set_ylim(args[idx].ylim) 176 | else: 177 | ax[idx].plot(args[idx]) 178 | if sup_title: 179 | fig.suptitle(sup_title, y=(1 - 0.3 * margin_top_inch / total_height_inch), fontsize=title_size) 180 | if is_display_console: 181 | plt.show() 182 | plt.savefig(export_path) 183 | print("export fig -> {}".format(export_path)) 184 | plt.close() 185 | return 186 | 187 | 188 | @ticker.FuncFormatter 189 | def major_formatter_khz(y, pos): 190 | return '{:.0f}'.format(y/1000) 191 | 192 | if __name__ == '__main__': 193 | 194 | #print("figsize: ", (plt.rcParams["figure.figsize"])) 195 | #print("dpi: ", (plt.rcParams["figure.dpi"])) 196 | 197 | n_fft:int = 2048 198 | n_shift:int = 1024 199 | n_overlap = n_fft // n_shift 200 | 201 | x = np.linspace(0, 2*np.pi, 2048) 202 | vector1 = np.cos(x) 203 | vector2 = np.sin(x) 204 | 205 | filename = "./avemaria.wav" 206 | # y, sr = librosa.load(filename, sr=None, mono=False) # read all 207 | y1, sr = librosa.load(filename, sr=None, mono=False, offset=3.0, duration=1.0) # read for 3 seconds to 1 second 208 | y2, sr = librosa.load(filename, sr=None, mono=False, offset=6.5, duration=1.0) # read for 6.5 seconds to 1 second 209 | # if stereo 2ch, split int Lch and Rch 210 | y1_l = y1[0, :] 211 | y1_r = y1[1, :] 212 | y2_l = y2[0, :] 213 | y2_r = y2[1, :] 214 | 215 | ymax = max(max(y1_l),max(y1_r),max(y2_l),max(y2_r)) 216 | ymin = min(min(y1_l),min(y1_r),min(y2_l),min(y2_l)) 217 | #ymax = max(abs(ymax),abs(ymin)) 218 | #ymin = -ymax 219 | #ymax = 1 220 | #ymin = -1 221 | 222 | S = librosa.stft(y2_l, n_fft=n_fft, window='hamm') 223 | f0y_0 = Figdata(np.abs(S)[200], data2=np.full(len(np.abs(S[200])), 0.1), xlabel="freq", ylabel="magnitude", color='g', title="FFT: abs") 224 | f0y_1 = Figdata(np.log(np.abs(S)[200]), xlabel="freq", ylabel="magnitude", color='r', title="FFT: log(abs)") 225 | f0y_2 = Figdata(np.angle(S)[200], data2='5', xlabel="freq", ylabel="magnitude", title="FFT: angle") 226 | f1y_l = Figdata(y1_l, xlabel="freq", ylabel="magnitude", title="Fig1", ylim=(ymin,ymax)) 227 | f1y_r = Figdata(y1_r, xlabel="freq", ylabel="magnitude", title="Fig2", ylim=(ymin,ymax)) 228 | f2y_l = Figdata(y2_l, data2=np.full(len(y2_l), 0.3), color2='yellow', xlabel="freq", ylabel="magnitude", title="Fig3", ylim=(ymin,ymax)) 229 | f2y_r = Figdata(y2_r, xlabel="freq", ylabel="magnitude", title="Fig4", ylim=(ymin,ymax)) 230 | s1 = Figdata(np.random.randn(100), data2=np.random.randn(200), type='boxplot', color='r', ylabel='condition', xlabel='anomaly score', title='baseline AE', labels=['anomaly', 'normal']) 231 | 232 | show_figs(vector1, f0y_0, f0y_1, f0y_2, f1y_l, s1, f1y_r, f2y_l, f2y_r, sup_title="test", sup_titlesize='xx-large', dpi=70) 233 | -------------------------------------------------------------------------------- /tools/plot_loss_curve.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import csv 3 | import os 4 | import pathlib 5 | if __name__ == "__main__": 6 | from plot_common import Figdata, show_figs 7 | else: 8 | from tools.plot_common import Figdata, show_figs 9 | 10 | def csv_to_figdata(file_path, column_heading_list=["loss"], xlabel="epoch", ylabel="loss", fig_count=1, cut_first_epoch=False, is_display_console=False): 11 | figdata_list = [] 12 | for i in range(fig_count): 13 | data_dict = {} 14 | column_heading_list_temp = column_heading_list[i] if fig_count > 1 else column_heading_list 15 | for column_heading in column_heading_list_temp: 16 | data_dict[column_heading] = [] 17 | 18 | with open(file_path) as f: 19 | reader = csv.DictReader(f) 20 | for row in reader: 21 | for column_heading in column_heading_list_temp: 22 | data_dict[column_heading].append(float(row[column_heading])) 23 | data_list = list(data_dict.values()) 24 | if cut_first_epoch: 25 | data_list = [ x[1:] for x in data_list ] 26 | if len(data_dict.keys()) >= 2: 27 | figdata_list.append(Figdata( 28 | data=data_list[0], 29 | data2=data_list[1:], 30 | type="plot", 31 | labels=column_heading_list_temp, 32 | xlabel=xlabel, 33 | ylabel=ylabel 34 | )) 35 | else: 36 | figdata_list.append(Figdata( 37 | data=data_list[0], 38 | type="plot", 39 | labels=column_heading_list_temp, 40 | xlabel=xlabel, 41 | ylabel=ylabel 42 | )) 43 | 44 | export_path =os.path.join(os.path.dirname(file_path), pathlib.PurePath(file_path).stem + ".png") 45 | show_figs( 46 | *figdata_list, 47 | sup_title=os.path.splitext(os.path.basename(file_path))[0], 48 | fold_interval=fig_count, 49 | export_path=export_path, 50 | is_display_console=is_display_console 51 | ) 52 | 53 | 54 | if __name__ == "__main__": 55 | parser = argparse.ArgumentParser( 56 | description='Main function to call training for different AutoEncoders') 57 | parser.add_argument("--file_path", type=str, default='../stable/', metavar='N') 58 | parser.add_argument("--column_heading", type=str, nargs='*', default=["loss"], metavar='N') 59 | parser.add_argument("--xlabel", type=str, default=["epoch"], metavar='N') 60 | parser.add_argument("--ylabel", type=str, default=["loss"], metavar='N') 61 | args = parser.parse_args() 62 | 63 | csv_to_figdata( 64 | file_path=args.file_path, 65 | column_heading_list=args.column_heading, 66 | xlabel=args.xlabel, 67 | ylabel=args.ylabel 68 | ) 69 | -------------------------------------------------------------------------------- /tools/plot_time_frequency.py: -------------------------------------------------------------------------------- 1 | import argparse, os, sys 2 | from tools.plot_common import Figdata, show_figs 3 | 4 | from datasets.datasets import Datasets 5 | 6 | import numpy as np 7 | import math 8 | import torch 9 | 10 | class TimeFrequencyFigData(): 11 | def __init__(self,max_imgs=1, max_extract=1, frames=5, frame_hop_length=1, shape=(1,128,5)): 12 | self.img_count = [0, 0] #[nml_count, anm_count] 13 | self.figdatas = [] 14 | self.max_imgs = max_imgs 15 | self.max_extract = max_extract 16 | self.anm_suffix = ["nml","anm"] 17 | self.frames = frames 18 | self.frame_hop_length = frame_hop_length 19 | self.shape = shape 20 | 21 | def append_figdata(self,data,label,machine_id,idx,fig_name="",is_fig_tern=False): 22 | if self.img_count[label] >= self.max_imgs: 23 | return 24 | imgs = data[ : self.frames*self.max_extract//self.frame_hop_length : self.frames//self.frame_hop_length].cpu() 25 | 26 | for i in range(len(imgs)): 27 | img = imgs[i] 28 | if is_fig_tern: 29 | img = torch.stack([img_tmp.T for img_tmp in img]) 30 | img = img.view(self.shape) 31 | self.figdatas.append(Figdata( 32 | img.T, 33 | type="image", 34 | title = "ID{id}-{idx}_{anm}\n{frame_min}-{frame_max}frame\n{fig_name}".format( 35 | id=machine_id, 36 | idx=idx, 37 | anm=self.anm_suffix[label], 38 | frame_min=i*self.frames, 39 | frame_max=(i+1)*self.frames, 40 | fig_name=fig_name 41 | ) 42 | )) 43 | self.img_count[label] += 1 44 | 45 | def show_fig(self, title="time_frequency", fold_interval=1, export_dir="results", is_display_console=False): 46 | show_figs( 47 | *self.figdatas, 48 | fold_interval=fold_interval, 49 | width_mm=50, 50 | margin_top_mm=30, 51 | margin_bottom_mm=30, 52 | margin_middle_mm=30, 53 | sup_title=title, 54 | export_path=f"{export_dir}/{title}.png", 55 | is_display_console=is_display_console 56 | ) 57 | 58 | def reset_count(self): 59 | self.img_count = [0, 0] 60 | -------------------------------------------------------------------------------- /tools/rename_eval_wav.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import csv 4 | import shutil 5 | import argparse 6 | from pathlib import Path 7 | 8 | ROOT_DIR = f"{os.path.dirname(os.path.abspath(__file__))}/../" 9 | os.chdir(ROOT_DIR) 10 | 11 | # labeled data path 12 | EVAL_DATA_LIST_PATH = { 13 | "DCASE2020T2":f"{ROOT_DIR}/datasets/eval_data_list_2020.csv", 14 | "DCASE2021T2":f"{ROOT_DIR}/datasets/eval_data_list_2021.csv", 15 | "DCASE2022T2":f"{ROOT_DIR}/datasets/eval_data_list_2022.csv", 16 | "DCASE2023T2":f"{ROOT_DIR}/datasets/eval_data_list_2023.csv", 17 | "DCASE2024T2":f"{ROOT_DIR}/datasets/eval_data_list_2024.csv", 18 | "DCASE2025T2":f"{ROOT_DIR}/datasets/eval_data_list_2025.csv", 19 | } 20 | 21 | FILENAME_COL = 0 22 | LABELING_FILENAME_COL = 1 23 | MACHINE_TYPE_COL = 0 24 | 25 | CHK_MACHINE_TYPE_LINE = 2 26 | 27 | def copy_wav(dataset_parent_dir, dataset_type): 28 | dataset_dir = str(Path(f"{ROOT_DIR}/{dataset_parent_dir}/raw/").relative_to(ROOT_DIR)) 29 | eval_data_list_path = EVAL_DATA_LIST_PATH[dataset_type] 30 | if not eval_data_list_path: 31 | return None 32 | 33 | if os.path.exists(eval_data_list_path): 34 | with open(eval_data_list_path) as fp: 35 | eval_data_list = list(csv.reader(fp)) 36 | else: 37 | print(f"Err:eval_data_list.csv not found : {eval_data_list_path}") 38 | sys.exit(1) 39 | 40 | count = 0 41 | print('copy... : test -> test_rename') 42 | for eval_data in eval_data_list: 43 | if len(eval_data) < CHK_MACHINE_TYPE_LINE: 44 | machine_type = eval_data[MACHINE_TYPE_COL] 45 | default_dir = dataset_dir.lower() + "/" + machine_type + "/test" 46 | save_dir = dataset_dir.lower() + "/" + machine_type + "/test_rename" 47 | if(not os.path.exists(save_dir)): 48 | Path(save_dir).mkdir(parents=True, exist_ok=True) 49 | count = 0 50 | sys.stdout.write('\n') 51 | sys.stdout.flush() 52 | else: 53 | if os.path.exists(default_dir + "/" + eval_data[FILENAME_COL]): 54 | shutil.copy2( 55 | default_dir + "/" + eval_data[FILENAME_COL], 56 | save_dir + "/" + eval_data[LABELING_FILENAME_COL]) 57 | count += 1 58 | sys.stdout.write(f'\r\t{machine_type}: {str(count)} files\tsaved dir: {save_dir}') 59 | sys.stdout.flush() 60 | sys.stdout.write('\n') 61 | 62 | if __name__ == "__main__": 63 | parser = argparse.ArgumentParser( 64 | description='Main function to call training for different AutoEncoders') 65 | parser.add_argument("--dataset_parent_dir", type=str, default="data", 66 | help="saving datasets directory name.") 67 | parser.add_argument("--dataset_type", type=str, required=True, 68 | choices=[ 69 | "DCASE2020T2", 70 | "DCASE2021T2", 71 | "DCASE2022T2", 72 | "DCASE2023T2", 73 | "DCASE2024T2", 74 | "DCASE2025T2", 75 | ], 76 | help="what Dataset name to renamed.") 77 | args = parser.parse_args() 78 | 79 | copy_wav( 80 | dataset_parent_dir=f"{args.dataset_parent_dir}/{args.dataset_type}/eval_data", 81 | dataset_type=args.dataset_type 82 | ) 83 | -------------------------------------------------------------------------------- /train.py: -------------------------------------------------------------------------------- 1 | import random 2 | import numpy as np 3 | import torch 4 | 5 | # original lib 6 | import common as com 7 | from networks.models import Models 8 | 9 | ######################################################################## 10 | # load parameter.yaml 11 | ######################################################################## 12 | param = com.yaml_load() 13 | ######################################################################## 14 | 15 | def main(): 16 | parser = com.get_argparse() 17 | # read parameters from yaml 18 | flat_param = com.param_to_args_list(params=param) 19 | args = parser.parse_args(args=flat_param) 20 | # read parameters from command line 21 | args = parser.parse_args(namespace=args) 22 | print(args) 23 | 24 | if args.train_only and args.test_only: 25 | raise ValueError("--train_only and --test_only cannot be used together.") 26 | elif args.train_only: 27 | train = True 28 | test = False 29 | elif args.test_only: 30 | train = False 31 | test = True 32 | else: 33 | train = True 34 | test = True 35 | 36 | args.cuda = args.use_cuda and torch.cuda.is_available() 37 | 38 | # Python random 39 | random.seed(args.seed) 40 | # Numpy 41 | np.random.seed(args.seed) 42 | # Pytorch 43 | torch.manual_seed(args.seed) 44 | torch.cuda.manual_seed(args.seed) 45 | torch.backends.cudnn.deterministic = True 46 | torch.use_deterministic_algorithms = True 47 | 48 | net = Models(args.model).net( 49 | args=args, 50 | train=train, 51 | test=test 52 | ) 53 | 54 | 55 | print(args.model) 56 | 57 | print("============== BEGIN TRAIN ==============") 58 | if train: 59 | for epoch in range(1, args.epochs + 2): 60 | net.train(epoch) 61 | print("============ END OF TRAIN ============") 62 | 63 | if test: 64 | net.test() 65 | 66 | if __name__ == "__main__": 67 | main() -------------------------------------------------------------------------------- /train_ae.sh: -------------------------------------------------------------------------------- 1 | echo $* 2 | 3 | dataset=$1 4 | dev_eval=$2 5 | id_1=$3 6 | id_2=$4 7 | id_3=$5 8 | id_4=$6 9 | 10 | id="$id_1 $id_2 $id_3 $id_4" 11 | 12 | echo dataset ${dataset} 13 | echo dev_eval ${dev_eval} 14 | echo id ${id} 15 | 16 | tag="id(" 17 | for i in ${id}; do 18 | tag="${tag}${i}_" 19 | done 20 | tag="${tag})" 21 | 22 | python3 train.py \ 23 | --dataset=${dataset} \ 24 | ${dev_eval} \ 25 | -tag=${tag} \ 26 | --use_ids ${id} \ 27 | --train_only \ 28 | --------------------------------------------------------------------------------