chrome://machine-learning-internals
The internals page chrome://machine-learning-internals
contains tools for controlling the ML Service (connecting, disconnecting) and evaluating a subset of models for benchmarking or debugging purposes. To make a new model available here, follow the instructions below.
Adding your model to the internals Web UI page represents a maintenance burden in a couple of ways:
You should only do this if the benefits will outweigh the costs. Here's a discussion of some use cases:
Basically, you need add some html code of your tab to machine_learning_internals.html, and create a your_model_tab.js
file in in chrome/browser/resources/chromeos/machine_learning/. The html code defines the user interface for input and output, and your_model_tab.js
defines the behaviour, like which model id to load, how to compose input tensors and how to extract information from output tensors.
Concretely, in <tabbox>
section of machine_learning_internals.html, you need to add a <tab>
to <tabs>
as the title, add a <tabpanel>
in <tabpanels>
as the main part of your tab, then import the your_model_tab.js
file, like:
<tabbox> <tabs> <tab>Your Model</tab> </tabs> <tabpanels> <tabpanel> <!-- elements of the new tab --> </tabpanel> </tabpanels> </tabbox> <script src="your_model_tab.js"></script>
You can take test_model_tab and test_model_tab.js as an example.
Then you need to register the new-added your_model_tab.js
file in browser_resources.grd by adding an entry for it, like
<include name="IDR_MACHINE_LEARNING_INTERNALS_YOUR_MODEL_TAB_JS" file="resources\chromeos\machine_learning\your_model_tab.js" type="BINDATA" compress="gzip" />
After that, add it to machine_learning_internals_ui.cc, like
source->AddResourcePath("your_model_tab.js", IDR_MACHINE_LEARNING_INTERNALS_YOUR_MODEL_TAB_JS);
If constructing input for your model requires some complicated operation which is difficult for javascript, and you want to do it in cpp, you can modify the machine_learning_internals_page_handler.mojom file, add your interface function, and implement it in machine_learning_internals_page_handler.h and machine_learning_internals_page_handler.cc. Then you can call this interface via pageHandler
in machine_learning_internals.js, execute this complicate operation in cpp and get the result in javascript.