[ML][Pipeline] Implement {register, unregister}CustomFilter 10/253510/13
authorPawel Wasowski <p.wasowski2@samsung.com>
Thu, 18 Feb 2021 10:09:04 +0000 (11:09 +0100)
committerPawel Wasowski <p.wasowski2@samsung.com>
Tue, 23 Feb 2021 17:45:46 +0000 (18:45 +0100)
commitc6556c49aaaf300dc21164c1b590558791eaf71a
tree34309ae137e4e54359f564c01eeb785c43376874
parent45f69e4d1f2c471b13cf1f9ddf2440e8e841ef9c
[ML][Pipeline] Implement {register, unregister}CustomFilter

ACR: TWDAPI-274

This is the first part of the implementation of nnstreamer's pipeline
CustomFilter Web API. It enables registering and unregistering
CustomFilters, but they don't process the data.

[Verification] Tested with the snippets below, works fine

var inputTI = new tizen.ml.TensorsInfo();
inputTI.addTensorInfo('ti1', 'UINT8', [4, 20, 15, 1]);
var outputTI = new tizen.ml.TensorsInfo();
outputTI.addTensorInfo('ti1', 'UINT8', [1200]);
var flattenPlusOne = function(input) {
    console.log("Custom filter called with: ");
    var outputTD = outputTI.getTensorsData();
    var rawInputData = input.getTensorRawData(0);
    for (var i = 0; i < rawInputData.data.size; ++i) {
        rawInputData.data[i] = rawInputData.data[i] + 1;
    }
        outputTD.setTensorRawData(0, rawInputData.data);
        return new tizen.ml.CustomFilterOutput(0, outputTD);
}

// register - the happy scenario
tizen.ml.pipeline.registerCustomFilter('testfilter2', flattenPlusOne, inputTI,
    outputTI, function errorCallback(error) {
        console.warn('custom filter error:') ; console.warn(error);
    });

var pipeline_def = "videotestsrc num-buffers=3 "
                   + "! video/x-raw,width=20,height=15,format=BGRA "
                   + "! tensor_converter "
                   + "! tensor_filter framework=custom-easy model=testfilter2 "
                   + "! appsink name=mysink";

var pipeline = tizen.ml.pipeline.createPipeline(pipeline_def,
                                                state => {console.log(state);})
// READY
pipeline.start()

// unregister - the happy scenario
tizen.ml.pipeline.unregisterCustomFilter('testfilter2')

// overwrite a previously registered filter - that's ok

tizen.ml.pipeline.registerCustomFilter('testfilter2', flattenPlusOne, inputTI,
    outputTI, function errorCallback(error) {
        console.warn('custom filter error:') ; console.warn(error);
    });

tizen.ml.pipeline.registerCustomFilter('testfilter2', flattenPlusOne, inputTI,
    outputTI, function errorCallback(error) {
        console.warn('custom filter error:') ; console.warn(error);
    });

// unregister nonexistent filter
tizen.ml.pipeline.unregisterCustomFilter('nonexistentfilter')
// InvalidValuesError: ""nonexistentfilter" CustomFilter not found"

Change-Id: Ib01490e669376149eae654937131116f5ec1a4df
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
src/ml/js/ml_pipeline.js
src/ml/ml.gyp
src/ml/ml_instance.cc
src/ml/ml_instance.h
src/ml/ml_pipeline_custom_filter.cc [new file with mode: 0644]
src/ml/ml_pipeline_custom_filter.h [new file with mode: 0644]
src/ml/ml_pipeline_manager.cc
src/ml/ml_pipeline_manager.h