Bonsai.Sleap 0.0.1002

dotnet add package Bonsai.Sleap --version 0.0.1002
                    
NuGet\Install-Package Bonsai.Sleap -Version 0.0.1002
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bonsai.Sleap" Version="0.0.1002" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bonsai.Sleap" Version="0.0.1002" />
                    
Directory.Packages.props
<PackageReference Include="Bonsai.Sleap" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bonsai.Sleap --version 0.0.1002
                    
#r "nuget: Bonsai.Sleap, 0.0.1002"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Bonsai.Sleap&version=0.0.1002
                    
Install Bonsai.Sleap as a Cake Addin
#tool nuget:?package=Bonsai.Sleap&version=0.0.1002
                    
Install Bonsai.Sleap as a Cake Tool

Bonsai - SLEAP

logo

Bonsai.SLEAP is a Bonsai interface for SLEAP allowing multi-animal, real-time, pose and identity estimation using pretrained network models stored in a Protocol buffer (.pb) format.

Bonsai.SLEAP loads these .pb files using TensorFlowSharp, a set of .NET bindings for TensorFlow allowing native inference using either the CPU or GPU. By using the .pb file and the corresponding configuration file (training_config.json), the PredictFullModelPose operator from Bonsai.SLEAP will push the live image data through the inference network and output a set of identified poses from which you can extract an object id and specific object part position. Bonsai can then leverage this data to drive online effectors or simply save it to an output file.

The Bonsai.SLEAP package came about following a fruitful discussion with the SLEAP team during the Quantitative Approaches to Behaviour.

How to install

Bonsai.SLEAP can be downloaded through the Bonsai package manager. In order to get visualizer support, you should download both the Bonsai.SLEAP and Bonsai.SLEAP.Design packages. However, in order to use it for either CPU or GPU inference, you need to pair it with a compiled native TensorFlow binary. You can find precompiled binaries for Windows 64-bit at https://www.tensorflow.org/install/lang_c.

To use GPU TensorFlow (highly recommended for live inference), you also need to install the CUDA Toolkit and the cuDNN libraries. The current SLEAP package was developed and tested with CUDA v11.3 and cuDNN 8.2. Additionally, make sure you have a CUDA compatible GPU with the latest NVIDIA drivers.

After downloading the native TensorFlow binary and cuDNN, you can follow these steps to get the required native files into the Extensions folder of your local Bonsai install:

  1. The easiest way to find your Bonsai install folder is to right-click on the Bonsai shortcut > Properties. The path to the folder will be shown in the "Start in" textbox;
  2. Copy tensorflow.dll file from either the CPU or GPU tensorflow release to the Extensions folder;
  3. If you are using TensorFlow GPU, make sure to add the cuda/bin folder of your cuDNN download to the PATH environment variable, or copy all DLL files to the Extensions folder.

How to use

Bonsai.SLEAP currently implements the following SLEAP networks through the correspondent Bonsai operator:

  • centroid:
    • Input : full frame with potentially multiple objects
    • Output : collection of multiple detected centroids in the input image
    • Operator : PredictCentroid
  • top-down-model:
    • Input : full frame with potentially multiple objects
    • Output : collection of detected poses (centroid + body parts) from multiple objects in the image
    • Operator : PredictPoses
  • top-down-id-model:
    • Input : full frame with potentially multiple objects
    • Output : collection of detected poses (centroid + body parts) plus identities from multiple objects in the image
    • Operator : PredictPoseIdentities
  • single_instance:
    • Input : croped instance with a single object in the input image
    • Output : returns a single pose (body parts)
    • Operator : PredictSinglePose

The general Bonsai workflow will thus be:

Bonsai_Pipeline

Additional information can be extracted by selecting the relevant structure fields.

Bonsai_Pipeline_expanded

In order to use the Predict operators, you will need to provide the ModelFileName to the exported .pb file folder containing your pretrained SLEAP model, along with the corresponding PoseConfigFileName to the training_config.json file.

If everything works out, you should see some indications in the Bonsai command line window about whether the GPU was successfully detected and enabled. The first frame will cold start the inference graph which may take a bit of time, but after that your poses should start streaming through!

SLEAP installation

For all questions regarding installation of SLEAP, please check the official docs.

Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Bonsai.Sleap:

Package Downloads
Bonsai.Sleap.Design

Bonsai Library containing reactive visualizations for markerless multi-pose estimation using SLEAP.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.1002 0 5/17/2025