Skip to content

Commit

Permalink
Merge pull request #101 from isZumpo/improve_docs
Browse files Browse the repository at this point in the history
Improve docs for building and installation steps
  • Loading branch information
tphakala authored Apr 6, 2024
2 parents 75880c3 + 8ec33a9 commit d3ecea0
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 128 deletions.
132 changes: 4 additions & 128 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,138 +33,14 @@ skills and a keen interest in contributing to a nature-focused project, I'd love

<img src="doc/BirdNET-Go-dashboard.webp" />

## Executable Distributions
## Installation

Ready to run binaries can be found from releases section https://github.com/tphakala/BirdNET-Go/releases/
Archives also contains libtensorflowlite_c library.
For detailed installation instructions, see the [installation documentation](doc/installation.md).

### Docker

```
docker run -ti \
-p 8080:8080 \
--env ALSA_CARD=<index/name>
--device /dev/snd \
-v /path/to/config:/config \
-v /path/to/data:/data \
ghcr.io/tphakala/birdnet-go:latest
```

| Parameter | Function |
| :----: | --- |
| `-p 8080` | BirdNET-GO webserver port. |
| `--env ALSA_CARD=<index/name>` | ALSA capture device to use. Find index/name of desired device by executing `arecord -l` on the host. [More info.](#deciding-alsa-card)|
| `--device /dev/snd` | Mounts in audio devices to the container. |
| `-v /config` | Config directory in the container. |
| `-v /data` | Data such as database and recordings. |


#### Deciding ALSA_CARD value

Within the BirdNET-Go container, knowledge of the designated microphone is absent. Consequently, it is necessary to specify the appropriate ALSA_CARD environment variable. Determining the correct value for this variable involves the following steps on the host computer:
1. Open a terminal and execute the command `arecord -l` to list all available capture devices.

```
> arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCH [Generic Analog], device 0: Analog [Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [Generic Analog], device 2: Alt Analog [Alt Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Microphone [USB Microphone], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
```
2. Identify the desired capture device. In the example above, cards 0 and 1 are available.
3. Specify the ALSA_CARD value when running the BirdNET-Go container. For instance, if the USB Microphone device is chosen, set `ALSA_CARD` to either `ALSA_CARD=1` or `ALSA_CARD=Microphone`.

## Compiling for Linux

### Install TensorFlow Lite C library and setup headers for compile process

Download precompiled TensorFlow Lite C library for Linux from https://github.com/tphakala/tflite_c/releases/tag/v2.14.0

Copy libtensorflowlite_c.so to /usr/local/lib and run ```ldconfig```

```bash
sudo cp libtensorflowlite_c.so /usr/local/lib
sudo ldconfig
```

Clone tensorflow repository, this is required for header files to be present while compiling with CGO

```bash
mkdir ~/src
cd ~/src
git clone https://github.com/tensorflow/tensorflow.git
```

Checkout TensorFlow v2.14.0 release

```bash
cd tensorflow
git checkout tags/v2.14.0
```

### Building BirdNET-Go

Clone BirdNET-Go repository

```bash
git clone https://github.com/tphakala/BirdNET-Go.git
```

Build BirdNET-Go by make, compiled binary will be placed in go-birdnet/bin directory

```bash
cd BirdNET-Go
make
```

## Compiling for Windows

Windows build is cross compiled on Linux, for this you need MinGW-w64 on your build system

```bash
sudo apt install mingw-w64-tools gcc-mingw-w64-x86-64 gcc-mingw-w64-i686
```

Download precompiled TensorFlow Lite C library for Windows from https://github.com/tphakala/tflite_c/releases/tag/v2.14.0

Copy **libtensorflowlite_c.dll** to /usr/x86_64-w64-mingw32/lib/

```bash
sudo cp libtensorflowlite_c.dll /usr/x86_64-w64-mingw32/lib/
```

Clone tensorflow repository, this is required for header files to be present while compiling with CGO

```bash
mkdir ~/src
cd ~/src
git clone https://github.com/tensorflow/tensorflow.git
```

### Cross compiling BirdNET-Go

Clone BirdNET-Go repository

```bash
git clone https://github.com/tphakala/BirdNET-Go.git
```

Build BirdNET-Go by running make windows

```bash
cd BirdNET-Go
make windows
```

Windows executable is in **bin/birdnet.exe**, copy this and **libtensorflowlite_c.so** to your Windows system, library file must be in PATH for birdnet.exe to run properly.
## Building
For instructions on how to build the project, see the [building documentation](doc/building.md).

Yes it is correct that you need **libtensorflowlite_c.dll** in /usr/x86_64-w64-mingw32/lib/ for compile process, and on Windows you need **libtensorflowlite_c.so** for runtime. This sounds backwards but this is how it works.

## Usage

Expand Down
101 changes: 101 additions & 0 deletions doc/building.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Building

Building can be a bit tricky because of the many dependencies. It is recommended to follow the [building locally guide](#building-locally) for building the project. However, there is also a provided [devcontainer](#devcontainer) approach that allows for easy development.

## Devcontainer

For convenient development in VSCode, a [devcontainer](https://code.visualstudio.com/docs/remote/containers) can be used. Simply open the project in VSCode and hit `F1`, type `Remote-Containers: Reopen in Container` and wait for the container to build.

The provided [`.devcontainer/devcontainer.json`](.devcontainer/devcontainer.json) contains all required dependencies and also mounts the source code into the container, so one can immediately start coding. When the container starts, a development server is started that can be reached at [localhost:8080](http://localhost:8080). The server automatically reloads the application on any code changes.

Note: Ensure Docker and VSCode with [Remote Development](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) extension are installed.



## Building locally

### Install prerequisites

#### Install TensorFlow Lite C library

Download precompiled TensorFlow Lite C library for Linux from https://github.com/tphakala/tflite_c/releases/tag/v2.14.0

Copy libtensorflowlite_c.so to /usr/local/lib and run ```ldconfig```

```bash
sudo cp libtensorflowlite_c.so /usr/local/lib
sudo ldconfig
```

Clone tensorflow repository, this is required for header files to be present while compiling with CGO

```bash
mkdir ~/src
cd ~/src
git clone https://github.com/tensorflow/tensorflow.git
```

Checkout TensorFlow v2.14.0 release

```bash
cd tensorflow
git checkout tags/v2.14.0
```

### Building BirdNET-Go

Clone BirdNET-Go repository

```bash
git clone https://github.com/tphakala/BirdNET-Go.git
```

Build BirdNET-Go by make, compiled binary will be placed in go-birdnet/bin directory

```bash
cd BirdNET-Go
make
```

#### Compiling for Windows

Windows build is cross compiled on Linux, for this you need MinGW-w64 on your build system

```bash
sudo apt install mingw-w64-tools gcc-mingw-w64-x86-64 gcc-mingw-w64-i686
```

Download precompiled TensorFlow Lite C library for Windows from https://github.com/tphakala/tflite_c/releases/tag/v2.14.0

Copy **libtensorflowlite_c.dll** to /usr/x86_64-w64-mingw32/lib/

```bash
sudo cp libtensorflowlite_c.dll /usr/x86_64-w64-mingw32/lib/
```

Clone tensorflow repository, this is required for header files to be present while compiling with CGO

```bash
mkdir ~/src
cd ~/src
git clone https://github.com/tensorflow/tensorflow.git
```

### Cross #compiling BirdNET-Go

Clone BirdNET-Go repository

```bash
git clone https://github.com/tphakala/BirdNET-Go.git
```

Build BirdNET-Go by running make windows

```bash
cd BirdNET-Go
make windows
```

Windows executable is in **bin/birdnet.exe**, copy this and **libtensorflowlite_c.so** to your Windows system, library file must be in PATH for birdnet.exe to run properly.

Yes it is correct that you need **libtensorflowlite_c.dll** in /usr/x86_64-w64-mingw32/lib/ for compile process, and on Windows you need **libtensorflowlite_c.so** for runtime. This sounds backwards but this is how it works.
91 changes: 91 additions & 0 deletions doc/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Installation

BirdNET-Go can be installed either using Docker or binary provided releases. Docker is the
preferred method, as it provides a self-contained and easily reproducible
environment. However, binary releases are convenient option for users who prefer not to install Docker.


## Docker

**Note**: Docker is currently only supported when running inside a Linux-based
host system.


### Installing Docker

To install Docker, follow the instructions in the [official installation guide](https://docs.docker.com/engine/install) for your operating system.

### Running BirdNET-GO with Docker - Simple setup


The command below will start a container with the latest version BirdNET-Go:

> docker run -ti -p 8080:8080 --device /dev/snd ghcr.io/tphakala/birdnet-go:latest
Once executed, the service can be reached at [localhost:8080](http://localhost:8080).


### Running BirdNET-GO with Docker - Normal setup
While the [simple](##Running-BirdNET-GO-with-Docker-Simple) example above works, it is highly likely that customizing the runtime settings more as well as enabling persistent storage is desirable. The docker run snippet below offers many more options:

```
docker run -ti \
-p 8080:8080 \
--env ALSA_CARD=<index/name>
--env TZ="<TZ identifier>"
--device /dev/snd \
-v /path/to/config:/config \
-v /path/to/data:/data \
ghcr.io/tphakala/birdnet-go:latest
```

Summary of parameters:

| Parameter | Function |
| :----: | --- |
| `-p 8080` | BirdNET-GO webserver port. |
| `--env ALSA_CARD=<index/name>` | ALSA capture device to use. Find index/name of desired device by executing `arecord -l` on the host. [More info.](#deciding-alsa_card-value)|
| `--env TZ="TZ identifier"` | Timezone to use. See [wikipedia article](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List) to find TZ identifier.|
| `--device /dev/snd` | Mounts in audio devices to the container. |
| `-v /config` | Config directory in the container. |
| `-v /data` | Data such as database and recordings. |

#### Example setup

To start BirdNET-GO, simply fill in the values of the parameters. Below is an example of how it might look:

```
docker run -ti \
-p 8080:8080 \
--env ALSA_CARD=0
--env TZ="Europe/Stockholm"
--device /dev/snd \
-v $HOME/BirdNET-Go-Volumes/config:/config \
-v $HOME/BirdNET-Go-Volumes/data:/data \
ghcr.io/tphakala/birdnet-go:latest
```

#### Deciding ALSA_CARD value

Within the BirdNET-Go container, knowledge of the designated microphone is absent. Consequently, it is necessary to specify the appropriate ALSA_CARD environment variable. Determining the correct value for this variable involves the following steps on the host computer:
1. Open a terminal and execute the command `arecord -l` to list all available capture devices.

```
> arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCH [Generic Analog], device 0: Analog [Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [Generic Analog], device 2: Alt Analog [Alt Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Microphone [USB Microphone], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
```
2. Identify the desired capture device. In the example above, cards 0 and 1 are available.
3. Specify the ALSA_CARD value when running the BirdNET-Go container. For instance, if the USB Microphone device is chosen, set `ALSA_CARD` to either `ALSA_CARD=1` or `ALSA_CARD=Microphone`.

## Binary releases

Ready to run binaries can be found in [releases](https://github.com/tphakala/BirdNET-Go/releases/) section. Unfortunately, not everything is contained inside the binary itself, meaning that certain dependencies must be installed on the host system first. One of them being TensorFlow Lite C library, see this [guide](building.md#install-tensorflow-lite-c-library) for more information.

0 comments on commit d3ecea0

Please sign in to comment.