From 4322449137c6e4997dc9cb8d4017051ea5c651ba Mon Sep 17 00:00:00 2001 From: Josef Haupt Date: Mon, 29 Apr 2024 13:52:31 +0200 Subject: [PATCH 1/2] some small fixes --- .gitignore | 4 ++++ analyze.py | 2 +- model.py | 3 ++- requirements.txt | 8 ++++++++ segments.py | 2 +- train.py | 12 +++++++----- utils.py | 3 ++- 7 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 4acc5c39..edeffba6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# Local testing +playground* +foo* + # Apple :/ .DS_Store diff --git a/analyze.py b/analyze.py index e189e0a6..3a85b1af 100644 --- a/analyze.py +++ b/analyze.py @@ -4,10 +4,10 @@ import argparse import datetime import json +import multiprocessing import operator import os import sys -import multiprocessing from multiprocessing import Pool, freeze_support import numpy as np diff --git a/model.py b/model.py index f4667199..2a5df422 100644 --- a/model.py +++ b/model.py @@ -333,10 +333,11 @@ def saveLinearClassifier(classifier, model_path: str, labels: list[str], mode="r def save_raven_model(classifier, model_path, labels: list[str], mode="replace"): - import tensorflow as tf import csv import json + import tensorflow as tf + global PBMODEL tf.get_logger().setLevel("ERROR") diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..bcbf3c98 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +librosa +resampy +tensorflow==2.15.0 +gradio +webview +tqdm +bottle +requests \ No newline at end of file diff --git a/segments.py b/segments.py index cfb8db73..0044ec48 100644 --- a/segments.py +++ b/segments.py @@ -3,8 +3,8 @@ Can be used to save the segments of the audio files for each detection. """ import argparse -import os import multiprocessing +import os from multiprocessing import Pool import numpy as np diff --git a/train.py b/train.py index daae51bf..47ebc5ed 100644 --- a/train.py +++ b/train.py @@ -3,19 +3,20 @@ Can be used to train a custom classifier with new training data. """ import argparse -import os -import tqdm import multiprocessing +import os from functools import partial from multiprocessing.pool import Pool import numpy as np +import tqdm import audio import config as cfg import model import utils + def _loadAudioFile(f, label_vector, config): """Load an audio file and extract features. Args: @@ -40,7 +41,7 @@ def _loadAudioFile(f, label_vector, config): except Exception as e: # Print Error print(f"\t Error when loading file {f}", flush=True) - pass + return np.array([]), np.array([]) # Crop training samples if cfg.SAMPLE_CROP_MODE == "center": @@ -208,10 +209,11 @@ def trainModel(on_epoch_end=None, on_trial_result=None, on_data_load_end=None): print(f"...Done. Loaded {x_train.shape[0]} training samples and {y_train.shape[1]} labels.", flush=True) if cfg.AUTOTUNE: - import keras_tuner - import keras import gc + import keras + import keras_tuner + # Call callback to initialize progress bar if on_trial_result: on_trial_result(0) diff --git a/utils.py b/utils.py index c9e8fd42..63a0e502 100644 --- a/utils.py +++ b/utils.py @@ -2,9 +2,10 @@ """ import os import traceback -import numpy as np from pathlib import Path +import numpy as np + import config as cfg From deeaaec6e9d28bccc9e7043f5e0703357749484d Mon Sep 17 00:00:00 2001 From: Josef Haupt Date: Mon, 29 Apr 2024 15:48:14 +0200 Subject: [PATCH 2/2] updated requirements --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index bcbf3c98..9076fc03 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -librosa +librosa==0.9.2 resampy tensorflow==2.15.0 gradio