2.0.0
How to write an MLC generation script


ST Edge AI Core

How to write an MLC generation script


for MLC target, based on ST Edge AI Core Technology 2.0.0




Overview

With the generate command, ST Edge AI Core offers the possibility of either extracting features computed by emulating MLC computations using --type arff, or generating the final sensor configuration (in .ucf and .h format) using --type ucf. To do so, the tool also requires --json <file> with an MLC generation script in .json format containing the desired settings specific to each MLC-based device.

Note: The same MLC generation script can be employed both for extracting the features and generating the sensor configuration, some fields will be required for both operations, while others will be only relevant for one operation and ignored for the other.

MLC generation script format

Fields for ARFF and UCF generation

  • name: MLC-capable device name

    { "name": "LSM6DSV16X" }
  • mlc_odr: MLC output rate (Hz) (see Device settings)

    { "mlc_odr": "30 Hz" }
  • input_type: MLC input type (see Device settings)

    { "input_type": "accelerometer_only" }
  • <input_name>**_fs**: Sensor full-scale range* (see Device settings)

    {"accelerometer_fs": "8 g" }
  • <input_name>**_odr**: Sensor output data rate (Hz)* (see Device settings)

    { "accelerometer_odr": "30 Hz" }
  • <ext_name>**_sensitivity**: External sensor sensitivity written as a 4-digits hex value (<ext_unit>/LSB)* (see Device settings)

    { "ext_sensitivity": "3C00" }

    Note: this value represents a half-precision floating-point number: SEEEEEFFFFFFFFFF (S: 1 sign bit; E: 5 exponent bits; F: 10 fraction bits)

  • decision_tree_count: Number of decision trees (#trees) (see Device settings)

    { "decision_tree_count": 1 }
  • window_length: Buffer length for features computation (#samples), choose a value between 1 and 255

    { "window_length": 60 }
  • filters (optional): List of filter objects, each specifying the following fields:

    • filter_id: Unique filter name to be used as suffix to feature input field
    • filter_type: Filter type name
    • input: Filter input name in the form <input_name>_<axis_name> (see Device settings)
    {
        "filters": [
            { "filter_id": "filter_1", "filter_type": "BP", "input": "Acc_V2", "a2": "-1.66", "a3": "0.81", "gain": "0.09" },
            "..."
        ]
    }

    Note: Depending on the filter_type value, filter objects may require extra fields (see Device settings)

  • features: List of feature objects, each specifying the following fields:

    • feature_name: Feature name (see Device settings)
    • input: Feature input name in the form <input_name><axis_name> to use raw input data or <input_name><axis_name>_<filter_id> to use filtered input data (see Device settings)
    • signed: Boolean flag to specify feature signedness
    {
        "features": [
            { "feature_name": "MEAN",         "input": "Acc_V2"          },
            { "feature_name": "MEAN",         "input": "Acc_V2_filter_1" },
            { "feature_name": "VARIANCE",     "input": "Acc_V2"          },
            { "feature_name": "VARIANCE",     "input": "Acc_V2_filter_1" },
            { "feature_name": "ENERGY",       "input": "Acc_V2"          },
            { "feature_name": "ENERGY",       "input": "Acc_V2_filter_1" },
            { "feature_name": "PEAK_TO_PEAK", "input": "Acc_V2"          },
            { "feature_name": "PEAK_TO_PEAK", "input": "Acc_V2_filter_1" },
            "..."
        ]
    }

    Note: Depending on the feature_name value, feature objects may require extra fields (see Device settings)

Fields for ARFF generation only

  • datalogs: List of data log objects, each specifying the following fields:

    • filename: Input path of data log file
    • label: Class name (multiple logs may share the same value)
    {
        "datalogs": [
            { "filename": "path/to/workspace/data/stationary.csv", "label": "stationary" },
            { "filename": "path/to/workspace/data/walking.csv",    "label": "walking"    },
            { "filename": "path/to/workspace/data/cycling.csv",    "label": "cycling"    },
            { "filename": "path/to/workspace/data/running.csv",    "label": "running"    },
            "..."
        ]
    }
  • arff: Output feature file path

    { "arff": "/path/to/workspace/features.arff" }

Fields for UCF generation only

  • dectree_features (optional): An ordered list of custom feature names used by the decision trees corresponding to the hardware ones configured in the features field. Note that if not specified, it is assumed that decision trees will use feature names defined in the .arff file generated before.

    {
        "dectree_features": [
            "F1_MEAN_ACC_V2",
            "F2_MEAN_ACC_V2_FILTER_1",
            "F3_VARIANCE_ACC_V2",
            "F4_VARIANCE_ACC_V2_FILTER_1",
            "F5_ENERGY_ACC_V2",
            "F6_ENERGY_ACC_V2_FILTER_1",
            "F7_PEAK_TO_PEAK_ACC_V2",
            "F8_PEAK_TO_PEAK_ACC_V2_FILTER_1",
            "..."
        ]
    }
  • dectrees: A list of decision tree objects, each specifying the following fields:

    • filename: Input file path of decision tree in Weka format
    • results: Mappings of class names to integer values
    • metaclassifier: List of metaclassifier end counter thresholds
    {
        "dectrees": [
            {
                "filename": "/path/to/workspace/dectree.txt",
                "results": [
                    { "label": "stationary", "value": 1  },
                    { "label": "walking",    "value": 4  },
                    { "label": "cycling",    "value": 8  },
                    { "label": "running",    "value": 12 },
                ],
                "metaclassifier": [ 2, 2, 2, 2 ]
            },
            "..."
        ]
    }
  • ucf: Output configuration file path

    { "ucf": "/path/to/workspace/mlc_conf.ucf" }

Device settings

Depending on the specific MLC-based device, specifications and settings may vary quite a lot. In order to use the generate command and create a valid configuration for a given device, the user must be aware of the available settings to properly write the MLC generation script.

For more information on device-specific settings, please follow the link corresponding to the target MLC-based device below:

Complete example

{
    "datalogs": [
        { "filename": "/path/to/workspace/data/stationary.csv", "label": "stationary" },
        { "filename": "/path/to/workspace/data/walking.csv",    "label": "walking"    },
        { "filename": "/path/to/workspace/data/cycling.csv",    "label": "cycling"    },
        { "filename": "/path/to/workspace/data/running.csv",    "label": "running"    },
        "..."
    ],
    "name": "LSM6DSV16X",
    "mlc_odr": "30 Hz",
    "input_type": "accelerometer_only",
    "accelerometer_fs": "8 g",
    "accelerometer_odr": "30 Hz",
    "decision_tree_count": 1,
    "window_length": 60,
    "filters": [
        { "filter_id": "filter_1", "filter_type": "BP", "input": "Acc_V2", "a2": "-1.66", "a3": "0.81", "gain": "0.09" },
        "..."
    ],
    "features": [
        { "feature_name": "MEAN",         "input": "Acc_V2"          },
        { "feature_name": "MEAN",         "input": "Acc_V2_filter_1" },
        { "feature_name": "VARIANCE",     "input": "Acc_V2"          },
        { "feature_name": "VARIANCE",     "input": "Acc_V2_filter_1" },
        { "feature_name": "ENERGY",       "input": "Acc_V2"          },
        { "feature_name": "ENERGY",       "input": "Acc_V2_filter_1" },
        { "feature_name": "PEAK_TO_PEAK", "input": "Acc_V2"          },
        { "feature_name": "PEAK_TO_PEAK", "input": "Acc_V2_filter_1" },
        "..."
    ],
    "dectree_features": [
        "F1_MEAN_ACC_V2",
        "F2_MEAN_ACC_V2_FILTER_1",
        "F3_VARIANCE_ACC_V2",
        "F4_VARIANCE_ACC_V2_FILTER_1",
        "F5_ENERGY_ACC_V2",
        "F6_ENERGY_ACC_V2_FILTER_1",
        "F7_PEAK_TO_PEAK_ACC_V2",
        "F8_PEAK_TO_PEAK_ACC_V2_FILTER_1",
        "..."
    ],
    "dectrees": [
        {
            "filename": "/path/to/workspace/dectree.txt",
            "results": [
                { "label": "stationary", "value": 1  },
                { "label": "walking",    "value": 4  },
                { "label": "cycling",    "value": 8  },
                { "label": "running",    "value": 12 },
            ],
            "metaclassifier": [ 2, 2, 2, 2 ]
        },
        "..."
    ],
    "arff": "/path/to/workspace/features.arff",
    "ucf": "/path/to/workspace/mlc_conf.ucf"
}