Tensors management
Machine Learning Web API in Tizen requires TensorsInfo and TensorsData objects. These objects are used to perform calculation with neural network models.
The main features of the Machine Learning API include the following:
-
Checking support of a specific neural network framework
You can check NNFW availability using
checkNNFWAvailability. -
Creating tensors structure
You can use the
TensorsInfoobject to manage the tensor information. -
Reading and writing raw data
You can read and write tensor data using the
TensorsDataobject.
Check NNFW availability
To check whether specific Neural Network Framework (NNFW) is supported, you can use checkNNFWAvailability:
var fw = "TENSORFLOW_LITE";
var hw = "CPU";
var available = tizen.ml.checkNNFWAvailability(fw, hw);
console.log(available); // true
Manage tensor information
-
To configure the tensor information, you need to create a new instance of the
TensorsInfoclass:var tensorsInfo = new tizen.ml.TensorsInfo(); -
TensorsInfoobject can store information such as name, data type, and dimensions:tensorsInfo.addTensorInfo("tensor", "UINT8", [2, 2]);Note
A single
TensorsInfoobject can store information about up to 16 tensors. -
You can modify tensor’s parameters with help of
setTensorName,setTensorType, andsetDimensions:tensorsInfo.setTensorName(0, "tensorName"); tensorsInfo.setTensorType(0, "UINT16"); tensorsInfo.setTensorDimensions(0, [2, 2]); -
To clone and compare
TensorsInfoobject:var clone = tensorsInfo.clone(); var isEqual = tensorsInfo.equals(clone);Note
Use
equals()to compareTensorInfoobjects. Comparisons must not be done with built-in==,===,!=,!==operators which may return false results for this data type. -
To calculate the byte size of tensor data use
getTensorSize:var byteSize = tensorsInfo.getTensorSize(0); -
After you create tensor definition, you can use
getTensorsDatato getTensorsDataobject:var tensorsData = tensorsInfo.getTensorsData(); -
Ensure to dispose off the
TensorsInfoobject when you do not need it anymore:tensorsInfo.dispose();
Manage tensor data
The TensorsData object keeps data value of the tensors.
-
To get specific data object from
TensorsData, usegetTensorRawData:var rawData = tensorsData.getTensorRawData(0);-
You can also specify the location and size of data you want to get:
// fetch one element var rawDataOne = tensorsData.getTensorRawData(0, [0, 0], [1, 1]); // fetch first row var rawDataRow = tensorsData.getTensorRawData(0, [0, 0], [-1, 1]);
Note
To gather more information about specifying location and size of the raw data, see
TensorsData.getTensorRawData(in TV applications). -
-
To set data to
TensorsDataobject, usesetTensorRawData:tensorsData.setTensorRawData(0, [1, 2, 3, 4]);-
You can also specify the location and size of data you want to set:
// set only one element tensorsData.setTensorRawData(0, [7], [0, 0], [1, 1]); // set first row tensorsData.setTensorRawData(0, [4, 5], [0, 0], [-1, 1]);
Note
To gather more information about specifying location and size of the raw data, see
TensorsData.setTensorRawData(in TV applications). -
-
Ensure to dispose off the
TensorsDataobjects when you do not need them anymore:tensorsData.dispose();
Related information
- Dependencies
- Tizen 6.5 and Higher for TV
- API References