Docker support
I'm making this issue and working on it myself, just in case anyone else here is interested in following the progress :)
What synchronicity!! I just posted this discussion for needs, and at the top is . . .
I want to help however I can!!! I know that this thing is not put together the way it would were I to be anything other than a hobbyist when it comes to developing a web application, so I will likely be of most value just by fixing things I've done so that they're not bad and to make things as easy for you as I can -- please just let me know how to help and I will!
At this point the simplest thing to do is emulate an entire Raspberry Pi image and then throw that into a container registry, but it's quite bloaty (so far my build is taking more than 20 mins 😿)
If you're interested and you want to rewrite the entire web-end in Laravel, and then just querying the existing 'server.py' service internally, you'd get a lot of support from me ;)
So far the initial issues are as you described in #104, the pre-built TFLite binaries are only for aarch64. This part of the stack I'm not too familiar with.
How feasible is it to get similar binaries for x86_64 architecture? If so we can dump a lot of the 'build' work to GitHub Actions.
I've managed to get a Docker image build running, https://github.com/olipayne/BirdNET-Pi-Docker/runs/6085934891 will leave that for tonight and get back to it tomorrow 🥳
How feasible is it to get similar binaries for x86_64 architecture? If so we can dump a lot of the 'build' work to GitHub Action
Pretty easy, but I think maybe the easiest thing to do would be to try adjusting the requirements.txt file's line for the tflite aarch64 binary to just say tflite_runtime, which ought to grab those for the platform you're building on -- I will try to track down a pre-build binary for x86 and will let you know if I can come up with it. If you get to setting up a build action before I get the chance, let me know how it goes! :+1:
Hey this is just a comment but imo, the cleanest way to "dockerize" this would be to refactor the whole thing into docker-compose and have each service (db, ui, server, analysis, recording, etc) running in a different container.
There are lots of things happening during BirdNET-Pi installation (new files in /usr/local/bin, scripts to add custom shebangs, scripts writing templates, etc). These hacks complicate the maintenance and updates. All of this would be much simpler when using docker images.
This is not an easy task if you've never worked with containers.
I am not saying dockerizing is the way to go. But if you want to do it properly, I would suggest to refactor at the same time instead of installing into docker image based on raspberry-pi image.
By the way, BalenaOS might be worth looking into to deploy docker containers on a raspberry-pi.
@olipayne I found an x86_64 whl online https://github.com/maxogden/BirdNET-Pi/blob/main/tflite_runtime-2.6.0-cp39-cp39-linux_x86_64.whl but I am not sure if it works... I tried building your Dockerfile locally and I think because balenalib/raspberrypi4-64-debian:bullseye is not amd64 it won't let me build on an amd64 machine. How were you planning on running raspbian on amd64?
@lpasselin @olipayne former balena employee here happy to help with the containerization push! I actually tried to deploy this today before realizing it was more complicated than I originally thought. It can certainly be done without much balena lockin (generic docker-compose and service definitions), but the open fleets stuff makes it stupid simple to deploy as well.
Again I'm no longer affiliated with balena, just happy to help to make this easier to get up and running!
Since this entire project is built on the premise that it's running on a Raspberry Pi of some sort, it might be a bigger job than initially expected. I'm looking into seeing what can be chopped up so that in theory, this entire project could run in separate places (e.g., recording on a Pi somewhere, sending the files to a more powerful machine for analysis and webpage hosting)
Quick update, I'm separating out the Tensorflow stuff first, it seems like the easiest route for now is to build a dedicated image per CPU arch, since there are a lot of hardware level optimisations you miss out on if you build an all-in-one docker image.
I've got the server.py service running on a local machine here, decided to open it to the world for testing:
https://bird-analyze.oli.xyz/analyze
Feel free to post to it as much as you like, it'll just slow down but it wont crash anything else.
Naturally, this comes with a privacy warning, you'd be sending raw audio to a third party (me). Once I've got a bit more running, I'll stitch together a docker-compose file so you can host this yourself.
Getting this running on a container platform + RTSP support would mean that people with home NAS devices etc could run the solution with existing security cameras without having to try and source an RPi for sale. Container support brings a whole new set of deployment options to the table and I'm pretty stoked that it's being worked out!
I'm going to give this an attempt as it will give me the opportunity to learn about docker. Not sure how it's going to work yet but I think splitting the analyse "server" into one docker and everything else on another for now will be a great start.
@supajason is on the right track, using https://github.com/kahst/BirdNET-Analyzer/blob/main/Dockerfile (slightly modified to run server.py though) and then forking everything else over to a normal 'web app' seems like the right way forward.
Quick update, I'm separating out the Tensorflow stuff first, it seems like the easiest route for now is to build a dedicated image per CPU arch, since there are a lot of hardware level optimisations you miss out on if you build an all-in-one docker image.
I've got the
server.pyservice running on a local machine here, decided to open it to the world for testing: https://bird-analyze.oli.xyz/analyzeFeel free to post to it as much as you like, it'll just slow down but it wont crash anything else.
Naturally, this comes with a privacy warning, you'd be sending raw audio to a third party (me). Once I've got a bit more running, I'll stitch together a docker-compose file so you can host this yourself.
If this could be modularized further, I could see an end result that you could plug in many different models, with applications outside of bird identification. I've always wanted to be able to identify sounds & trilaterate them in 3D space using an array of microphones. Similar to gunshot detection that cities use.
Hi @mgottholsen! I just wanted to show you this since you might be interested in their findings.
My best, Patrick
@mcguirepr89 This is really awesome stuff! IT conceptually overlaps with some other stuff I've been looking at Rhasspy voice assistant satellite devices that run on similarly specc'ed hardware. The multilateration is a killer feature as well. I noticed you helped them with their setup, were there large differences in their implementation that would make sense here?
@mgottholsen My contributions to that DTU project were not around any of the cool engineering, unfortunately -- I just made myself available to them, helped get the installation working, answered questions, etc., and was able to make little adjustments here and there to make things easier for their needs.
The system can be noded without too much hassle so long as you know a little bit about networking. Also, since the system can run on the $15 Raspberry Pi 0W2, a triangle of nodes could be ~$45 + $cost of (3)three USB mics, and (3)three USB-A to micro-USB adapters.
Do you have any recommendations on some 101, introductory type sources for getting started in being able to gather the info needed to start tinkering with this?
Unfortunately I'm not the best person to get you started on something like this, I have limited experience in implementation for multilateration, although I did work on a pilot to dispatch drones based off the X/Y results from trilateration/multilateration.
There is a good Github reference in that whitepaper you linked that I think can show how the technique can work - https://github.com/jurasofish/multilateration
+1 for breaking out the different services into different containers. The way I would refactor this (I am not a PHP person so probably not much help in actually doing it):
- Get everything running in a single container (sounds like already got that kind of working), this would be really helpful for testing if you do not have a bunch of RPIs laying around.
- Start identifying the core "pieces" of the project that you can break out. My initial guess would be...
- Audio capture
- TensorFlow / audio processing
- Web application (PHP)
- HTTP server (basically your single "ingress" point that will sit in front of the PHP app and eventually the optional services)
- Database maintenance/misc background cleanup/tasks
- Everything else
- Start splitting out the different pieces from above into their own containers with docker compose. Leave out everything under "everything else" to start with. The prototype/MVP should not have a Web terminal, file manager, FTP server, phpSysInfo, etc. You can slow add those back in later. You can use shared volumes to share files like the SQLite database and audio files between the containers.
- Update the install scripts to basically install docker -> pull compose setup -> configure it -> add systemd unit to start on boot -> start
- Add back in optional components from 3.
- Make PR and merge in to mainline.
- Add new things that make sense as you scale it out (Postgres/MySQL support?, audio from multiple RTSP sources, multi-node support within the Web app, running multiple instances Web apps, etc.)
I would love to run this as I have a lot of Docker/server space and a lot of security cameras, but no RPIs.
If you need a testing subject and want some help testing things out, let me know. I think this would be a really neat project to throw up for the fun.
Audio capture is a bit of sticking point. I don't know enough about docker for USB/device recording. For not I might focus just on using streams then try and add it later. Next up will be understanding how the front end works and see about running it on its own container.