Skip to content

Quickstart

Install HeartKit

We provide several installation methods including pip, poetry, and Docker. Install HeartKit via pip/poetry for the latest stable release or by cloning the GitHub repo for the most up-to-date. Additionally, a VSCode Dev Container is available and defined in ./.devcontainer to run in an isolated Docker environment.

Install

Clone the repository if you are interested in contributing to the development or wish to experiment with the latest source code. After cloning, navigate into the directory and install the package. In this mode, Poetry is recommended.

# Clone the repository
git clone https://github.com/AmbiqAI/heartkit.git

# Navigate to the cloned directory
cd heartkit

# Install the package in editable mode for development
poetry install

When using editable mode via Poetry, be sure to activate the python environment: poetry shell.
On Windows using Powershell, use .venv\Scripts\activate.ps1.

Install the HeartKit package using pip or Poetry. Visit the Python Package Index (PyPI) for more details on the package: https://pypi.org/project/heartkit/

# Install with poetry
poetry add heartkit

Or, if you prefer to use Pip, you can install the package with the following command:

# Install with pip
pip install heartkit
Alternatively, you can install the latest development version directly from the GitHub repository. Make sure to have the Git command-line tool installed on your system. The @main command installs the main branch and may be modified to another branch, i.e. @release.

poetry add git+https://github.com/AmbiqAI/heartkit.git@main

Requirements

Check the project's pyproject.toml file for a list of up-to-date Python dependencies. Note that the installation methods above install all required dependencies. The following are also required to compile and flash the binary to evaluate the demos running on Ambiq's evaluation boards (EVBs):

Once installed, HeartKit can be used as either a CLI-based tool or as a Python package to perform advanced experimentation.


Use HeartKit with CLI

The HeartKit command line interface (CLI) allows for simple single-line commands without the need for a Python environment. The CLI requires no customization or Python code. You can simply run all tasks from the terminal with the heartkit command. Check out the CLI Guide to learn more about available options.

Example

Heartkit commands use the following syntax:

heartkit --mode [MODE] --task [TASK] --config [CONFIG]

Or using short flags:

heartkit -m [MODE] -t [TASK] -c [CONFIG]

Where:

  • MODE is one of download, train, evaluate, export, or demo
  • TASK is one of segmentation, rhythm, beat, or denoise
  • CONFIG is configuration as JSON content or file path

Download datasets specified in the configuration file.

heartkit -m download -c ./configs/download-datasets.json

Train a rhythm model using the supplied configuration file.

heartkit -m train -t rhythm -c ./configs/rhythm-class-2.json

Evaluate the trained rhythm model using the supplied configuration file.

heartkit -m evaluate -t rhythm  -c ./configs/rhythm-class-2.json

Run demo on trained rhythm model using the supplied configuration file.

heartkit -m demo -t rhythm -c ./configs/rhythm-class-2.json

Use HeartKit with Python

The HeartKit Python package allows for more fine-grained control and customization. You can use the package to train, evaluate, and deploy models for a variety of tasks. The package is designed to be simple and easy to use.

For example, you can create a custom model, train it, evaluate its performance on a validation set, and even export a quantized TensorFlow Lite model for deployment. Check out the Python Guide to learn more about using HeartKit as a Python package.

Example

import heartkit as hk

ds_params = hk.HKDownloadParams(
    ds_path="./datasets",
    datasets=["ludb", "synthetic"],
    progress=True
)


with open("configuration.json", "r", encoding="utf-8") as file:
    config = json.load(file)

train_params = hk.HKTrainParams.model_validate(config)
test_params = hk.HKTestParams.model_validate(config)
export_params = hk.HKExportParams.model_validate(config)

# Download datasets
hk.datasets.download_datasets(ds_params)

task = hk.TaskFactory.get("rhythm")

# Train rhythm model
task.train(train_params)

# Evaluate rhythm model
task.evaluate(test_params)

# Export rhythm model
task.export(export_params)