Installation

The MLTK supports three modes of installation:

Note

Python3 9,10,11, or 12 is required

Standard Python Package

This describes how to install the MLTK Python package into your Python3 environment.

Note

1 ) Optionally create and activate a Python virtual environment:

This step is highly recommended as the MLTK installs other dependencies like Tensorflow into the Python environment.

python  -m venv mltk_pyvenv
.\mltk_pyvenv\Scripts\activate.bat
python3 -m venv mltk_pyvenv
source ./mltk_pyvenv/bin/activate

2 ) Install the MLTK Python package via pip:

This installs the pre-built Python package. This is the easiest and fastest approach to installing the MLTK.
However, the package may not be up-to-date with the Github repository.

pip  install silabs-mltk[full] --upgrade
pip3 install silabs-mltk[full] --upgrade

Alternatively,

This builds and installs the Python package from the Github repository.
This will take longer to install but will use the most up-to-date source code.

pip  install "silabs-mltk[full] @ git+https://github.com/siliconlabs/mltk.git"
pip3 install "silabs-mltk[full] @ git+https://github.com/siliconlabs/mltk.git"

NOTE: The silabs-mltk[full] @ part of the command is optional. This will install additional dependencies used by some the the MLTK commands. Omitting this from the command will speedup installation but may cause some of the commands like classify_audio, view, tensorboard to require additional install step.

After the command completes, the MLTK should be available to the current Python environment.
You can verify by issuing the command:

mltk --help

See the Command-Line Guide for more details on how to use the command-line.

You can also import the MLTK via Python script, e.g.:

from mltk.core import profile_model

profile_model('~/my_model.tflite')

See the API Examples for more details on how to use the MLTK Python API.

Update Python Package

If the MLTK Python package has already been installed, you may update to the latest MLTK by running the command:

pip  install silabs-mltk[full] --upgrade
pip3 install silabs-mltk[full] --upgrade

Alternatively, you can update to a specific version with:

pip  install silabs-mltk[full]==0.20.0
pip3 install silabs-mltk[full]==0.20.0

and replace 0.20.0 with the desired version.

Google Colab

Google offers it own free Cloud servers for model training, Google Colaboratory (a.k.a. Colab).
This is very useful as you can leverage Google’s cloud servers and GPUs for training your model. The following describes how to install the MLTK into a Colab notebook.

1 ) Create a Google Account (if necessary)
Go to the Google Signup page.
NOTE: Click the Use my current email address instead button to use your existing email instead of creating a gmail email address.

2 ) Refer to the Colab Basic Features Overview to get a basic idea of how notebooks work
3 ) Create a new Colab notebook
4 ) Create a Python code cell and copy & paste the following into the cell

!pip install --upgrade silabs-mltk

5 ) Execute the cell
Once the cell executes, the MLTK will be installed. You may import and use the MLTK package as normal from this point on inside the notebook

Local Development

The MLTK can also be installed for local development. In this mode, the Python C++ wrappers are built from source.
Additionally, a new Python virtual environment is created specifically for the MLTK.

Note

Before installing, you must have Python3.9,10,11, or 12 installed on your computer

1 ) Clone the MLTK GIT repository

git clone https://github.com/siliconlabs/mltk

2 ) Run the install script at the root of the repository

cd mltk
python  .\install_mltk.py
cd mltk
python3 ./install_mltk.py

The install script will:

  1. Create a python virtual environment at <mltk root>/.venv

  2. Install the MLTK Python package for local development into Python virtual environment:

    pip install -e .
    

See also