-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tensorflow js models? #169
Comments
We don't have a workflow to convert models right now, but you can try for yourself. There is a guide here. |
Thamks for getting back to me @Josef-Haupt , I did try the conversion, this is the command I used:
On execution, I get the expected whinging about gradients, but converstion fails with:
I wondered if you had implemented custom operations in the model? That would be one reason I would get this error. |
It's been a while and I just redoscovered this issue: We do have a TFJS version of BirdNET ready to use, including an example on how to run it. You can find the model and the code here: https://github.com/kahst/BirdNET-Analyzer/tree/main/checkpoints/V2.4/BirdNET_GLOBAL_6K_V2.4_Model_TFJS I would love to develop something like birdnet.js or BirdNET as npm package, yet, we do lack the skills to do so. If you're interested in attempting that, let us know :) |
@kahst Sorry - I didn't see your reply until this morning. Thanks for sharing, that's awesome! I've had a little play around, it's looking really great 😄 One suggestion: if you make the following small changes to call method of the MelSpecLayerSimple class in your example, it will support batch predictions, which gives a decent performance boost (up to c. 40% faster inference):
I can create a PR if you like. But I ran out of time today! Meanwhile, I have an Electron App which now has your BirdNet model as a backend option, taking advantage of the metadata model's 'species location' filtering. Happy days! |
Awesome! Yes, please create a PR. Also, let us know more about your Electron app, we're always looking for cool projects to feature in our showcase. Thanks! |
@kahst @Josef-Haupt - hey guys, sorry to bother you again. I have a question about your TFJS conversion, motivated by the finding that a comparison shows the results from the TFJS model are similar, but far from identical to those given by BirdNET-Analyser-GUI.exe. A link to the TFJS model output from the example soundscape.wav file from this repo is here: For the avoidance of doubt, I have used these settings in the TFJS analysis:
And in the GUI
In both cases batchsize and threads settings make zero difference, as you would expect. I know there could be myriad reasons for this - there are many possibilities at my end. However, before I spend too much time comparing the outputs of the individual libraries involved, I wanted to see if you'd used any aggressive quantization in the TFJS conversion? Like UINT8 in some activation layers for example? Using Netron, I noticed some of the layers have "QUANT" and others 'NO_QUANT' appended to their names, so I thought it would be a good thing to check. It's worth saying, I'm not sure this is even a bug, it may be expected behaviour - both models make good predictions, but if am to release an App which claims to offer the BirdNET 2.4 model for predictions, I would like a handle on why the results are this different. Thanks again for your input, I really appreciate it! The app I've been developing was initially inspired by BirdNET-Electron. You may find some of the design elements familiar Stefan, although it's come a long way since. You can read about, even download it, here: https://chirpity.mattkirkland.co.uk (When I release a version with the new BirdNET model, the app will auto-update) |
Hmmm, there shouldn't be a significant difference between models. We do test our models after conversion to make sure the scores align with the original Keras version - even after quantization. The TFJS model is not quantized and should yield scores that are very similar to the TFLite 32bit model. There might be something off with the GUI though. We'll investigate and keep you posted. |
Hi @kahst , thanks again for getting back to me. I just ran the same analysis of the soundscape.wav file through the CLI and the results are identical to the GUI results posted above. I think next steps would be for me to build/run a minimal implementation for the TFJS model such that it can accept the soundscape.wav, chunk it up into 3 second clips and output predictions. If the results are still different I'll share that code back with you, otherwise I'll know it's an issue at my end. |
@Mattk70 I bet difference comes from differences in sigmoid sensitivity implementation you mentioned |
@kahst @tphakala OK. I have done a validation of the TFJS model using the flask app and sample.wav Analyzer.py output for ths file: TFJS via the flask app in this repo* produces the following: Whilst these are different they are minimally so, which is what I'd have expected. Start (s) | End (s) | Scientific name | Common name | Confidence So, it's an issue with my code. The Flask app has a couple of issues I needed to correct before I could get it to work.
I'll do a PR with these changes. And then start looking into the dang problem with my code. At least, if there's an upside, I'd never have spotted this bug if I hadn't integrated BirdNET ;-) |
Nailed it! My native model uses 24000Hz sample rate, and there was one place in the code I'd missed, which was switching the audioContext in the audio pipeline to this with BirdNET, before then upsampling the audioBuffer back to 48k. Now that's fixed, the predictions in the soundscape.wav of the TFJS and python models are almost identical. |
Hi Stefan, et al.
You've done great work here, it's really inspiring! I wanted to ask if there wsa any prospect of releasing the latest models in a tensorflowjs format, so they could be run in a web browser? I've seen this repo: https://github.com/kahst/BirdNET-Electron but it was last updated about 4 yewars ago.
The text was updated successfully, but these errors were encountered: