diff --git a/chirp/__init__.py b/chirp/__init__.py index 05320a6d..46a4d0dc 100644 --- a/chirp/__init__.py +++ b/chirp/__init__.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/audio_utils.py b/chirp/audio_utils.py index c2ae2ee4..dc9fb79a 100644 --- a/chirp/audio_utils.py +++ b/chirp/audio_utils.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/birb_sep_paper/audio_ops.py b/chirp/birb_sep_paper/audio_ops.py index 8eca9ced..d49147a5 100644 --- a/chirp/birb_sep_paper/audio_ops.py +++ b/chirp/birb_sep_paper/audio_ops.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/birb_sep_paper/beam_index.py b/chirp/birb_sep_paper/beam_index.py index 029b16de..4a0665bd 100644 --- a/chirp/birb_sep_paper/beam_index.py +++ b/chirp/birb_sep_paper/beam_index.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/birb_sep_paper/beam_inference.py b/chirp/birb_sep_paper/beam_inference.py index 37b07972..e5f823c9 100644 --- a/chirp/birb_sep_paper/beam_inference.py +++ b/chirp/birb_sep_paper/beam_inference.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/birb_sep_paper/data_tools.py b/chirp/birb_sep_paper/data_tools.py index 29691ddd..e0819a3d 100644 --- a/chirp/birb_sep_paper/data_tools.py +++ b/chirp/birb_sep_paper/data_tools.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/birb_sep_paper/dataset_info.py b/chirp/birb_sep_paper/dataset_info.py index f66efc95..ba6ca302 100644 --- a/chirp/birb_sep_paper/dataset_info.py +++ b/chirp/birb_sep_paper/dataset_info.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/birb_sep_paper/model_utils.py b/chirp/birb_sep_paper/model_utils.py index d831bf2e..4898d43f 100644 --- a/chirp/birb_sep_paper/model_utils.py +++ b/chirp/birb_sep_paper/model_utils.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/birb_sep_paper/pcen_ops.py b/chirp/birb_sep_paper/pcen_ops.py index 75b08109..54a847a2 100644 --- a/chirp/birb_sep_paper/pcen_ops.py +++ b/chirp/birb_sep_paper/pcen_ops.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/birb_sep_paper/taxonomy.py b/chirp/birb_sep_paper/taxonomy.py index cb233773..fcf39f2a 100644 --- a/chirp/birb_sep_paper/taxonomy.py +++ b/chirp/birb_sep_paper/taxonomy.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/config_utils.py b/chirp/config_utils.py index 075f065d..3e44c9ed 100644 --- a/chirp/config_utils.py +++ b/chirp/config_utils.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baseline.py b/chirp/configs/baseline.py index 369c037a..f00faef4 100644 --- a/chirp/configs/baseline.py +++ b/chirp/configs/baseline.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baseline_attention.py b/chirp/configs/baseline_attention.py index 8fa2f2bf..399a6641 100644 --- a/chirp/configs/baseline_attention.py +++ b/chirp/configs/baseline_attention.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baseline_mel_conformer.py b/chirp/configs/baseline_mel_conformer.py index 4a82f8fd..a4b347f4 100644 --- a/chirp/configs/baseline_mel_conformer.py +++ b/chirp/configs/baseline_mel_conformer.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/large_efficientnet_train_and_valid.py b/chirp/configs/baselines/large_efficientnet_train_and_valid.py index 64eae6cd..9ed9b120 100644 --- a/chirp/configs/baselines/large_efficientnet_train_and_valid.py +++ b/chirp/configs/baselines/large_efficientnet_train_and_valid.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/large_efficientnet_train_and_valid_ablation.py b/chirp/configs/baselines/large_efficientnet_train_and_valid_ablation.py index 85a11d1b..f6c77105 100644 --- a/chirp/configs/baselines/large_efficientnet_train_and_valid_ablation.py +++ b/chirp/configs/baselines/large_efficientnet_train_and_valid_ablation.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/large_mel_conformer_train_and_valid.py b/chirp/configs/baselines/large_mel_conformer_train_and_valid.py index 4f3fa7d6..476155e1 100644 --- a/chirp/configs/baselines/large_mel_conformer_train_and_valid.py +++ b/chirp/configs/baselines/large_mel_conformer_train_and_valid.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/large_mel_conformer_train_and_valid_ablation.py b/chirp/configs/baselines/large_mel_conformer_train_and_valid_ablation.py index 3638de56..152af633 100644 --- a/chirp/configs/baselines/large_mel_conformer_train_and_valid_ablation.py +++ b/chirp/configs/baselines/large_mel_conformer_train_and_valid_ablation.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/logistic_regression_train_and_valid.py b/chirp/configs/baselines/logistic_regression_train_and_valid.py index 1fdf1688..dac24d64 100644 --- a/chirp/configs/baselines/logistic_regression_train_and_valid.py +++ b/chirp/configs/baselines/logistic_regression_train_and_valid.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/logistic_regression_train_and_valid_ablation.py b/chirp/configs/baselines/logistic_regression_train_and_valid_ablation.py index 0ae10216..fb02e99a 100644 --- a/chirp/configs/baselines/logistic_regression_train_and_valid_ablation.py +++ b/chirp/configs/baselines/logistic_regression_train_and_valid_ablation.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/presets.py b/chirp/configs/baselines/presets.py index 9df9d630..e0d75b93 100644 --- a/chirp/configs/baselines/presets.py +++ b/chirp/configs/baselines/presets.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/small_efficientnet_train_and_valid.py b/chirp/configs/baselines/small_efficientnet_train_and_valid.py index 7d1b7634..4e098bea 100644 --- a/chirp/configs/baselines/small_efficientnet_train_and_valid.py +++ b/chirp/configs/baselines/small_efficientnet_train_and_valid.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/small_efficientnet_train_and_valid_ablation.py b/chirp/configs/baselines/small_efficientnet_train_and_valid_ablation.py index 06246fa5..964cd631 100644 --- a/chirp/configs/baselines/small_efficientnet_train_and_valid_ablation.py +++ b/chirp/configs/baselines/small_efficientnet_train_and_valid_ablation.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/small_mel_conformer_train_and_valid.py b/chirp/configs/baselines/small_mel_conformer_train_and_valid.py index b8e9255c..cc226162 100644 --- a/chirp/configs/baselines/small_mel_conformer_train_and_valid.py +++ b/chirp/configs/baselines/small_mel_conformer_train_and_valid.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/small_mel_conformer_train_and_valid_ablation.py b/chirp/configs/baselines/small_mel_conformer_train_and_valid_ablation.py index a0526ecf..9b41d890 100644 --- a/chirp/configs/baselines/small_mel_conformer_train_and_valid_ablation.py +++ b/chirp/configs/baselines/small_mel_conformer_train_and_valid_ablation.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/svm_train_and_valid.py b/chirp/configs/baselines/svm_train_and_valid.py index 09e40e91..e53db88f 100644 --- a/chirp/configs/baselines/svm_train_and_valid.py +++ b/chirp/configs/baselines/svm_train_and_valid.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/baselines/svm_train_and_valid_ablation.py b/chirp/configs/baselines/svm_train_and_valid_ablation.py index a9cc8f0c..812cc842 100644 --- a/chirp/configs/baselines/svm_train_and_valid_ablation.py +++ b/chirp/configs/baselines/svm_train_and_valid_ablation.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/config_globals.py b/chirp/configs/config_globals.py index 350270a7..5472f2de 100644 --- a/chirp/configs/config_globals.py +++ b/chirp/configs/config_globals.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/debugging/baseline.py b/chirp/configs/debugging/baseline.py index 2d5bc330..d58b53fa 100644 --- a/chirp/configs/debugging/baseline.py +++ b/chirp/configs/debugging/baseline.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/debugging/baseline_logistic_regression.py b/chirp/configs/debugging/baseline_logistic_regression.py index f8e154fe..b31e2656 100644 --- a/chirp/configs/debugging/baseline_logistic_regression.py +++ b/chirp/configs/debugging/baseline_logistic_regression.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/debugging/hubert.py b/chirp/configs/debugging/hubert.py index c8ad21a0..56f7fd91 100644 --- a/chirp/configs/debugging/hubert.py +++ b/chirp/configs/debugging/hubert.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/debugging/hubert_presets.py b/chirp/configs/debugging/hubert_presets.py index e4d894f0..2fafc839 100644 --- a/chirp/configs/debugging/hubert_presets.py +++ b/chirp/configs/debugging/hubert_presets.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/debugging/presets.py b/chirp/configs/debugging/presets.py index a9a64aa1..50736868 100644 --- a/chirp/configs/debugging/presets.py +++ b/chirp/configs/debugging/presets.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/eval_protocol_v1_base.py b/chirp/configs/eval_protocol_v1_base.py index 4420457d..7a03e066 100644 --- a/chirp/configs/eval_protocol_v1_base.py +++ b/chirp/configs/eval_protocol_v1_base.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/eval_protocol_v1_separatortf.py b/chirp/configs/eval_protocol_v1_separatortf.py index 34d3ebde..25bdbe2c 100644 --- a/chirp/configs/eval_protocol_v1_separatortf.py +++ b/chirp/configs/eval_protocol_v1_separatortf.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/eval_protocol_v2_base.py b/chirp/configs/eval_protocol_v2_base.py index 44357264..7eded2c8 100644 --- a/chirp/configs/eval_protocol_v2_base.py +++ b/chirp/configs/eval_protocol_v2_base.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/hubert_base_pq.py b/chirp/configs/hubert_base_pq.py index 6c083e35..07b87fb9 100644 --- a/chirp/configs/hubert_base_pq.py +++ b/chirp/configs/hubert_base_pq.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/hubert_base_pq_eval.py b/chirp/configs/hubert_base_pq_eval.py index 16643d1c..924bb3ae 100644 --- a/chirp/configs/hubert_base_pq_eval.py +++ b/chirp/configs/hubert_base_pq_eval.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/hubert_base_pq_reload_hubert.py b/chirp/configs/hubert_base_pq_reload_hubert.py index 56d62cef..9ddd07e1 100644 --- a/chirp/configs/hubert_base_pq_reload_hubert.py +++ b/chirp/configs/hubert_base_pq_reload_hubert.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/hubert_base_pq_semisupervised_finetuning.py b/chirp/configs/hubert_base_pq_semisupervised_finetuning.py index 4483c732..e1bf5c62 100644 --- a/chirp/configs/hubert_base_pq_semisupervised_finetuning.py +++ b/chirp/configs/hubert_base_pq_semisupervised_finetuning.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/hubert_base_pq_supervised_finetuning.py b/chirp/configs/hubert_base_pq_supervised_finetuning.py index 235d21d3..42ab45dc 100644 --- a/chirp/configs/hubert_base_pq_supervised_finetuning.py +++ b/chirp/configs/hubert_base_pq_supervised_finetuning.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/hubert_base_pq_with_intermediate.py b/chirp/configs/hubert_base_pq_with_intermediate.py index d5b4e629..9323818e 100644 --- a/chirp/configs/hubert_base_pq_with_intermediate.py +++ b/chirp/configs/hubert_base_pq_with_intermediate.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/hubert_base_rq.py b/chirp/configs/hubert_base_rq.py index 8e076315..55f8ad9f 100644 --- a/chirp/configs/hubert_base_rq.py +++ b/chirp/configs/hubert_base_rq.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/hubert_frozen_quantizer.py b/chirp/configs/hubert_frozen_quantizer.py index 9168aba5..fff3cfd0 100644 --- a/chirp/configs/hubert_frozen_quantizer.py +++ b/chirp/configs/hubert_frozen_quantizer.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/hubert_large_pq.py b/chirp/configs/hubert_large_pq.py index 8ab0f984..92b9d4aa 100644 --- a/chirp/configs/hubert_large_pq.py +++ b/chirp/configs/hubert_large_pq.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/hubert_presets.py b/chirp/configs/hubert_presets.py index 5c7d10b0..1619e58e 100644 --- a/chirp/configs/hubert_presets.py +++ b/chirp/configs/hubert_presets.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/mae.py b/chirp/configs/mae.py index 4660c89b..e1d7d601 100644 --- a/chirp/configs/mae.py +++ b/chirp/configs/mae.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/mae_finetune.py b/chirp/configs/mae_finetune.py index 8817ccfc..28fc4d5a 100644 --- a/chirp/configs/mae_finetune.py +++ b/chirp/configs/mae_finetune.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/multidataset_classifier.py b/chirp/configs/multidataset_classifier.py index 726e1c4c..c29e9783 100644 --- a/chirp/configs/multidataset_classifier.py +++ b/chirp/configs/multidataset_classifier.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/presets.py b/chirp/configs/presets.py index 9c928bb9..1af6cb18 100644 --- a/chirp/configs/presets.py +++ b/chirp/configs/presets.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/quantizer_pq.py b/chirp/configs/quantizer_pq.py index 2c8eb4aa..4b0172a0 100644 --- a/chirp/configs/quantizer_pq.py +++ b/chirp/configs/quantizer_pq.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/sample_eval_protocol_v1_config.py b/chirp/configs/sample_eval_protocol_v1_config.py index 0ab8db07..075ba7c7 100644 --- a/chirp/configs/sample_eval_protocol_v1_config.py +++ b/chirp/configs/sample_eval_protocol_v1_config.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/configs/separator.py b/chirp/configs/separator.py index 34c992c7..329471eb 100644 --- a/chirp/configs/separator.py +++ b/chirp/configs/separator.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/crawl/inaturalist.py b/chirp/crawl/inaturalist.py index d9b333b3..972d75b7 100644 --- a/chirp/crawl/inaturalist.py +++ b/chirp/crawl/inaturalist.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/crawl/xeno_canto.py b/chirp/crawl/xeno_canto.py index 2da55e4b..ab3eda47 100644 --- a/chirp/crawl/xeno_canto.py +++ b/chirp/crawl/xeno_canto.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/bird_taxonomy/__init__.py b/chirp/data/bird_taxonomy/__init__.py index 8935e648..148e7ec6 100644 --- a/chirp/data/bird_taxonomy/__init__.py +++ b/chirp/data/bird_taxonomy/__init__.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/bird_taxonomy/bird_taxonomy.py b/chirp/data/bird_taxonomy/bird_taxonomy.py index 40625ac1..a81f0724 100644 --- a/chirp/data/bird_taxonomy/bird_taxonomy.py +++ b/chirp/data/bird_taxonomy/bird_taxonomy.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/bird_taxonomy/premade_queries.py b/chirp/data/bird_taxonomy/premade_queries.py index a168d420..ffe28110 100644 --- a/chirp/data/bird_taxonomy/premade_queries.py +++ b/chirp/data/bird_taxonomy/premade_queries.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/filter_scrub_utils.py b/chirp/data/filter_scrub_utils.py index dfcfd5d8..007672a1 100644 --- a/chirp/data/filter_scrub_utils.py +++ b/chirp/data/filter_scrub_utils.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/sampling_utils.py b/chirp/data/sampling_utils.py index 17c19682..ac84219c 100644 --- a/chirp/data/sampling_utils.py +++ b/chirp/data/sampling_utils.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/soundevents/__init__.py b/chirp/data/soundevents/__init__.py index c756aeeb..123bb586 100644 --- a/chirp/data/soundevents/__init__.py +++ b/chirp/data/soundevents/__init__.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/soundevents/soundevents.py b/chirp/data/soundevents/soundevents.py index 69dbd968..023b02cd 100644 --- a/chirp/data/soundevents/soundevents.py +++ b/chirp/data/soundevents/soundevents.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/soundscapes/__init__.py b/chirp/data/soundscapes/__init__.py index e9442a25..bf691f56 100644 --- a/chirp/data/soundscapes/__init__.py +++ b/chirp/data/soundscapes/__init__.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/soundscapes/dataset_fns.py b/chirp/data/soundscapes/dataset_fns.py index cd0b31c2..3058ef24 100644 --- a/chirp/data/soundscapes/dataset_fns.py +++ b/chirp/data/soundscapes/dataset_fns.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/soundscapes/soundscapes.py b/chirp/data/soundscapes/soundscapes.py index 9b5620bf..a1a9b34f 100644 --- a/chirp/data/soundscapes/soundscapes.py +++ b/chirp/data/soundscapes/soundscapes.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/soundscapes/soundscapes_lib.py b/chirp/data/soundscapes/soundscapes_lib.py index e5544ee3..5693c947 100644 --- a/chirp/data/soundscapes/soundscapes_lib.py +++ b/chirp/data/soundscapes/soundscapes_lib.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/tfds_builder.py b/chirp/data/tfds_builder.py index 5921a5cb..acb4c1fb 100644 --- a/chirp/data/tfds_builder.py +++ b/chirp/data/tfds_builder.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/tfds_features.py b/chirp/data/tfds_features.py index a5e2dd28..dd79fc2c 100644 --- a/chirp/data/tfds_features.py +++ b/chirp/data/tfds_features.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/data/utils.py b/chirp/data/utils.py index fd90889f..c630e5ac 100644 --- a/chirp/data/utils.py +++ b/chirp/data/utils.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/eval/callbacks.py b/chirp/eval/callbacks.py index a2b46310..eaa112eb 100644 --- a/chirp/eval/callbacks.py +++ b/chirp/eval/callbacks.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/eval/eval.py b/chirp/eval/eval.py index c0cfd0cd..a165f140 100644 --- a/chirp/eval/eval.py +++ b/chirp/eval/eval.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/eval/eval_lib.py b/chirp/eval/eval_lib.py index d612a890..8ad40803 100644 --- a/chirp/eval/eval_lib.py +++ b/chirp/eval/eval_lib.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/export_utils.py b/chirp/export_utils.py index 5292a600..2a32aa3d 100644 --- a/chirp/export_utils.py +++ b/chirp/export_utils.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -97,7 +97,7 @@ def get_tf_zero_inputs(self): def export_converted_model( self, - workdir: str, + export_dir: str, train_step: int, class_lists: dict[str, namespace.ClassList] | None = None, export_tf_lite: bool = True, @@ -111,17 +111,19 @@ def export_converted_model( logging.info('Saving TF SavedModel...') tf.saved_model.save( - self, os.path.join(workdir, 'savedmodel'), signatures=concrete_fn + self, os.path.join(export_dir, 'savedmodel'), signatures=concrete_fn ) with tf.io.gfile.GFile( - os.path.join(workdir, 'savedmodel', 'ckpt.txt'), 'w' + os.path.join(export_dir, 'savedmodel', 'ckpt.txt'), 'w' ) as f: f.write(f'train_state.step: {train_step}\n') logging.info('Writing class lists...') if class_lists is not None: for key, class_list in class_lists.items(): - with tf.io.gfile.GFile(os.path.join(workdir, f'{key}.csv'), 'w') as f: + with tf.io.gfile.GFile( + os.path.join(export_dir, f'{key}.csv'), 'w' + ) as f: # NOTE: Although the namespace is written to the file, there is no # guarantee that the class list will still be compatible with the # namespace if the latter gets updated. @@ -155,11 +157,13 @@ def export_converted_model( converter.target_spec.supported_ops += [tf.lite.OpsSet.SELECT_TF_OPS] tflite_float_model = converter.convert() - if not tf.io.gfile.exists(workdir): - tf.io.gfile.makedirs(workdir) - with tf.io.gfile.GFile(os.path.join(workdir, 'model.tflite'), 'wb') as f: + if not tf.io.gfile.exists(export_dir): + tf.io.gfile.makedirs(export_dir) + with tf.io.gfile.GFile(os.path.join(export_dir, 'model.tflite'), 'wb') as f: f.write(tflite_float_model) - with tf.io.gfile.GFile(os.path.join(workdir, 'tflite_ckpt.txt'), 'w') as f: + with tf.io.gfile.GFile( + os.path.join(export_dir, 'tflite_ckpt.txt'), 'w' + ) as f: f.write(f'train_state.step: {train_step}\n') logging.info('Export complete.') diff --git a/chirp/inference/colab_utils.py b/chirp/inference/colab_utils.py index 7478d2b2..a6e43652 100644 --- a/chirp/inference/colab_utils.py +++ b/chirp/inference/colab_utils.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/inference/configs/birdnet_soundscapes.py b/chirp/inference/configs/birdnet_soundscapes.py index 0653c358..e3f8643c 100644 --- a/chirp/inference/configs/birdnet_soundscapes.py +++ b/chirp/inference/configs/birdnet_soundscapes.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/inference/configs/raw_soundscapes.py b/chirp/inference/configs/raw_soundscapes.py index cbaed256..b4d8537b 100644 --- a/chirp/inference/configs/raw_soundscapes.py +++ b/chirp/inference/configs/raw_soundscapes.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/inference/configs/separate_soundscapes.py b/chirp/inference/configs/separate_soundscapes.py index 933712a1..17543f4f 100644 --- a/chirp/inference/configs/separate_soundscapes.py +++ b/chirp/inference/configs/separate_soundscapes.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/inference/configs/separated_seabirds.py b/chirp/inference/configs/separated_seabirds.py index 1a2161b6..174e5734 100644 --- a/chirp/inference/configs/separated_seabirds.py +++ b/chirp/inference/configs/separated_seabirds.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/inference/embed.py b/chirp/inference/embed.py index fe091e2d..83c707a0 100644 --- a/chirp/inference/embed.py +++ b/chirp/inference/embed.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/inference/embed_lib.py b/chirp/inference/embed_lib.py index 91264250..20c7599e 100644 --- a/chirp/inference/embed_lib.py +++ b/chirp/inference/embed_lib.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/inference/interface.py b/chirp/inference/interface.py index 96baf034..577db86e 100644 --- a/chirp/inference/interface.py +++ b/chirp/inference/interface.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -42,12 +42,14 @@ class InferenceOutputs: logits array has shape [Frames, L.size] or [Frames, Channels, L.size]. separated_audio: Separated audio channels with shape [Channels, Samples]. batched: If True, each output has an additonal batch dimension. + frontend: Model frontend output, such as melspectrogram. """ embeddings: np.ndarray | None = None logits: LogitType | None = None separated_audio: np.ndarray | None = None batched: bool = False + frontend: np.ndarray | None = None def __post_init__(self): # In some scenarios, we may be passed TF EagerTensors. We dereference these diff --git a/chirp/inference/models.py b/chirp/inference/models.py index c9965779..d366d097 100644 --- a/chirp/inference/models.py +++ b/chirp/inference/models.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -255,7 +255,7 @@ class TaxonomyModelTF(interface.EmbeddingModel): window_size_s: float hop_size_s: float model: Any # TF SavedModel - class_list: namespace.ClassList + class_list: dict[str, namespace.ClassList] batchable: bool target_peak: float | None = 0.25 tfhub_version: int | None = None @@ -263,7 +263,21 @@ class TaxonomyModelTF(interface.EmbeddingModel): @classmethod def is_batchable(cls, model: Any) -> bool: sig = model.signatures['serving_default'] - return sig.inputs[0].shape[0] is None + if sig.inputs[0].shape[0] is not None: + raise NotImplementedError( + 'The non-batchable model is no longer supported. ' + 'Please update to a more recent model!' + ) + return True + + @classmethod + def load_class_lists(cls, csv_glob): + class_lists = {} + for csv_path in csv_glob: + with csv_path.open('r') as f: + key = csv_path.name.replace('.csv', '') + class_lists[key] = namespace.ClassList.from_csv(f) + return class_lists @classmethod def from_tfhub(cls, config: config_dict.ConfigDict) -> 'TaxonomyModelTF': @@ -283,11 +297,10 @@ def from_tfhub(cls, config: config_dict.ConfigDict) -> 'TaxonomyModelTF': # Get the labels CSV from TFHub. model_path = hub.resolve(model_url) - labels_path = epath.Path(model_path) / 'assets/label.csv' - with labels_path.open('r') as f: - class_list = namespace.ClassList.from_csv(f) + class_lists_glob = (epath.Path(model_path) / 'assets').glob('*.csv') + class_lists = cls.load_class_lists(class_lists_glob) return cls( - model=model, class_list=class_list, batchable=batchable, **config + model=model, class_list=class_lists, batchable=batchable, **config ) @classmethod @@ -303,61 +316,51 @@ def from_config(cls, config: config_dict.ConfigDict) -> 'TaxonomyModelTF': ).exists(): # This looks like a downloaded TFHub model. model_path = base_path - label_csv_path = epath.Path(config.model_path) / 'assets' / 'label.csv' + class_lists_glob = (epath.Path(model_path) / 'assets').glob('*.csv') else: # Probably a savedmodel distributed directly. model_path = base_path / 'savedmodel' - label_csv_path = base_path / 'label.csv' + class_lists_glob = epath.Path(base_path).glob('*.csv') model = tf.saved_model.load(model_path) - with label_csv_path.open('r') as f: - class_list = namespace.ClassList.from_csv(f) + class_lists = cls.load_class_lists(class_lists_glob) # Check whether the model support polymorphic batch shape. batchable = cls.is_batchable(model) return cls( - model=model, class_list=class_list, batchable=batchable, **config + model=model, class_list=class_lists, batchable=batchable, **config ) def embed(self, audio_array: np.ndarray) -> interface.InferenceOutputs: - if self.batchable: - return interface.embed_from_batch_embed_fn(self.batch_embed, audio_array) - - # Process one example at a time. - # This should be fine on CPU, but may be somewhat inefficient for large - # arrays on GPU or TPU. - framed_audio = self.frame_audio( - audio_array, self.window_size_s, self.hop_size_s - ) - framed_audio = self.normalize_audio(framed_audio, self.target_peak) - - all_logits, all_embeddings = self.model.infer_tf(framed_audio[:1]) - for window in framed_audio[1:]: - logits, embeddings = self.model.infer_tf(window[np.newaxis, :]) - all_logits = np.concatenate([all_logits, logits], axis=0) - all_embeddings = np.concatenate([all_embeddings, embeddings], axis=0) - - # Add channel dimension. - all_embeddings = all_embeddings[:, np.newaxis, :] - - return interface.InferenceOutputs( - all_embeddings, {'label': all_logits}, None - ) + return interface.embed_from_batch_embed_fn(self.batch_embed, audio_array) def batch_embed( self, audio_batch: np.ndarray[Any, Any] ) -> interface.InferenceOutputs: - if not self.batchable: - return interface.batch_embed_from_embed_fn(self.embed, audio_batch) - framed_audio = self.frame_audio( audio_batch, self.window_size_s, self.hop_size_s ) framed_audio = self.normalize_audio(framed_audio, self.target_peak) rebatched_audio = framed_audio.reshape([-1, framed_audio.shape[-1]]) - logits, embeddings = self.model.infer_tf(rebatched_audio) - logits = np.reshape(logits, framed_audio.shape[:2] + (logits.shape[-1],)) + outputs = self.model.infer_tf(rebatched_audio) + frontend_output = None + if hasattr(outputs, 'keys'): + # Dictionary-type outputs. Arrange appropriately. + embeddings = outputs.pop('embedding') + if 'frontend' in outputs: + frontend_output = outputs.pop('frontend') + # Assume remaining outputs are all logits. + logits = outputs + elif len(outputs) == 2: + # Assume logits, embeddings outputs. + label_logits, embeddings = outputs + logits = {'label': label_logits} + else: + raise ValueError('Unexpected outputs type.') + + for k, v in logits.items(): + logits[k] = np.reshape(v, framed_audio.shape[:2] + (v.shape[-1],)) # Unbatch and add channel dimension. embeddings = np.reshape( embeddings, @@ -367,9 +370,12 @@ def batch_embed( embeddings.shape[-1], ), ) - return interface.InferenceOutputs( - embeddings, {'label': logits}, None, batched=True + embeddings=embeddings, + logits=logits, + separated_audio=None, + batched=True, + frontend=frontend_output, ) diff --git a/chirp/inference/tf_examples.py b/chirp/inference/tf_examples.py index 14d67241..91069387 100644 --- a/chirp/inference/tf_examples.py +++ b/chirp/inference/tf_examples.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/audio_layers.py b/chirp/models/audio_layers.py index 3ab5d277..4e592dd9 100644 --- a/chirp/models/audio_layers.py +++ b/chirp/models/audio_layers.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/class_average.py b/chirp/models/class_average.py index 314daedb..0a2e9e68 100644 --- a/chirp/models/class_average.py +++ b/chirp/models/class_average.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/conformer.py b/chirp/models/conformer.py index 6b33fc81..9d02b609 100644 --- a/chirp/models/conformer.py +++ b/chirp/models/conformer.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/cwt.py b/chirp/models/cwt.py index 34fecc9f..ae730997 100644 --- a/chirp/models/cwt.py +++ b/chirp/models/cwt.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/efficientnet.py b/chirp/models/efficientnet.py index f3f96ab9..0cb5e39a 100644 --- a/chirp/models/efficientnet.py +++ b/chirp/models/efficientnet.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/frontend.py b/chirp/models/frontend.py index eaedeb56..7581f7c7 100644 --- a/chirp/models/frontend.py +++ b/chirp/models/frontend.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/handcrafted_features.py b/chirp/models/handcrafted_features.py index 18c0e813..b24d66a6 100644 --- a/chirp/models/handcrafted_features.py +++ b/chirp/models/handcrafted_features.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/hubert.py b/chirp/models/hubert.py index c40cb689..1e1dcfbf 100644 --- a/chirp/models/hubert.py +++ b/chirp/models/hubert.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/layers.py b/chirp/models/layers.py index 1719a5b3..bedfbd56 100644 --- a/chirp/models/layers.py +++ b/chirp/models/layers.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/mae.py b/chirp/models/mae.py index 9692c169..87d9a7da 100644 --- a/chirp/models/mae.py +++ b/chirp/models/mae.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/metrics.py b/chirp/models/metrics.py index d43271e1..eea3fd13 100644 --- a/chirp/models/metrics.py +++ b/chirp/models/metrics.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/output.py b/chirp/models/output.py index ce6d9099..afbcefa4 100644 --- a/chirp/models/output.py +++ b/chirp/models/output.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/pooling.py b/chirp/models/pooling.py index 90cb9a9d..59094b58 100644 --- a/chirp/models/pooling.py +++ b/chirp/models/pooling.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/quantizers.py b/chirp/models/quantizers.py index d9255c10..05010614 100644 --- a/chirp/models/quantizers.py +++ b/chirp/models/quantizers.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/separation_model.py b/chirp/models/separation_model.py index 52d7878b..d5d3893e 100644 --- a/chirp/models/separation_model.py +++ b/chirp/models/separation_model.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/soundstream_unet.py b/chirp/models/soundstream_unet.py index dda70f29..74adef94 100644 --- a/chirp/models/soundstream_unet.py +++ b/chirp/models/soundstream_unet.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/models/taxonomy_model.py b/chirp/models/taxonomy_model.py index d39d0181..49eab7bc 100644 --- a/chirp/models/taxonomy_model.py +++ b/chirp/models/taxonomy_model.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -97,6 +97,7 @@ def __call__( x = self.hubert_feature_extractor(inputs) # pylint: disable=not-callable else: x = inputs + frontend_outputs = x # Apply the encoder. while len(x.shape) < 4: @@ -110,6 +111,7 @@ def __call__( # Classify the encoder outputs and assemble outputs. model_outputs = {} model_outputs["embedding"] = x + model_outputs["frontend"] = frontend_outputs for k, n in self.num_classes.items(): model_outputs[k] = nn.Dense(n)(x) return model_outputs diff --git a/chirp/path_utils.py b/chirp/path_utils.py index 71444901..5b037ffa 100644 --- a/chirp/path_utils.py +++ b/chirp/path_utils.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/preprocessing/pipeline.py b/chirp/preprocessing/pipeline.py index 6fb749a7..13ea4b5c 100644 --- a/chirp/preprocessing/pipeline.py +++ b/chirp/preprocessing/pipeline.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/projects/bootstrap/bootstrap.py b/chirp/projects/bootstrap/bootstrap.py index aefd7e77..955111ea 100644 --- a/chirp/projects/bootstrap/bootstrap.py +++ b/chirp/projects/bootstrap/bootstrap.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/projects/bootstrap/display.py b/chirp/projects/bootstrap/display.py index e213c2a6..8a292d15 100644 --- a/chirp/projects/bootstrap/display.py +++ b/chirp/projects/bootstrap/display.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/projects/bootstrap/search.py b/chirp/projects/bootstrap/search.py index 5964db6f..49071589 100644 --- a/chirp/projects/bootstrap/search.py +++ b/chirp/projects/bootstrap/search.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/projects/bootstrap/tests/search_test.py b/chirp/projects/bootstrap/tests/search_test.py index 8659af41..81a6e0f3 100644 --- a/chirp/projects/bootstrap/tests/search_test.py +++ b/chirp/projects/bootstrap/tests/search_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/projects/main.py b/chirp/projects/main.py index 0436b091..ca1d63d9 100644 --- a/chirp/projects/main.py +++ b/chirp/projects/main.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/projects/multicluster/classify.py b/chirp/projects/multicluster/classify.py index 67bdc1c6..3dcfadf2 100644 --- a/chirp/projects/multicluster/classify.py +++ b/chirp/projects/multicluster/classify.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/projects/multicluster/data_lib.py b/chirp/projects/multicluster/data_lib.py index 9f411e2f..de1173e0 100644 --- a/chirp/projects/multicluster/data_lib.py +++ b/chirp/projects/multicluster/data_lib.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/signal.py b/chirp/signal.py index 237b7c2a..66facc6c 100644 --- a/chirp/signal.py +++ b/chirp/signal.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/taxonomy/annotations.py b/chirp/taxonomy/annotations.py index 5b484c33..39d98d26 100644 --- a/chirp/taxonomy/annotations.py +++ b/chirp/taxonomy/annotations.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/taxonomy/class_utils.py b/chirp/taxonomy/class_utils.py index cd4b65a8..7195d546 100644 --- a/chirp/taxonomy/class_utils.py +++ b/chirp/taxonomy/class_utils.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/taxonomy/ebird.py b/chirp/taxonomy/ebird.py index 810ff4ee..16f10571 100644 --- a/chirp/taxonomy/ebird.py +++ b/chirp/taxonomy/ebird.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/taxonomy/namespace.py b/chirp/taxonomy/namespace.py index 6f4b387a..53b05ce8 100644 --- a/chirp/taxonomy/namespace.py +++ b/chirp/taxonomy/namespace.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/taxonomy/namespace_db.py b/chirp/taxonomy/namespace_db.py index 3da72dfe..21b26547 100644 --- a/chirp/taxonomy/namespace_db.py +++ b/chirp/taxonomy/namespace_db.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/audio_utils_test.py b/chirp/tests/audio_utils_test.py index 4f95e7b7..cdeab135 100644 --- a/chirp/tests/audio_utils_test.py +++ b/chirp/tests/audio_utils_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/bird_taxonomy_test.py b/chirp/tests/bird_taxonomy_test.py index a72a88fc..522105d5 100644 --- a/chirp/tests/bird_taxonomy_test.py +++ b/chirp/tests/bird_taxonomy_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/conformer_test.py b/chirp/tests/conformer_test.py index 458e0d2a..27e7490b 100644 --- a/chirp/tests/conformer_test.py +++ b/chirp/tests/conformer_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/efficientnet_test.py b/chirp/tests/efficientnet_test.py index e46f4168..d5dc0db8 100644 --- a/chirp/tests/efficientnet_test.py +++ b/chirp/tests/efficientnet_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/eval_lib_test.py b/chirp/tests/eval_lib_test.py index 19b8b7f0..d5feacd8 100644 --- a/chirp/tests/eval_lib_test.py +++ b/chirp/tests/eval_lib_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/fake_dataset.py b/chirp/tests/fake_dataset.py index de1bf41c..948d45e3 100644 --- a/chirp/tests/fake_dataset.py +++ b/chirp/tests/fake_dataset.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/filter_scrub_test.py b/chirp/tests/filter_scrub_test.py index c7441acb..672f141b 100644 --- a/chirp/tests/filter_scrub_test.py +++ b/chirp/tests/filter_scrub_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/frontend_test.py b/chirp/tests/frontend_test.py index 29ff7b6f..f4c26f3a 100644 --- a/chirp/tests/frontend_test.py +++ b/chirp/tests/frontend_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/hubert_test.py b/chirp/tests/hubert_test.py index 0996c83f..75c108bd 100644 --- a/chirp/tests/hubert_test.py +++ b/chirp/tests/hubert_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/inference_test.py b/chirp/tests/inference_test.py index 7f5dc0f4..3036413b 100644 --- a/chirp/tests/inference_test.py +++ b/chirp/tests/inference_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -618,20 +618,26 @@ def test_beam_pipeline(self): print(metrics) @parameterized.product( + model_return_type=('tuple', 'dict'), batchable=(True, False), ) - def test_taxonomy_model_tf(self, batchable): + def test_taxonomy_model_tf(self, model_return_type, batchable): class FakeModelFn: - output_depths = (3, 256) + output_depths = {'label': 3, 'embedding': 256} def infer_tf(self, audio_array): - outputs = [ - np.zeros([audio_array.shape[0], depth], dtype=np.float32) - for depth in self.output_depths - ] + outputs = { + k: np.zeros([audio_array.shape[0], d], dtype=np.float32) + for k, d in self.output_depths.items() + } + if model_return_type == 'tuple': + # Published Perch models v1 through v4 returned a tuple, not a dict. + return outputs['label'], outputs['embedding'] return outputs - class_list = namespace.ClassList('fake', ['alpha', 'beta', 'delta']) + class_list = { + 'label': namespace.ClassList('fake', ['alpha', 'beta', 'delta']) + } wrapped_model = models.TaxonomyModelTF( sample_rate=32000, model_path='/dev/null', diff --git a/chirp/tests/layers_test.py b/chirp/tests/layers_test.py index f83b1e1b..417ff703 100644 --- a/chirp/tests/layers_test.py +++ b/chirp/tests/layers_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/mae_test.py b/chirp/tests/mae_test.py index 5780af2e..a15a4f7f 100644 --- a/chirp/tests/mae_test.py +++ b/chirp/tests/mae_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/metrics_test.py b/chirp/tests/metrics_test.py index 5e4dd21b..bd1b3fe0 100644 --- a/chirp/tests/metrics_test.py +++ b/chirp/tests/metrics_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/namespace_db_test.py b/chirp/tests/namespace_db_test.py index ee42c39b..4b5e6c86 100644 --- a/chirp/tests/namespace_db_test.py +++ b/chirp/tests/namespace_db_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/pipeline_test.py b/chirp/tests/pipeline_test.py index feb4d5d7..56bc8e48 100644 --- a/chirp/tests/pipeline_test.py +++ b/chirp/tests/pipeline_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/pooling_test.py b/chirp/tests/pooling_test.py index 439c2218..32247b60 100644 --- a/chirp/tests/pooling_test.py +++ b/chirp/tests/pooling_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/quantizers_test.py b/chirp/tests/quantizers_test.py index dbbfd185..c99593bd 100644 --- a/chirp/tests/quantizers_test.py +++ b/chirp/tests/quantizers_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/sep_train_test.py b/chirp/tests/sep_train_test.py index cf80232d..ab7504b7 100644 --- a/chirp/tests/sep_train_test.py +++ b/chirp/tests/sep_train_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/signal_test.py b/chirp/tests/signal_test.py index a94188e9..c205392f 100644 --- a/chirp/tests/signal_test.py +++ b/chirp/tests/signal_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/soundevents_test.py b/chirp/tests/soundevents_test.py index 6d695144..fc440e81 100644 --- a/chirp/tests/soundevents_test.py +++ b/chirp/tests/soundevents_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/soundscapes_lib_test.py b/chirp/tests/soundscapes_lib_test.py index c4efeb46..9c15bcf7 100644 --- a/chirp/tests/soundscapes_lib_test.py +++ b/chirp/tests/soundscapes_lib_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/soundscapes_test.py b/chirp/tests/soundscapes_test.py index 16db3347..761f9eb7 100644 --- a/chirp/tests/soundscapes_test.py +++ b/chirp/tests/soundscapes_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/soundstream_unet_test.py b/chirp/tests/soundstream_unet_test.py index e2f9c5ca..ac892fa0 100644 --- a/chirp/tests/soundstream_unet_test.py +++ b/chirp/tests/soundstream_unet_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/taxonomy_model_test.py b/chirp/tests/taxonomy_model_test.py index 42a77c26..643d9d99 100644 --- a/chirp/tests/taxonomy_model_test.py +++ b/chirp/tests/taxonomy_model_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/tfds_builder_wav_directory_test.py b/chirp/tests/tfds_builder_wav_directory_test.py index ba769a45..bedae7bc 100644 --- a/chirp/tests/tfds_builder_wav_directory_test.py +++ b/chirp/tests/tfds_builder_wav_directory_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/tests/train_test.py b/chirp/tests/train_test.py index 50036edf..594be591 100644 --- a/chirp/tests/train_test.py +++ b/chirp/tests/train_test.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/train/classifier.py b/chirp/train/classifier.py index 8da4a47a..7a28c192 100644 --- a/chirp/train/classifier.py +++ b/chirp/train/classifier.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ """Training loop.""" import functools -from typing import Callable, Sequence +from typing import Any, Callable, Sequence from absl import logging from chirp import export_utils @@ -42,14 +42,13 @@ EVAL_LOOP_SLEEP_S = 30 -def get_keyed_map_fn(key): +def get_keyed_av_prec_fn(key): def _map(**kwargs): return metrics.average_precision( scores=kwargs[f"{key}_logits"], labels=kwargs[key], label_mask=kwargs.get(f"{key}_mask", None), ) - return _map @@ -64,7 +63,7 @@ def get_train_metrics( len(md.class_list.classes) ).from_output(f"{md.key}_loss") metrics_[f"{md.key}_map"] = clu_metrics.Average.from_fun( - get_keyed_map_fn(md.key) + get_keyed_av_prec_fn(md.key) ) return metrics_ @@ -150,9 +149,9 @@ def initialize_model( def train( - model_bundle, - train_state, - train_dataset, + model_bundle: Any, + train_state: Any, + train_dataset: Any, num_train_steps: int, logdir: str, log_every_steps: int, @@ -398,12 +397,18 @@ def export_tf_model( eval_sleep_s: int = EVAL_LOOP_SLEEP_S, polymorphic_batch: bool = True, output_keys: Sequence[str] | None = None, + tf_lite_dtype: str = "float16", + tf_lite_select_ops: bool = True, + export_dir: str | None = None, ): """Export SavedModel and TFLite.""" # Get model_ouput keys from output_head_metadatas and add the 'embedding' key if output_keys is None: output_keys = set(md.key for md in model_bundle.output_head_metadatas) output_keys.add("embedding") # Add 'embedding' if not already present + output_keys.add("frontend") # Add 'frontend' if not already present + if export_dir is None: + export_dir = workdir for train_state in train_utils.checkpoint_iterator( train_state, model_bundle.ckpt, workdir, num_train_steps, eval_sleep_s @@ -415,9 +420,7 @@ def infer_fn(audio_batch, variables): variables, audio_batch, train=False ) # Will use all keys in configs.init_config.output_head_metadatas - return tuple( - model_outputs[key] for key in output_keys if key in model_outputs - ) + return {k: v for k, v in model_outputs.items() if k in output_keys} if polymorphic_batch: shape = (None,) + input_shape @@ -430,7 +433,11 @@ def infer_fn(audio_batch, variables): md.key: md.class_list for md in model_bundle.output_head_metadatas } converted_model.export_converted_model( - workdir, train_state.step, class_lists + export_dir, + train_state.step, + class_lists, + tf_lite_dtype=tf_lite_dtype, + tf_lite_select_ops=tf_lite_select_ops, ) diff --git a/chirp/train/hubert.py b/chirp/train/hubert.py index 5ddbb429..70045af2 100644 --- a/chirp/train/hubert.py +++ b/chirp/train/hubert.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/train/mae.py b/chirp/train/mae.py index 1136bdd9..45e7a950 100644 --- a/chirp/train/mae.py +++ b/chirp/train/mae.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/train/separator.py b/chirp/train/separator.py index 3dc1afc6..0dcd6d91 100644 --- a/chirp/train/separator.py +++ b/chirp/train/separator.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/chirp/train/train_utils.py b/chirp/train/train_utils.py index f61ec64c..33dc3ccc 100644 --- a/chirp/train/train_utils.py +++ b/chirp/train/train_utils.py @@ -1,5 +1,5 @@ # coding=utf-8 -# Copyright 2023 The Perch Authors. +# Copyright 2024 The Perch Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.