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 @@ -145,6 +145,7 @@
|ListDiff|setdiff1dAsync|
|NonMaxSuppressionV2|nonMaxSuppression|
|NonMaxSuppressionV3|nonMaxSuppression|
|NonMaxSuppressionV5|nonMaxSuppression|
|Where|whereAsync|

## Operations - Evaluation
Expand Down
36 changes: 36 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,42 @@
}
]
},
{
"tfOpName": "NonMaxSuppressionV5",
"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"
},
{
"start": 5,
"name": "softNmsSigma",
"type": "number"
}
]
},
{
"tfOpName": "Where",
"category": "dynamic",
Expand Down
5 changes: 3 additions & 2 deletions tfjs-converter/src/executor/model_analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ export function getNodesInTopologicalOrder(
}

const CONTROL_FLOW_OPS = ['Switch', 'Merge', 'Enter', 'Exit', 'NextIteration'];
const DYNAMIC_SHAPE_OPS =
['NonMaxSuppressionV2', 'NonMaxSuppressionV3', 'Where'];
const DYNAMIC_SHAPE_OPS = [
'NonMaxSuppressionV2', 'NonMaxSuppressionV3', 'NonMaxSuppressionV5', 'Where'
];

export function isControlFlow(node: Node) {
return CONTROL_FLOW_OPS.indexOf(node.op) >= 0;
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 @@ -26,6 +26,7 @@ export async function executeOp(
node: Node, tensorMap: NamedTensorsMap,
context: ExecutionContext): Promise<tfc.Tensor[]> {
switch (node.op) {
case 'NonMaxSuppressionV5':
case 'NonMaxSuppressionV3':
case 'NonMaxSuppressionV2': {
const boxes =
Expand All @@ -38,6 +39,18 @@ export async function executeOp(
getParamValue('iouThreshold', node, tensorMap, context) as number;
const scoreThreshold =
getParamValue('scoreThreshold', node, tensorMap, context) as number;

if (node.op === 'NonMaxSuppressionV5') {
const softNmsSigma =
getParamValue('softNmsSigma', node, tensorMap, context) as number;

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

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

return [await tfc.image.nonMaxSuppressionAsync(
boxes as tfc.Tensor2D, scores as tfc.Tensor1D, maxOutputSize,
iouThreshold, scoreThreshold)];
Expand Down
39 changes: 39 additions & 0 deletions tfjs-converter/src/operations/executors/dynamic_executor_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,45 @@ describe('dynamic', () => {
});
});

describe('NonMaxSuppressionV5', () => {
it('should return input', () => {
node.op = 'NonMaxSuppressionV5';
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.inputParams['softNmsSigma'] = createNumberAttrFromIndex(5);
node.inputNames =
['input1', 'input2', 'input3', 'input4', 'input5', 'input6'];
const input2 = [tfc.tensor1d([1])];
const input3 = [tfc.tensor1d([1])];
const input4 = [tfc.tensor1d([1])];
const input5 = [tfc.tensor1d([1])];
const input6 = [tfc.tensor1d([1])];
spyOn(tfc.image, 'nonMaxSuppressionWithScoreAsync').and.callThrough();
const result = executeOp(
node, {input1, input2, input3, input4, input5, input6}, context);
expect(tfc.image.nonMaxSuppressionWithScoreAsync)
.toHaveBeenCalledWith(input1[0], input2[0], 1, 1, 1, 1);
expect(result instanceof Promise).toBeTruthy();
});
it('should match json def', () => {
node.op = 'NonMaxSuppressionV5';
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.inputParams['softNmsSigma'] = createNumberAttrFromIndex(5);
node.inputNames =
['input1', 'input2', 'input3', 'input4', 'input5', 'input6'];

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

describe('Where', () => {
it('should call tfc.whereAsync', async () => {
node.op = 'Where';
Expand Down
12 changes: 12 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,18 @@ export const json: OpMapper[] = [
{'start': 4, 'name': 'scoreThreshold', 'type': 'number'}
]
},
{
'tfOpName': 'NonMaxSuppressionV5',
'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'},
{'start': 5, 'name': 'softNmsSigma', 'type': 'number'}
]
},
{
'tfOpName': 'Where',
'category': 'dynamic',
Expand Down