Python Usage
HeartKit python package allows for more fine-grained control and customization. You can use the package to train, evaluate, and deploy models for both built-in taks and custom tasks. In addition, custom datasets and model architectures can be created and registered with corresponding factories.
Overview
The main components of HeartKit include the following:
Tasks
A Task inherits from the HKTask class and provides implementations for each of the main modes: download, train, evaluate, export, and demo. Each mode is provided with a set of parameters defined by HKTaskParams. Additional task-specific parameters can be extended to the HKTaskParams
class. These tasks are then registered and accessed via the TaskFactory
using a unique task name as the key and the custom Task class as the value.
Datasets
A dataset inherits from the HKDataset class and provides implementations for downloading, preparing, and loading the dataset. Each dataset is provided with a set of custom parameters for initialization. Since each task will require specific transformations of the data, the dataset class provides only a general interface for loading the data. Each task must then provide a set of corresponding HKDataloader classes to transform the dataset into a format that can be used by the task. The datasets are registered and accessed via the DatasetFactory using a unique dataset name as the key and the Dataset class as the value. Each Task can then create its own DataloaderFactory
that will provide a corresponding dataloader for each supported dataset. The Task's DataloaderFactory
should use the same dataset names as the DatasetFactory to ensure that the correct dataloader is used for each dataset.
Models
Lastly, HeartKit leverages neuralspot-edge's customizable model architectures. To enable creating custom network topologies from configuration files, HeartKit provides a ModelFactory
that allows you to create models by specifying the model key and the model parameters. Each item in the factory is a callable that takes a keras.Input
, model parameters, and number of classes as arguments and returns a keras.Model
.
import keras
import heartkit as hk
inputs = keras.Input((256, 1), dtype="float32")
num_classes = 4
model_params = dict(...)
model = hk.ModelFactory.get('tcn')(
inputs=inputs,
params=model_params,
num_classes=num_classes
)
Usage
Running a built-in task w/ existing datasets
-
Create a task configuration file defining the model, datasets, class labels, mode parameters, and so on. Have a look at the HKTaskParams for more details on the available parameters.
-
Leverage
TaskFactory
to get the desired built-in task. -
Run the task's main modes:
download
,train
,evaluate
,export
, and/ordemo
.
- Example configuration:
Running a custom task w/ custom datasets
To create a custom task, check out the Bring-Your-Own-Task Guide.
To create a custom dataset, check out the Bring-Your-Own-Dataset Guide.