Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tfjs-converter/docs/supported_ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
|ListDiff|setdiff1dAsync|
|NonMaxSuppressionV2|nonMaxSuppression|
|NonMaxSuppressionV3|nonMaxSuppression|
|NonMaxSuppressionV4|nonMaxSuppression|
|NonMaxSuppressionV5|nonMaxSuppression|
|Where|whereAsync|

Expand Down
50 changes: 50 additions & 0 deletions tfjs-converter/python/tensorflowjs/op_list/dynamic.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,56 @@
}
]
},
{
"tfOpName": "NonMaxSuppressionV4",
"category": "dynamic",
"inputs": [
{
"start": 0,
"name": "boxes",
"type": "tensor"
},
{
"start": 1,
"name": "scores",
"type": "tensor"
},
{
"start": 2,
"name": "maxOutputSize",
"type": "number"
},
{
"start": 3,
"name": "iouThreshold",
"type": "number"
},
{
"start": 4,
"name": "scoreThreshold",
"type": "number"
}
],
"attrs": [
{
"tfName": "T",
"name": "dtype",
"type": "dtype",
"notSupported": true
},
{
"tfName": "T_threshold",
"name": "threshold",
"type": "dtype",
"notSupported": true
},
{
"tfName": "pad_to_max_output_size",
"name": "padToMaxOutputSize",
"type": "bool"
}
]
},
{
"tfOpName": "NonMaxSuppressionV5",
"category": "dynamic",
Expand Down
13 changes: 13 additions & 0 deletions tfjs-converter/src/operations/executors/dynamic_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const executeOp: InternalOpAsyncExecutor = async(
context: ExecutionContext): Promise<tfc.Tensor[]> => {
switch (node.op) {
case 'NonMaxSuppressionV5':
case 'NonMaxSuppressionV4':
case 'NonMaxSuppressionV3':
case 'NonMaxSuppressionV2': {
const boxes =
Expand All @@ -52,6 +53,18 @@ export const executeOp: InternalOpAsyncExecutor = async(
return [result.selectedIndices, result.selectedScores];
}

if (node.op === 'NonMaxSuppressionV4') {
const padToMaxOutputSize =
getParamValue('padToMaxOutputSize', node, tensorMap, context) as
boolean;

const result = await tfc.image.nonMaxSuppressionPaddedAsync(
boxes as tfc.Tensor2D, scores as tfc.Tensor1D, maxOutputSize,
iouThreshold, scoreThreshold, padToMaxOutputSize);

return [result.selectedIndices, result.validOutputs];
}

return [await tfc.image.nonMaxSuppressionAsync(
boxes as tfc.Tensor2D, scores as tfc.Tensor1D, maxOutputSize,
iouThreshold, scoreThreshold)];
Expand Down
38 changes: 37 additions & 1 deletion tfjs-converter/src/operations/executors/dynamic_executor_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as dynamic from '../op_list/dynamic';
import {Node} from '../types';

import {executeOp} from './dynamic_executor';
import {createNumberAttrFromIndex, createTensorAttr, validateParam} from './test_helper';
import {createBoolAttr, createNumberAttrFromIndex, createTensorAttr, validateParam} from './test_helper';

describe('dynamic', () => {
let node: Node;
Expand Down Expand Up @@ -109,6 +109,42 @@ describe('dynamic', () => {
});
});

describe('NonMaxSuppressionV4', () => {
it('should return input', () => {
node.op = 'NonMaxSuppressionV4';
node.inputParams['boxes'] = createTensorAttr(0);
node.inputParams['scores'] = createTensorAttr(1);
node.inputParams['maxOutputSize'] = createNumberAttrFromIndex(2);
node.inputParams['iouThreshold'] = createNumberAttrFromIndex(3);
node.inputParams['scoreThreshold'] = createNumberAttrFromIndex(4);
node.attrParams['padToMaxOutputSize'] = createBoolAttr(true);
node.inputNames = ['input1', 'input2', 'input3', 'input4', 'input5'];
const input2 = [tfc.tensor1d([1])];
const input3 = [tfc.tensor1d([1])];
const input4 = [tfc.tensor1d([1])];
const input5 = [tfc.tensor1d([1])];
spyOn(tfc.image, 'nonMaxSuppressionPaddedAsync').and.returnValue({});
const result =
executeOp(node, {input1, input2, input3, input4, input5}, context);
expect(tfc.image.nonMaxSuppressionPaddedAsync)
.toHaveBeenCalledWith(input1[0], input2[0], 1, 1, 1, true);
expect(result instanceof Promise).toBeTruthy();
});
it('should match json def', () => {
node.op = 'NonMaxSuppressionV4';
node.inputParams['boxes'] = createTensorAttr(0);
node.inputParams['scores'] = createTensorAttr(1);
node.inputParams['maxOutputSize'] = createNumberAttrFromIndex(2);
node.inputParams['iouThreshold'] = createNumberAttrFromIndex(3);
node.inputParams['scoreThreshold'] = createNumberAttrFromIndex(4);
node.attrParams['padToMaxOutputSize'] = createBoolAttr(true);
node.inputNames = ['input1', 'input2', 'input3', 'input4', 'input5'];

expect(validateParam(node, dynamic.json, 'NonMaxSuppressionV4'))
.toBeTruthy();
});
});

describe('NonMaxSuppressionV5', () => {
it('should return input', () => {
node.op = 'NonMaxSuppressionV5';
Expand Down
24 changes: 24 additions & 0 deletions tfjs-converter/src/operations/op_list/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ export const json: OpMapper[] = [
{'start': 4, 'name': 'scoreThreshold', 'type': 'number'}
]
},
{
'tfOpName': 'NonMaxSuppressionV4',
'category': 'dynamic',
'inputs': [
{'start': 0, 'name': 'boxes', 'type': 'tensor'},
{'start': 1, 'name': 'scores', 'type': 'tensor'},
{'start': 2, 'name': 'maxOutputSize', 'type': 'number'},
{'start': 3, 'name': 'iouThreshold', 'type': 'number'},
{'start': 4, 'name': 'scoreThreshold', 'type': 'number'}
],
'attrs': [
{'tfName': 'T', 'name': 'dtype', 'type': 'dtype', 'notSupported': true}, {
'tfName': 'T_threshold',
'name': 'threshold',
'type': 'dtype',
'notSupported': true
},
{
'tfName': 'pad_to_max_output_size',
'name': 'padToMaxOutputSize',
'type': 'bool'
}
]
},
{
'tfOpName': 'NonMaxSuppressionV5',
'category': 'dynamic',
Expand Down