# From sleep signals to Edge AI

## A starting point for your sleep-monitoring application

Building a sleep model takes more than choosing a network. You need recordings and labels, consistent signal processing, a training setup and a way to evaluate the results. sleepKIT brings these pieces together in a configurable development workflow for engineers and researchers working on wearable and edge applications.

Start with the included dataset integrations, feature sets, model configurations and examples. Run experiments from the command line or compose a custom workflow with the Python API. You can replace individual components as your application develops, then use the export tools to prepare models for integration on Ambiq devices.

## Included tasks

Start with a built-in task, or extend the same workflow with your own training, evaluation and export routines.

Sleep detection
Identify sleep and wake periods from wrist-worn motion signals.
Explore detection →

Sleep staging
Explore feature sets and models for classifying sleep stages.
Explore staging →

Sleep apnea
Explore the task and available resources for apnea event detection.
Explore apnea →

Bring your own task
Register a custom task and reuse sleepKIT’s configuration, datasets and development workflow.
Create a task →

Code and Ambiq-authored documentation use BSD-3-Clause, except separately licensed material. Model weights and datasets have [their own terms](https://ambiqai.github.io/sleepkit/model-licensing-policy/).

## Installation

Use **uv** for a Python project, **uvx** to run the CLI in an isolated environment, or **pipx** to keep the CLI installed. Choose **Git clone** when developing sleepKIT itself.

Create a project with Python 3.12, then add sleepKIT. In an existing uv project, start with `uv add sleepkit`.

```bash title="Terminal"
uv init --python 3.12 my-sleep-project
cd my-sleep-project
uv add sleepkit
uv run sleepkit --help
```

Run the CLI without adding sleepKIT to a project. The first invocation downloads sleepKIT and its dependencies into an isolated environment.

```bash title="Terminal"
uvx --python 3.12 sleepkit --help
```

Use a project installation for Python imports and notebooks.

Install the CLI in its own environment. This command uses an installed Python 3.12 interpreter.

```bash title="Terminal"
pipx install --python python3.12 sleepkit
sleepkit --help
```

If the command is not on your PATH, run `pipx ensurepath` and reopen your terminal. Use a project installation for Python imports and notebooks.

Install into an activated virtual environment.

```bash title="Terminal"
python -m pip install sleepkit
sleepkit --help
```

Work with the repository source and its development dependencies.

```bash title="Terminal"
git clone https://github.com/AmbiqAI/sleepkit.git
cd sleepkit
uv sync --python 3.12
uv run sleepkit --help
```

Need the package manager first? See the [uv installation guide](https://docs.astral.sh/uv/getting-started/installation/) or [pipx installation guide](https://pipx.pypa.io/stable/installation/). The [Quickstart](https://ambiqai.github.io/sleepkit/quickstart/) covers configuration and your first workflow.

---

## Usage

__sleepKIT__ can be used as either a CLI-based tool or as a Python package to perform advanced development. In both forms, sleepKIT exposes a number of modes and tasks outlined below. In addition, by leveraging highly-customizable configurations, sleepKIT can be used to create custom workflows for a given application with minimal coding. Refer to the [Quickstart](https://ambiqai.github.io/sleepkit/quickstart/) to quickly get up and running in minutes.

---

## Modes

The __ADK__ provides a number of [modes](https://ambiqai.github.io/sleepkit/modes/) that can be invoked for a given task. These modes can be accessed via the CLI or directly within the Python package. Each mode is accompanied by a set of [task parameters](https://ambiqai.github.io/sleepkit/modes/configuration/) that can be customized to fit the user's needs.

- **[Download](https://ambiqai.github.io/sleepkit/modes/download/)**: Download specified datasets
- **[Feature](https://ambiqai.github.io/sleepkit/features/)**: Generate features from datasets
- **[Train](https://ambiqai.github.io/sleepkit/modes/train/)**: Train a model for specified task and feature set
- **[Evaluate](https://ambiqai.github.io/sleepkit/modes/evaluate/)**: Evaluate a model for specified task and feature set
- **[Export](https://ambiqai.github.io/sleepkit/modes/export/)**: Export a trained model to TensorFlow Lite and TFLM
- **[Demo](https://ambiqai.github.io/sleepkit/modes/demo/)**: Run task-level demo on PC or remotely on Ambiq EVB

---

## Datasets

__sleepKIT__ includes several open-source datasets via the __dataset factory__. Each dataset has a corresponding Python class to aid in downloading and extracting the data. The datasets are used to generate feature sets that are then used to train and evaluate the models. Check out the [Datasets Guide](https://ambiqai.github.io/sleepkit/datasets/) to learn more about the available datasets along with their corresponding licenses and limitations.

* **[MESA](https://ambiqai.github.io/sleepkit/datasets/mesa/)**: A longitudinal investigation of factors associated with the development of subclinical cardiovascular disease and the progression of subclinical to clinical cardiovascular disease in 6,814 black, white, Hispanic, and Chinese
* **[CMIDSS](https://ambiqai.github.io/sleepkit/datasets/cmidss/)**: The Child Mind Institute - Detect Sleep States (CMIDSS) dataset comprises 300 subjects with over 500 multi-day recordings of wrist-worn accelerometer data annotated with two event types: onset, the beginning of sleep, and wakeup, the end of sleep.
* **[YSYW](https://ambiqai.github.io/sleepkit/datasets/ysyw/)**: A total of 1,983 PSG recordings were provided by the Massachusetts General Hospital’s (MGH) Sleep Lab in the Sleep Division together with the Computational Clinical Neurophysiology Laboratory, and the Clinical Data Ani- mation Center.
* **[STAGES](https://ambiqai.github.io/sleepkit/datasets/stages/)**: The Stanford Technology Analytics and Genomics in Sleep (STAGES) study is a prospective cross-sectional, multi-site study involving 20 data collection sites from six centers including Stanford University, Bogan Sleep Consulting, Geisinger Health, Mayo Clinic, MedSleep, and St. Luke's Hospital.

---

## Models

The __ADK__ provides a variety of model architectures geared towards efficient, real-time edge applications. These models are provided by Ambiq's [helia-edge](https://ambiqai.github.io/helia-edge/) and expose a set of parameters that can be used to fully customize the network for a given application. In addition, sleepKIT includes a model factory, [ModelFactory](https://ambiqai.github.io/sleepkit/models/#model-factory), to register current models as well as allow new custom architectures to be added. Check out the [Models Guide](https://ambiqai.github.io/sleepkit/models/) to learn more about the available network architectures and model factory.

---

## Features

The __ADK__ provides a __feature store__ that allows you to easily create and extract features from the given datasets. The feature store includes a number of feature sets used to train the included model zoo. Each feature set exposes a number of high-level parameters that can be used to customize the feature extraction process for a given application. These parameters can be set as part of the configuration accessible via the CLI and Python package. Check out the [Features Guide](https://ambiqai.github.io/sleepkit/features/) to learn more about the available feature set generators.

---

## Model Zoo

A number of pre-trained models are available for each task. These models are trained on a variety of datasets and are optimized for deployment on Ambiq's ultra-low power SoCs. In addition to providing links to download the models, __sleepKIT__ provides the corresponding configuration files and performance metrics. The configuration files allow you to easily recreate the models or use them as a starting point for custom solutions. Furthermore, the performance metrics provide insights into the model's accuracy, precision, recall, and F1 score. For a number of the models, we provide experimental and ablation studies to showcase the impact of various design choices. Check out the [Model Zoo](https://ambiqai.github.io/sleepkit/zoo/) to learn more about the available models and their corresponding performance metrics.

---

## [Guides](https://ambiqai.github.io/sleepkit/guides/)

Checkout the [Guides](https://ambiqai.github.io/sleepkit/guides/) to see detailed examples and tutorials on how to use sleepKIT for a variety of tasks. The guides provide step-by-step instructions on how to train, evaluate, and deploy models for a given task. In addition, the guides provide insights into the design choices and performance metrics for the models. The guides are designed to help you get up and running quickly and to provide a deeper understanding of the capabilities provided by sleepKIT.

---
