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
2 changes: 2 additions & 0 deletions tfjs-converter/docs/supported_ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
|Any|any|
|ArgMax|argMax|
|ArgMin|argMin|
|Cumsum|cumsum|
|Max|max|
|Mean|mean|
|Min|min|
Expand Down Expand Up @@ -273,6 +274,7 @@
|Tensorflow Op Name|Tensorflow.js Op Name|
|---|---|
|BatchToSpaceND|batchToSpaceND|
|BroadcstTo|broadcastTo|
|Cast|cast|
|DepthToSpace|depthToSpace|
|ExpandDims|expandDims|
Expand Down
24 changes: 24 additions & 0 deletions tfjs-converter/python/tensorflowjs/op_list/convolution.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@
"type": "string",
"defaultValue": "NHWC"
},
{
"tfName": "explicit_paddings",
"name": "explicitPaddings",
"type": "number[]",
"defaultValue": []
},
{
"tfName": "dilations",
"name": "dilations",
Expand Down Expand Up @@ -416,6 +422,12 @@
"name": "dataFormat",
"type": "string",
"notSupported": true
},
{
"tfName": "explicit_paddings",
"name": "explicitPaddings",
"type": "number[]",
"defaultValue": []
}
]
},
Expand Down Expand Up @@ -451,6 +463,12 @@
"type": "string",
"defaultValue": "NHWC"
},
{
"tfName": "explicit_paddings",
"name": "explicitPaddings",
"type": "number[]",
"defaultValue": []
},
{
"tfName": "dilations",
"name": "dilations",
Expand Down Expand Up @@ -490,6 +508,12 @@
"type": "string",
"defaultValue": "NHWC"
},
{
"tfName": "explicit_paddings",
"name": "explicitPaddings",
"type": "number[]",
"defaultValue": []
},
{
"tfName": "dilations",
"name": "dilations",
Expand Down
28 changes: 28 additions & 0 deletions tfjs-converter/python/tensorflowjs/op_list/reduction.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,33 @@
"type": "bool"
}
]
},
{
"tfOpName": "Cumsum",
"category": "reduction",
"inputs": [
{
"start": 0,
"name": "x",
"type": "tensor"
},
{
"start": 1,
"name": "axis",
"type": "number"
}
],
"attrs": [
{
"tfName": "exclusive",
"name": "exclusive",
"type": "bool"
},
{
"tfName": "reverse",
"name": "reverse",
"type": "bool"
}
]
}
]
17 changes: 17 additions & 0 deletions tfjs-converter/python/tensorflowjs/op_list/transformation.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,22 @@
"type": "string"
}
]
},
{
"tfOpName": "BroadcastTo",
"category": "transformation",
"inputs": [
{
"start": 0,
"name": "x",
"type": "tensor"
},
{
"start": 1,
"name": "shape",
"type": "number[]"
}
],
"attrs": []
}
]
16 changes: 13 additions & 3 deletions tfjs-converter/src/operations/executors/reduction_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import {InternalOpExecutor, Node} from '../types';
import {getParamValue} from './utils';

export const executeOp: InternalOpExecutor = (node: Node,
tensorMap: NamedTensorsMap,
context: ExecutionContext):
tfc.Tensor[] => {
tensorMap: NamedTensorsMap,
context: ExecutionContext):
tfc.Tensor[] => {
switch (node.op) {
case 'Max': {
const axis = getParamValue('axis', node, tensorMap, context) as number[];
Expand Down Expand Up @@ -94,6 +94,16 @@ export const executeOp: InternalOpExecutor = (node: Node,
getParamValue('x', node, tensorMap, context) as tfc.Tensor, axis,
keepDims)];
}
case 'Cumsum': {
const axis = getParamValue('axis', node, tensorMap, context) as number;
const exclusive =
getParamValue('exclusive', node, tensorMap, context) as boolean;
const reverse =
getParamValue('reverse', node, tensorMap, context) as boolean;
return [tfc.cumsum(
getParamValue('x', node, tensorMap, context) as tfc.Tensor, axis,
exclusive, reverse)];
}
default:
throw TypeError(`Node type ${node.op} is not implemented`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {ExecutionContext} from '../../executor/execution_context';
import {Node} from '../types';

import {executeOp} from './reduction_executor';
import {createBoolAttr, createNumberAttr, createTensorAttr} from './test_helper';
import {createBoolAttr, createNumberAttr, createNumberAttrFromIndex, createTensorAttr} from './test_helper';

describe('reduction', () => {
let node: Node;
Expand Down Expand Up @@ -68,6 +68,20 @@ describe('reduction', () => {

expect(tfc.argMin).toHaveBeenCalledWith(input1[0], 1);
});
describe('Cumsum', () => {
it('should call tfc.cumsum', () => {
spyOn(tfc, 'cumsum');
node.op = 'Cumsum';
node.attrParams.exclusive = createBoolAttr(true);
node.attrParams.reverse = createBoolAttr(false);
node.inputNames = ['input1', 'input2'];
node.inputParams.axis = createNumberAttrFromIndex(1);
const input2 = [tfc.scalar(2)];
executeOp(node, {input1, input2}, context);

expect(tfc.cumsum).toHaveBeenCalledWith(input1[0], 2, true, false);
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import {InternalOpExecutor, Node} from '../types';
import {getParamValue, split} from './utils';

export const executeOp: InternalOpExecutor = (node: Node,
tensorMap: NamedTensorsMap,
context: ExecutionContext):
tfc.Tensor[] => {
tensorMap: NamedTensorsMap,
context: ExecutionContext):
tfc.Tensor[] => {
switch (node.op) {
case 'Cast': {
return [tfc.cast(
Expand Down Expand Up @@ -88,6 +88,11 @@ export const executeOp: InternalOpExecutor = (node: Node,
getParamValue('x', node, tensorMap, context) as tfc.Tensor4D,
blockSize, dataFormat)];
}
case 'BroadcastTo': {
return [tfc.broadcastTo(
getParamValue('x', node, tensorMap, context) as tfc.Tensor,
getParamValue('shape', node, tensorMap, context) as number[])];
}
default:
throw TypeError(`Node type ${node.op} is not implemented`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,17 @@ describe('transformation', () => {
expect(tfc.depthToSpace).toHaveBeenCalledWith(input1[0], 1, 'NHWC');
});
});
describe('BroadcastTo', () => {
it('should call tfc.broadcastTo', () => {
spyOn(tfc, 'broadcastTo');
node.op = 'BroadcastTo';
node.inputParams.shape = createNumericArrayAttrFromIndex(1);
node.inputNames = ['input1', 'input2'];

executeOp(node, {input1, input2}, context);

expect(tfc.broadcastTo).toHaveBeenCalledWith(input1[0], [1, 1]);
});
});
});
});
29 changes: 27 additions & 2 deletions tfjs-converter/src/operations/op_list/convolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ export const json: OpMapper[] = [
'type': 'string',
'defaultValue': 'NHWC'
},
{
'tfName': 'explicit_paddings',
'name': 'explicitPaddings',
'type': 'number[]',
'defaultValue': []
},
{'tfName': 'dilations', 'name': 'dilations', 'type': 'number[]'}
]
},
Expand Down Expand Up @@ -211,12 +217,19 @@ export const json: OpMapper[] = [
],
'attrs': [
{'tfName': 'strides', 'name': 'strides', 'type': 'number[]'},
{'tfName': 'padding', 'name': 'pad', 'type': 'string'}, {
{'tfName': 'padding', 'name': 'pad', 'type': 'string'},
{
'tfName': 'data_format',
'name': 'dataFormat',
'type': 'string',
'notSupported': true
}
},
{
'tfName': 'explicit_paddings',
'name': 'explicitPaddings',
'type': 'number[]',
'defaultValue': []
},
]
},
{
Expand All @@ -234,6 +247,12 @@ export const json: OpMapper[] = [
'type': 'string',
'defaultValue': 'NHWC'
},
{
'tfName': 'explicit_paddings',
'name': 'explicitPaddings',
'type': 'number[]',
'defaultValue': []
},
{'tfName': 'dilations', 'name': 'dilations', 'type': 'number[]'}
]
},
Expand All @@ -252,6 +271,12 @@ export const json: OpMapper[] = [
'type': 'string',
'defaultValue': 'NHWC'
},
{
'tfName': 'explicit_paddings',
'name': 'explicitPaddings',
'type': 'number[]',
'defaultValue': []
},
{'tfName': 'dilations', 'name': 'dilations', 'type': 'number[]'}
]
},
Expand Down
12 changes: 12 additions & 0 deletions tfjs-converter/src/operations/op_list/reduction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,17 @@ export const json: OpMapper[] = [
{'start': 1, 'name': 'axis', 'type': 'number[]'},
],
'attrs': [{'tfName': 'keep_dims', 'name': 'keepDims', 'type': 'bool'}]
},
{
'tfOpName': 'Cumsum',
'category': 'reduction',
'inputs': [
{'start': 0, 'name': 'x', 'type': 'tensor'},
{'start': 1, 'name': 'axis', 'type': 'number'},
],
'attrs': [
{'tfName': 'exclusive', 'name': 'exclusive', 'type': 'bool'},
{'tfName': 'reverse', 'name': 'reverse', 'type': 'bool'}
]
}
];
9 changes: 9 additions & 0 deletions tfjs-converter/src/operations/op_list/transformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,14 @@ export const json: OpMapper[] = [
{'tfName': 'block_size', 'name': 'blockSize', 'type': 'number'},
{'tfName': 'data_format', 'name': 'dataFormat', 'type': 'string'}
]
},
{
'tfOpName': 'BroadcastTo',
'category': 'transformation',
'inputs': [
{'start': 0, 'name': 'x', 'type': 'tensor'},
{'start': 1, 'name': 'shape', 'type': 'number[]'},
],
'attrs': []
}
];