Knowledge Packs

The model that gets generated for your edge device is called a Knowledge Pack. A Knowledge Pack contains the device firmware code for detecting events in your application and will be flashed to your device. The Knowledge Pack contains all the information about how the model was trained, the metrics for the trained model, as well as the full trained pipeline model.

Download Knowledge Pack

To download a Knowledge Pack, you will need to create a configuration for the download.

The first part of the configuration is the kb_description, which describes the models that will be part of the Knowledge Pack. The format is as follows:

kb_description = {
   "MODEL_1": {
      "source": "<CAPTURE CONFIG UUID>",
      "uuid": "<Model UUID>"
   },
}

Where model name can be whatever you choose. Source is the capture configuration that the model should use (this is used to set up the correct sensors and sample rate). uuid is the model UUID to use.

To get the UUID of the capture configuration and Knowledge Pack for a particular project use the following:

client.project.list_knowledgepacks()

client.list_capture_configurations()

Next we will create the config for the download. To see a list of available target platforms along with their application and output_options use:

client.platforms_v2()

You can generate the template configuration by using the following

config = client.platforms_v2.get_platform_by_name('x86 GCC Generic').get_config()

replace the “x86 GCC Generic” platform name with the platform you would like to download.

print(config)

{'target_platform': '26eef4c2-6317-4094-8013-08503dcd4bc5',
'test_data': '',
'debug': False,
'output_options': ['serial'],
'application': 'SensiML AI Model Runner',
'target_processor': '822581d2-8845-4692-bcac-4446d341d4a0',
'target_compiler': '62aabe7e-4f5d-4167-a786-072e468dc158',
'float_options': '',
'selected_platform_version': ''}

config["kb_description"] = kb_description

And finally, we can now download the model as a library source (if supported by your subscription) or binary (if supported by your platform).

kp = client.get_knowledgepack("<MODEL UUID>")

kp.download_library_v2(config=config)
# kp.download_binary_v2(config=config)
# kp.download_source_v2(config=config)

Multi Model Knowledge Pack

If you want to download multiple Knowledge Packs at once you will need to use the programmatic interface. Models can either be Parent or Children Models. Parent models require a source. Children models require a segmenter_from and parent flag. Optional flags are results which allows a Child model to be called depending on the output of a Parent model.

The model graphs are defined in the kb_description. The format for multiple parent models is as follows:

{
   "MODEL_1": {
      "source": "<CAPTURE CONFIG UUID>",
      "uuid": "<Model UUID>"
   },
   "MODEL_2": {
      "source": "<CAPTURE CONFIG UUID>",
      "uuid": "<Model UUID>"
   },
   "MODEL_3": {
      "source": "<CAPTURE CONFIG UUID>",
      "uuid": "<Model UUID>"
   }
}

The format for multiple parent models and with multiple child models is as follows:

{
   "PARENT_1": {
      "source": "<CAPTURE CONFIG UUID>",
      "uuid": "<Model UUID>",
      "results": {
            "1": "CHILD_1",
            "2": "CHILD_2"
      }
   },
   "PARENT_2": {
      "source": "<CAPTURE CONFIG UUID>",
      "uuid": "<Model UUID>",
   },
   "CHILD_1": {
      "uuid": "<Model UUID>",
      "parent": "PARENT_1",
      "results": {
            "1": "Child 4",
      },
      "segmenter_from": "parent"
   },
   "CHILD_2": {
      "uuid": "<Model UUID>",
      "parent": "PARENT_1",
      "segmenter_from": "parent"
   },
   "CHILD_3": {
      "uuid": "<Model UUID>",
      "parent": "PARENT_1",
      "segmenter_from": "parent"
   },
   "CHILD_4": {
      "uuid": "<Model UUID>",
      "parent": "PARENT_1",
      "segmenter_from": "parent"
   }
}
class sensiml.datamanager.knowledgepack.KnowledgePack(connection, project_uuid, sandbox_uuid)

Base class for a KnowledgePack

property class_map

A summary of the integer classes/categories used by the KnowledgePack and the corresponding application categories

property cost_dict

A summary of device costs incurred by the KnowledgePack

property cost_report

A printed tabular report of the device cost incurred by the KnowledgePack

property cost_report_json

A JSON report of the Knowledge Pack cost summary

cost_resource_summary(processor_uuid=None, hardware_accelerator=None)

A summary of resources and time needed in a classification from a Knowledge Pack

delete()

Deletes the knowledgepack

Returns

result of executed pipeline, specified by the sandbox (dict): execution summary including execution time and whether cache was used for each step; also contains a feature cost table if applicable

Return type

(DataFrame or ModelResultSet)

download_binary_v2(folder='', run_async=True, platform=None, renderer=None, *args, **kwargs)

Calls the server to generate full binary image based on device config.

Parameters

folder (str) – Folder to save to if not generating a link

Returns

Denoting success, or link to file download

Return type

str

download_library_v2(folder='', run_async=True, platform=None, renderer=None, *args, **kwargs)

Calls the server to generate static library image based on device config.

Parameters

folder (str) – Folder to save to if not generating a link

Returns

Denoting success, or link to file download

Return type

str

download_source_v2(folder='', run_async=True, platform=None, renderer=None, *args, **kwargs)

Calls the server to generate static library image based on device config.

Parameters

folder (str) – Folder to save to if not generating a link

Returns

Denoting success, or link to file download

Return type

str

property feature_summary

A summary of the features generated by the KnowledgePack

get_report(report_type, processor_uuid=None, hardware_accelerator=None)

Sends a request for a report to the server and returns the result.

Parameters

report_type (string) – string name of report, ex: ‘cost’

Returns

string representation of desired report

Return type

(string)

property knowledgepack_description

Description of knowledgepack. It is for the hierarchical model which created by Autosense

property knowledgepack_summary

A summary of device costs incurred by the KnowledgePack

property model_parameters

The model’s parameters

property model_results

The model results associated with the KnowledgePack (in JSON form)

property neuron_array

The model’s neuron array

property pipeline_summary

A summary specification of the pipeline which created the KnowledgePack

property query_summary

A summary specification of the query used by the pipeline which created the KnowledgePack

recognize_features(data)

Sends a single vector of features to the KnowledgePack for recognition.

Parameters

data (dict) –

dictionary containing

  • a feature vector in the format ‘Vector’: [126, 32, 0, …]

  • ’DesiredResponses’ indicating the number of neuron responses to return

Returns

dictionary containing

  • CategoryVector (list): numerical categories of the neurons that fired

  • MappedCategoryVector (list): original class categories of the neurons that fired

  • NIDVector (list): ID numbers of the neurons that fired

  • DistanceVector (list): distances of the feature vector to each neuron that fired

Return type

(dict)

recognize_signal(capture=None, datafile=None, stop_step=False, segmenter=True, platform='emulator', get_result=True, kb_description=None, compare_labels=False, renderer=None)

Sends a DataFrame of raw signals to be run through the feature generation pipeline and recognized.

Parameters
  • capturefile (str) – The name of a file uploaded through the data capture lab

  • datafile (str) – The name of an uploading datafile

  • platform (str) – “emulator” or “cloud”. The “emulator” will run compiled c code giving device exact results, the cloud runs similarly to training providing more flexibility in returning early results by setting the stop step.

  • stop_step (int) – for debugging, if you want to stop the pipeline at a particular step, set stop_step to its index

  • compare_labels (bool) – If there are labels for the input dataframe, use them to create a confusion matrix

  • segmenter (bool or FunctionCall) – to suppress or override the segmentation algorithm in the original pipeline, set this to False or a function call of type ‘segmenter’ (defaults to True)

  • lock (bool, True) – If True, waits for the result to return before releasing the ipython cell.

Returns

dictionary of results and summary statistics from the executed pipeline and recognition

Return type

(dict)

retrieve(silent=False)

Gets the result of a prior asynchronous execution of the sandbox.

Returns

result of executed pipeline, specified by the sandbox (dict): execution summary including execution time and whether cache was used for each step; also contains a feature cost table if applicable

Return type

(DataFrame or ModelResultSet)

property reverse_class_map

A summary of the category/integer class used by the KnowledgePack and the corresponding application categories

save(name)

Save a knowledgepack with a name.

Returns

result of executed pipeline, specified by the sandbox (dict): execution summary including execution time and whether cache was used for each step; also contains a feature cost table if applicable

Return type

(DataFrame or ModelResultSet)

property sensor_summary

A summary of sensor streams used by the KnowledgePack

stop_recognize_signal()

Sends a kill signal to a pipeline

property training_metrics

The training metrics associated with the KnowledgePack

property transform_summary

A summary of transform parameters used by the KnowledgePack