Closed MaHaWo closed 7 months ago
possibly relevant: #80, #67
Hi @MaHaWo, thanks for digging into this, and for posting your working code. I'm away from the lab until Wednesday, so I can't test your workaround in depth (other than on my field laptop).
Are you seeing the same detection results from your modified code as you see with BirdNET's command line script python3 analyze.py --classifier checkpoints/custom/Custom_Classifier.tflite
?
If I recall correctly, the custom models I'm using are trained using BirdNET 2.3, so perhaps I've missed a recent change from Stefan and his team.
If you don't mind sharing your model (or any other failing model), here's an upload link: https://www.dropbox.com/request/lTUadB0XVNNJ9HMmny89
I only use provided models internally, and delete them after closing this issue. If you'd rather not upload, that's ok too.
Hello @joeweiss, thanks for the quick reply!
uploaded the retrained model that I'm using. It's the result of following the example they provide in the BirdNET-Analyzer readme, with out autotuning.
test code to assert equality using the CustomAnalyzer
from above:
custom_model_path = '/path/to/where/stuff/is/BirdNET-Analyzer/checkpoints/custom/Custom_Classifier.tflite' custom_labels_path = '/path/to/where/stuff/is/BirdNET-Analyzer/checkpoints/custom/Custom_Classifier_Labels.txt'
recording = Recording( CustomAnalyzer(classifier_labels_path=custom_labels_path, classifier_model_path=custom_model_path, ), current / Path("soundscape.wav"), min_conf=0.25, )
recording.analyze()
pd.DataFrame(recording.detections).sort_values(by = "confidence", ascending = True).to_csv("/path/to/where/stuff/is/birdnet_experiments/example_results/custom_results_birdnetlib_experimental.csv")
command = 'python3 /path/to/where/stuff/is/BirdNET-Analyzer/analyze.py --classifier '+custom_model_path+' --i /path/to/where/stuff/is/BirdNET-Analyzer/example --o /path/to/where/stuff/is/BirdNET-Analyzer/example_custom_results --min_conf 0.25 --threads 12 --rtype csv'
subprocess.run(command, shell = True)
birdnet_analyzer = pd.read_csv('/path/to/where/stuff/is/BirdNET-Analyzer/example_custom_results/soundscape.BirdNET.results.csv').sort_values(by='Confidence', ascending = True)
birdnet_lib = pd.read_csv('/path/to/where/stuff/is/birdnet_experiments/example_results/custom_results_birdnetlib_experimental.csv').sort_values(by='confidence', ascending = True) birdnet_lib['confidence'] = birdnet_lib['confidence'].round(4)
print("analyzer:", birdnet_analyzer[['Start (s)', 'End (s)', 'Confidence', 'Common name']])
print("birdnet-lib: ",birdnet_lib[['start_time', 'end_time', 'confidence', 'common_name']])
print("equal? ", np.all(birdnet_analyzer[['Start (s)', 'End (s)', 'Confidence', 'Common name']].to_numpy() == birdnet_lib[['start_time', 'end_time', 'confidence', 'common_name']].to_numpy()))
I omitt the output here for brevity, but for me the equality check prints 'True', so it seems the results are equal.
I'm trying to figure out how to replace models in birdnetlib since we need that for a researc project, and as a first step tried to use a the result of the BirdNet retraining example via bridnetlib:
which however fails at the preparation step(?) of the model with the following error message, apparently indicating that the input data has the wrong shape:
The version without the custom model works fine. What I did then was to dig around in the code a bit, and then copied the respective code form the
model.py
file from BirdNET-Analyzer into a child class ofAnalyzer
:With this, things appear to work fine. I'm new to TensorFlow/machine learning, so I have a hard time interpreting the underlying logic that results in this problem.
Is this a symptom of support for the retraining/custom-model stuff being in its early stages?