Installation¶
The MLTK supports three modes of installation:
Standard Python Package - Use the MLTK like any other package in your local Python3 environment
Google Colab - Run the MLTK in the Google Colab cloud servers. This allows for running the MLTK without installing it locally
Local Development - Locally build the MLTK C++ Python wrappers and examples from source
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
Before installing, you must have Python 3.9, 3.10, 3.11, 3.12 installed on your computer
Installing the MLTK will also install Google Tensorflow into your Python environment, if your computer has an NVidia GPU, then ensure the proper drivers are installed
If you’re using Windows, be sure to install the Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019 which is required by Tensorflow
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:
Create a python virtual environment at
<mltk root>/.venv
Install the MLTK Python package for local development into Python virtual environment:
pip install -e .
See also
C++ Development - Describes how to build and run MLTK C++ applications