[ML][Pipeline] Change CustomFilter interface and implementation
ACR: TWDAPI-274
CustomFilter API and implementation are changed to avoid
copying TensorsData.
Change-Id: Id48b774c86b65f5b45f3dd74733c006b6a729b8c
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
[Verification] Code tested with the snippets below works fine
// Valid CustomFilter callback - the happy scenario
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 flattenAndSet123 = function(input, output) {
console.log("Custom filter called");
var rawOutputData = new Uint8Array(1200);
for (var i = 0; i < rawOutputData.length; ++i) {
rawOutputData[i] = 123;
}
output.setTensorRawData(0, rawOutputData);
return 0;
}
tizen.ml.pipeline.registerCustomFilter('testfilter2', flattenAndSet123, 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);})
pipeline.registerSinkListener('mysink', function(sinkName, data) {
console.log('SinkListener for "' + sinkName + '" sink called');
console.log(data);
})
// READY
// Custom filter called
// PAUSED
pipeline.start()
// PLAYING
// <CustomFilter and SinkListener callbacks' outputs 3 times>
////////////////////////////////////////////////////////////
// Valid CustomFilter callback - the happy scenario; ignore the data
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, output) {
console.log("Custom filter called");
return 1; // ignore data
}
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);})
pipeline.registerSinkListener('mysink', function(sinkName, data) {
console.log('SinkListener for "' + sinkName + '" sink called');
console.log(data);
})
// READY
// Custom filter called
// Custom filter called
// Custom filter called
// PAUSED
pipeline.start()
// PLAYING
////////////////////////////////////////////////////////////
// Valid CustomFilter callback - CustomFilter returns an error
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, output) {
console.log("Custom filter called");
return -1;
}
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);})
pipeline.registerSinkListener('mysink', function(sinkName, data) {
console.log('SinkListener for "' + sinkName + '" sink called');
console.log(data);
})
// READY
// Custom filter called
// PAUSED
pipeline.start()
// PLAYING
////////////////////////////////////////////////////////////
// Invalid CustomFilterOutput.status
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");
return 123;
}
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);})
pipeline.registerSinkListener('mysink', function(sinkName, data) {
console.log('SinkListener for "' + sinkName + '" sink called');
console.log(data);
})
// InvalidValuesError,
// message: "CustomFilterOutput.status === 1 is the only legal positive value"
////////////////////////////////////////////////////////////
// Check if {input, output}.dispose() and input.setTensorRawData()
// have any effect
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 flattenAndSet123 = function(input, output) {
console.log("Custom filter called");
// dispose should have no efect
input.dispose();
console.log('input count: ' + input.tensorsInfo.count);
// dispose should have no efect
input.dispose();
console.log('output count: ' + output.tensorsInfo.count);
var rawOutputData = new Uint8Array(1200);
for (var i = 0; i < rawOutputData.length; ++i) {
rawOutputData[i] = 123;
}
output.setTensorRawData(0, rawOutputData);
// this call should have no effect
input.setTensorRawData(0, rawOutputData);
return 0;
}
tizen.ml.pipeline.registerCustomFilter('testfilter2', flattenAndSet123, 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);})
pipeline.registerSinkListener('mysink', function(sinkName, data) {
console.log('SinkListener for "' + sinkName + '" sink called');
console.log(data);
})
Change-Id: Id48b774c86b65f5b45f3dd74733c006b6a729b8c
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>