@tensorflow/tfjs-converter
Advanced tools
Comparing version 0.6.5 to 0.6.6
@@ -21,5 +21,7 @@ import { NamedTensorMap, NamedTensorsMap, TensorInfo } from '../data/types'; | ||
execute(inputs: NamedTensorsMap, strictInputCheck?: boolean, outputs?: string | string[]): NamedTensorMap; | ||
private getFrozenTensorIds(tensorMap); | ||
private checkTensorForDisposal(nodeName, node, tensorMap, context, tensorsToKeep, intermediateTensorConsumerCount); | ||
executeAsync(inputs: NamedTensorsMap, outputs?: string | string[]): Promise<NamedTensorMap>; | ||
private executeWithControlFlow(inputs, context); | ||
private processStack(inputNodes, stack, context, tensorMap, added); | ||
private processStack(inputNodes, stack, context, tensorMap, added, tensorsToKeep, intermediateTensorConsumerCount); | ||
private processChildNodes(node, stack, context, tensorMap, added); | ||
@@ -26,0 +28,0 @@ private calculateOutputs(outputs?); |
@@ -171,2 +171,4 @@ "use strict"; | ||
var tensorMap = __assign({}, _this.weightMap, inputs); | ||
var tensorsToKeep = _this.getFrozenTensorIds(tensorMap); | ||
var intermediateTensorConsumerCount = {}; | ||
var compiledNodes = _this.compiledMap.get(names.join(_this.SEPERATOR)); | ||
@@ -178,2 +180,3 @@ for (var i = 0; i < compiledNodes.length; i++) { | ||
operation_executor_1.executeOp(node, tensorMap, context); | ||
_this.checkTensorForDisposal(node.name, node, tensorMap, context, tensorsToKeep, intermediateTensorConsumerCount); | ||
} | ||
@@ -188,2 +191,39 @@ if (outputNames.every(function (name) { return !!tensorMap[name]; })) { | ||
}; | ||
GraphExecutor.prototype.getFrozenTensorIds = function (tensorMap) { | ||
var ids = Object.keys(tensorMap) | ||
.map(function (key) { return tensorMap[key]; }) | ||
.map(function (tensors) { return tensors.map(function (tensor) { return tensor.id; }); }); | ||
return new (Set.bind.apply(Set, [void 0].concat(ids)))(); | ||
}; | ||
GraphExecutor.prototype.checkTensorForDisposal = function (nodeName, node, tensorMap, context, tensorsToKeep, intermediateTensorConsumerCount) { | ||
if (node.category === 'control') { | ||
return; | ||
} | ||
tensorMap[nodeName].forEach(function (tensor) { | ||
if (tensor != null) { | ||
intermediateTensorConsumerCount[tensor.id] = | ||
(intermediateTensorConsumerCount[tensor.id] || 0) + | ||
node.children.length; | ||
} | ||
}); | ||
node.inputs.forEach(function (input) { | ||
if (input.category !== 'control') { | ||
var tensors = utils_1.getTensorsForCurrentContenxt(input.name, tensorMap, context); | ||
if (tensors != null) { | ||
tensors.forEach(function (tensor) { | ||
if (tensor && !tensorsToKeep.has(tensor.id)) { | ||
var count = intermediateTensorConsumerCount[tensor.id]; | ||
if (count === 1) { | ||
tensor.dispose(); | ||
delete intermediateTensorConsumerCount[tensor.id]; | ||
} | ||
else if (count != null) { | ||
intermediateTensorConsumerCount[tensor.id]--; | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
}; | ||
GraphExecutor.prototype.executeAsync = function (inputs, outputs) { | ||
@@ -225,3 +265,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
var names, inputNodes, stack, tensorMap, added, promises; | ||
var names, inputNodes, stack, tensorMap, intermediateTensorConsumerCount, tensorsToKeep, added, promises; | ||
return __generator(this, function (_a) { | ||
@@ -236,2 +276,4 @@ switch (_a.label) { | ||
tensorMap = __assign({}, this.weightMap, inputs); | ||
intermediateTensorConsumerCount = {}; | ||
tensorsToKeep = this.getFrozenTensorIds(tensorMap); | ||
added = {}; | ||
@@ -241,3 +283,3 @@ _a.label = 1; | ||
if (!(stack.length > 0)) return [3, 3]; | ||
promises = this.processStack(inputNodes, stack, context, tensorMap, added); | ||
promises = this.processStack(inputNodes, stack, context, tensorMap, added, tensorsToKeep, intermediateTensorConsumerCount); | ||
return [4, Promise.all(promises)]; | ||
@@ -252,3 +294,3 @@ case 2: | ||
}; | ||
GraphExecutor.prototype.processStack = function (inputNodes, stack, context, tensorMap, added) { | ||
GraphExecutor.prototype.processStack = function (inputNodes, stack, context, tensorMap, added, tensorsToKeep, intermediateTensorConsumerCount) { | ||
var _this = this; | ||
@@ -274,2 +316,3 @@ var promises = []; | ||
context.currentContext = currentContext_1; | ||
_this.checkTensorForDisposal(nodeName, item.node, tensorMap, context, tensorsToKeep, intermediateTensorConsumerCount); | ||
_this.processChildNodes(item.node, stack, context, tensorMap, added); | ||
@@ -281,2 +324,3 @@ return t; | ||
tensorMap[nodeName] = tensors; | ||
this_1.checkTensorForDisposal(nodeName, item.node, tensorMap, context, tensorsToKeep, intermediateTensorConsumerCount); | ||
this_1.processChildNodes(item.node, stack, context, tensorMap, added); | ||
@@ -283,0 +327,0 @@ } |
@@ -83,2 +83,4 @@ "use strict"; | ||
return [tfc.div(tfc.scalar(1.0, 'float32'), tfc.sqrt(utils_1.getTensor(node.inputNames[0], tensorMap, context)))]; | ||
case 'prod': | ||
return [tfc.prod(utils_1.getParamValue('x', node, tensorMap, context), utils_1.getParamValue('axes', node, tensorMap, context))]; | ||
default: | ||
@@ -85,0 +87,0 @@ throw TypeError("Node type " + node.op + " is not implemented"); |
@@ -66,3 +66,5 @@ "use strict"; | ||
return [3, 17]; | ||
case 1: return [2, [utils_1.getParamValue('pred', node, tensorMap, context)]]; | ||
case 1: return [2, [ | ||
utils_1.getParamValue('pred', node, tensorMap, context).clone() | ||
]]; | ||
case 2: | ||
@@ -72,6 +74,8 @@ pred = utils_1.getParamValue('pred', node, tensorMap, context); | ||
return [4, pred.data()]; | ||
case 3: return [2, (_b.sent())[0] ? [undefined, data_1] : [data_1, undefined]]; | ||
case 3: return [2, (_b.sent())[0] ? [undefined, data_1.clone()] : | ||
[data_1.clone(), undefined]]; | ||
case 4: | ||
inputName = node.inputNames.find(function (name) { return utils_1.getTensor(name, tensorMap, context) !== undefined; }); | ||
return [2, inputName ? [utils_1.getTensor(inputName, tensorMap, context)] : undefined]; | ||
return [2, inputName ? [utils_1.getTensor(inputName, tensorMap, context).clone()] : | ||
undefined]; | ||
case 5: | ||
@@ -81,11 +85,11 @@ frameId = utils_1.getParamValue('frameName', node, tensorMap, context); | ||
context.enterFrame(frameId); | ||
return [2, [data]]; | ||
return [2, [data.clone()]]; | ||
case 6: | ||
tensor = utils_1.getParamValue('tensor', node, tensorMap, context); | ||
context.exitFrame(); | ||
return [2, [tensor]]; | ||
return [2, [tensor.clone()]]; | ||
case 7: | ||
input = utils_1.getParamValue('tensor', node, tensorMap, context); | ||
context.nextIteration(); | ||
return [2, [input]]; | ||
return [2, [input.clone()]]; | ||
case 8: | ||
@@ -92,0 +96,0 @@ size = utils_1.getParamValue('size', node, tensorMap, context); |
@@ -16,3 +16,5 @@ "use strict"; | ||
case 'fakeQuantWithMinMaxVars': | ||
return [utils_1.getParamValue('x', node, tensorMap, context)]; | ||
return [ | ||
utils_1.getParamValue('x', node, tensorMap, context).clone() | ||
]; | ||
case 'snapshot': | ||
@@ -19,0 +21,0 @@ var snapshot = utils_1.getParamValue('x', node, tensorMap, context); |
@@ -80,2 +80,20 @@ "use strict"; | ||
} | ||
case 'scatterNd': { | ||
var indices = utils_1.getParamValue('indices', node, tensorMap, context); | ||
var values = utils_1.getParamValue('values', node, tensorMap, context); | ||
var shape = utils_1.getParamValue('shape', node, tensorMap, context); | ||
return [tfc.scatterND(indices, values, shape)]; | ||
} | ||
case 'gatherNd': { | ||
var x = utils_1.getParamValue('x', node, tensorMap, context); | ||
var indices = utils_1.getParamValue('indices', node, tensorMap, context); | ||
return [tfc.gatherND(x, indices)]; | ||
} | ||
case 'sparseToDense': { | ||
var indices = utils_1.getParamValue('sparseIndices', node, tensorMap, context); | ||
var shape = utils_1.getParamValue('outputShape', node, tensorMap, context); | ||
var sparseValues = utils_1.getParamValue('sparseValues', node, tensorMap, context); | ||
var defaultValue = utils_1.getParamValue('defaultValue', node, tensorMap, context); | ||
return [tfc.sparseToDense(indices, sparseValues, shape, defaultValue)]; | ||
} | ||
default: | ||
@@ -82,0 +100,0 @@ throw TypeError("Node type " + node.op + " is not implemented"); |
@@ -13,2 +13,2 @@ import { OpMapper, ParamValue } from '../types'; | ||
export declare function createDtypeAttr(dtype: string): ParamValue; | ||
export declare function validateParam(node: Node, opMappers: OpMapper[]): boolean; | ||
export declare function validateParam(node: Node, opMappers: OpMapper[], tfOpName?: string): boolean; |
@@ -43,4 +43,6 @@ "use strict"; | ||
exports.createDtypeAttr = createDtypeAttr; | ||
function validateParam(node, opMappers) { | ||
var opMapper = opMappers.find(function (mapper) { return mapper.dlOpName === node.op; }); | ||
function validateParam(node, opMappers, tfOpName) { | ||
var opMapper = tfOpName != null ? | ||
opMappers.find(function (mapper) { return mapper.tfOpName === tfOpName; }) : | ||
opMappers.find(function (mapper) { return mapper.dlOpName === node.op; }); | ||
return Object.keys(node.params).every(function (key) { | ||
@@ -47,0 +49,0 @@ var value = node.params[key]; |
@@ -7,4 +7,5 @@ import * as tfc from '@tensorflow/tfjs-core'; | ||
export declare function getTensor(name: string, tensorsMap: NamedTensorsMap, context: ExecutionContext): tfc.Tensor; | ||
export declare function getTensorsForCurrentContenxt(name: string, tensorsMap: NamedTensorsMap, context: ExecutionContext): tfc.Tensor[]; | ||
export declare function getNodeNameAndIndex(inputName: string, context?: ExecutionContext): [string, number]; | ||
export declare function parseNodeName(name: string): [string, number]; | ||
export declare function split(arr: number[], size: number): number[][]; |
@@ -34,2 +34,6 @@ "use strict"; | ||
exports.getTensor = getTensor; | ||
function getTensorsForCurrentContenxt(name, tensorsMap, context) { | ||
return tensorsMap[getNodeNameWithContextId(name, context.currentContextId)]; | ||
} | ||
exports.getTensorsForCurrentContenxt = getTensorsForCurrentContenxt; | ||
function getNodeNameAndIndex(inputName, context) { | ||
@@ -36,0 +40,0 @@ var _a = parseNodeName(inputName), nodeName = _a[0], index = _a[1]; |
@@ -464,4 +464,24 @@ "use strict"; | ||
] | ||
}, | ||
{ | ||
'tfOpName': 'Prod', | ||
'dlOpName': 'prod', | ||
'category': 'basic_math', | ||
'params': [ | ||
{ 'tfInputIndex': 0, 'dlParamName': 'x', 'type': 'tensor' }, | ||
{ 'tfInputIndex': 1, 'dlParamName': 'axes', 'type': 'number[]' }, { | ||
'tfParamName': 'keep_dims', | ||
'dlParamName': 'keepDims', | ||
'type': 'bool', | ||
'notSupported': true | ||
}, | ||
{ | ||
'tfParamName': 'T', | ||
'dlParamName': 'dtype', | ||
'type': 'dtype', | ||
'notSupported': true | ||
} | ||
] | ||
} | ||
]; | ||
//# sourceMappingURL=basic_math.js.map |
@@ -48,2 +48,17 @@ export declare const json: ({ | ||
'tfInputIndex': number; | ||
'dlParamName': string; | ||
'type': string; | ||
notSupported?: undefined; | ||
} | { | ||
'tfInputIndex': number; | ||
'dlParamName': string; | ||
'type': string; | ||
'notSupported': boolean; | ||
})[]; | ||
} | { | ||
'tfOpName': string; | ||
'dlOpName': string; | ||
'category': string; | ||
'params': ({ | ||
'tfInputIndex': number; | ||
'tfInputParamLength': number; | ||
@@ -95,2 +110,21 @@ 'dlParamName': string; | ||
})[]; | ||
} | { | ||
'tfOpName': string; | ||
'dlOpName': string; | ||
'category': string; | ||
'params': ({ | ||
'tfInputIndex': number; | ||
'dlParamName': string; | ||
'type': string; | ||
tfParamName?: undefined; | ||
defaultValue?: undefined; | ||
notSupported?: undefined; | ||
} | { | ||
'tfParamName': string; | ||
'dlParamName': string; | ||
'type': string; | ||
'defaultValue': boolean; | ||
'notSupported': boolean; | ||
tfInputIndex?: undefined; | ||
})[]; | ||
})[]; |
@@ -39,3 +39,3 @@ "use strict"; | ||
{ 'tfInputIndex': 1, 'dlParamName': 'indices', 'type': 'tensor' }, { | ||
'tfParamName': 'axis', | ||
'tfInputIndex': 2, | ||
'dlParamName': 'axis', | ||
@@ -72,4 +72,8 @@ 'type': 'number', | ||
'params': [ | ||
{ 'tfInputIndex': 0, 'dlParamName': 'x', 'type': 'tensor' }, | ||
{ 'tfInputIndex': 1, 'dlParamName': 'axis', 'type': 'number' } | ||
{ 'tfInputIndex': 0, 'dlParamName': 'x', 'type': 'tensor' }, { | ||
'tfInputIndex': 1, | ||
'dlParamName': 'dims', | ||
'type': 'bool', | ||
'notSupported': true | ||
} | ||
] | ||
@@ -83,3 +87,3 @@ }, | ||
{ 'tfInputIndex': 0, 'dlParamName': 'x', 'type': 'tensor' }, | ||
{ 'tfInputIndex': 1, 'dlParamName': 'axis', 'type': 'number' } | ||
{ 'tfInputIndex': 1, 'dlParamName': 'axis', 'type': 'number[]' } | ||
] | ||
@@ -224,4 +228,40 @@ }, | ||
] | ||
}, | ||
{ | ||
'tfOpName': 'ScatterNd', | ||
'dlOpName': 'scatterNd', | ||
'category': 'slice_join', | ||
'params': [ | ||
{ 'tfInputIndex': 0, 'dlParamName': 'indices', 'type': 'tensor' }, | ||
{ 'tfInputIndex': 1, 'dlParamName': 'values', 'type': 'tensor' }, | ||
{ 'tfInputIndex': 2, 'dlParamName': 'shape', 'type': 'number[]' } | ||
] | ||
}, | ||
{ | ||
'tfOpName': 'GatherNd', | ||
'dlOpName': 'gatherNd', | ||
'category': 'slice_join', | ||
'params': [ | ||
{ 'tfInputIndex': 0, 'dlParamName': 'x', 'type': 'tensor' }, | ||
{ 'tfInputIndex': 1, 'dlParamName': 'indices', 'type': 'tensor' } | ||
] | ||
}, | ||
{ | ||
'tfOpName': 'SparseToDense', | ||
'dlOpName': 'sparseToDense', | ||
'category': 'slice_join', | ||
'params': [ | ||
{ 'tfInputIndex': 0, 'dlParamName': 'sparseIndices', 'type': 'tensor' }, | ||
{ 'tfInputIndex': 1, 'dlParamName': 'outputShape', 'type': 'number[]' }, | ||
{ 'tfInputIndex': 2, 'dlParamName': 'sparseValues', 'type': 'tensor' }, | ||
{ 'tfInputIndex': 3, 'dlParamName': 'defaultValue', 'type': 'tensor' }, { | ||
'tfParamName': 'validate_indices', | ||
'dlParamName': 'validateIndices', | ||
'type': 'bool', | ||
'defaultValue': false, | ||
'notSupported': true | ||
} | ||
] | ||
} | ||
]; | ||
//# sourceMappingURL=slice_join.js.map |
@@ -1,2 +0,2 @@ | ||
declare const version = "0.6.5"; | ||
declare const version = "0.6.6"; | ||
export { version }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var version = '0.6.5'; | ||
var version = '0.6.6'; | ||
exports.version = version; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@tensorflow/tfjs-converter", | ||
"version": "0.6.5", | ||
"version": "0.6.6", | ||
"description": "Tensorflow model converter for javascript", | ||
@@ -17,6 +17,6 @@ "main": "dist/src/index.js", | ||
"peerDependencies": { | ||
"@tensorflow/tfjs-core": "~0.13.8" | ||
"@tensorflow/tfjs-core": "0.13.10" | ||
}, | ||
"devDependencies": { | ||
"@tensorflow/tfjs-core": "~0.13.8", | ||
"@tensorflow/tfjs-core": "0.13.10", | ||
"@types/jasmine": "~2.8.6", | ||
@@ -23,0 +23,0 @@ "@types/node-fetch": "1.6.9", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2804620
17396