@tensorflow/tfjs-converter
Advanced tools
Comparing version 0.5.1 to 0.5.2
import { DataType, Tensor } from '@tensorflow/tfjs-core'; | ||
import { TensorArray } from '../executor/tensor_array'; | ||
export declare type NamedTensorMap = { | ||
@@ -8,2 +9,5 @@ [key: string]: Tensor; | ||
}; | ||
export declare type TensorArrayMap = { | ||
[key: number]: TensorArray; | ||
}; | ||
export interface TensorInfo { | ||
@@ -10,0 +14,0 @@ name: string; |
import { Tensor } from '@tensorflow/tfjs-core'; | ||
import { NamedTensorsMap } from '../data/types'; | ||
import { NamedTensorsMap, TensorArrayMap } from '../data/types'; | ||
import { TensorArray } from './tensor_array'; | ||
export interface ExecutionContextInfo { | ||
@@ -9,3 +10,4 @@ id: number; | ||
export declare class ExecutionContext { | ||
weightMap: NamedTensorsMap; | ||
readonly weightMap: NamedTensorsMap; | ||
readonly tensorArrayMap: TensorArrayMap; | ||
private rootContext; | ||
@@ -15,3 +17,3 @@ private contexts; | ||
private _currentContextIds; | ||
constructor(weightMap: NamedTensorsMap); | ||
constructor(weightMap: NamedTensorsMap, tensorArrayMap: TensorArrayMap); | ||
private newFrame(id, frameName); | ||
@@ -27,2 +29,4 @@ currentContext: ExecutionContextInfo[]; | ||
getWeight(name: string): Tensor[]; | ||
addTensorArray(tensorArray: TensorArray): void; | ||
getTensorArray(id: number): TensorArray; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ExecutionContext = (function () { | ||
function ExecutionContext(weightMap) { | ||
function ExecutionContext(weightMap, tensorArrayMap) { | ||
this.weightMap = weightMap; | ||
this.tensorArrayMap = tensorArrayMap; | ||
this.rootContext = { id: 0, frameName: '', iterationId: 0 }; | ||
@@ -94,2 +95,8 @@ this.contexts = [this.rootContext]; | ||
}; | ||
ExecutionContext.prototype.addTensorArray = function (tensorArray) { | ||
this.tensorArrayMap[tensorArray.id] = tensorArray; | ||
}; | ||
ExecutionContext.prototype.getTensorArray = function (id) { | ||
return this.tensorArrayMap[id]; | ||
}; | ||
return ExecutionContext; | ||
@@ -96,0 +103,0 @@ }()); |
import * as tfc from '@tensorflow/tfjs-core'; | ||
import { TensorInfo } from '../data/types'; | ||
import { NamedTensorsMap, TensorInfo } from '../data/types'; | ||
export declare class FrozenModel implements tfc.InferenceModel { | ||
@@ -16,2 +16,3 @@ private modelUrl; | ||
readonly outputs: TensorInfo[]; | ||
readonly weights: NamedTensorsMap; | ||
constructor(modelUrl: string, weightManifestUrl: string, requestOption?: RequestInit); | ||
@@ -18,0 +19,0 @@ getPathPrefix(): string; |
@@ -86,2 +86,9 @@ "use strict"; | ||
}); | ||
Object.defineProperty(FrozenModel.prototype, "weights", { | ||
get: function () { | ||
return this.executor.weightMap; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
FrozenModel.prototype.getPathPrefix = function () { | ||
@@ -88,0 +95,0 @@ var url = Url.parse(this.weightManifestUrl); |
@@ -146,4 +146,5 @@ "use strict"; | ||
this.checkInputShapeAndType(inputs); | ||
var tensorArrayMap = {}; | ||
var result = tfjs_core_1.tidy(function () { | ||
var context = new execution_context_1.ExecutionContext(_this._weightMap); | ||
var context = new execution_context_1.ExecutionContext(_this._weightMap, tensorArrayMap); | ||
var tensors = _this.compiledOrder.reduce(function (map, node) { | ||
@@ -160,3 +161,3 @@ map[node.name] = operation_executor_1.executeOp(node, map, context); | ||
var _this = this; | ||
var context, tensors, results, outputIds, inputIdArray, inputIds; | ||
var tensorArrayMap, context, tensors, results, outputIds, inputIdArray, inputIds; | ||
return __generator(this, function (_a) { | ||
@@ -167,3 +168,4 @@ switch (_a.label) { | ||
this.checkInputShapeAndType(inputs); | ||
context = new execution_context_1.ExecutionContext(this._weightMap); | ||
tensorArrayMap = {}; | ||
context = new execution_context_1.ExecutionContext(this._weightMap, tensorArrayMap); | ||
return [4, this.executeWithControlFlow(inputs, context)]; | ||
@@ -193,3 +195,3 @@ case 1: | ||
return __awaiter(this, void 0, void 0, function () { | ||
var stack, tensorMap, added, item, tensors, nodeName, _a, _b; | ||
var stack, tensorMap, added, item, nodeName, tensors, _a, _b; | ||
return __generator(this, function (_c) { | ||
@@ -208,4 +210,11 @@ switch (_c.label) { | ||
context.currentContext = item.contexts; | ||
nodeName = ''; | ||
if (item.node.op === 'enter' && | ||
utils_1.getParamValue('isConstant', item.node, tensorMap, context)) { | ||
nodeName = utils_1.getNodeNameAndIndex(item.node.name, context)[0]; | ||
} | ||
tensors = operation_executor_1.executeOp(item.node, tensorMap, context); | ||
nodeName = utils_1.getNodeNameAndIndex(item.node.name, context)[0]; | ||
if (!nodeName) { | ||
nodeName = utils_1.getNodeNameAndIndex(item.node.name, context)[0]; | ||
} | ||
_a = tensorMap; | ||
@@ -212,0 +221,0 @@ _b = nodeName; |
@@ -16,4 +16,6 @@ import { DataType, Tensor } from '@tensorflow/tfjs-core'; | ||
readonly clearAfterRead: boolean; | ||
private static nextId; | ||
private tensors; | ||
private closed_; | ||
readonly id: number; | ||
constructor(name: string, dtype: DataType, maxSize: number, elementShape: number[], identicalElementShapes: boolean, dynamicSize: boolean, clearAfterRead: boolean); | ||
@@ -20,0 +22,0 @@ readonly closed: boolean; |
@@ -15,2 +15,3 @@ "use strict"; | ||
this.closed_ = false; | ||
this.id = TensorArray.nextId++; | ||
} | ||
@@ -65,2 +66,5 @@ Object.defineProperty(TensorArray.prototype, "closed", { | ||
} | ||
if (this.size() === 0 && this.elementShape.length === 0) { | ||
this.elementShape = tensor.shape; | ||
} | ||
tfjs_core_1.util.assertShapesMatch(this.elementShape, tensor.shape, "TensorArray " + this.name + ": Could not write to TensorArray index " + index + "."); | ||
@@ -165,2 +169,3 @@ if (t && t.read) { | ||
}; | ||
TensorArray.nextId = 0; | ||
return TensorArray; | ||
@@ -167,0 +172,0 @@ }()); |
@@ -38,6 +38,8 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tfjs_core_1 = require("@tensorflow/tfjs-core"); | ||
var tensor_array_1 = require("../../executor/tensor_array"); | ||
var utils_1 = require("./utils"); | ||
function executeOp(node, tensorMap, context) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, pred, data_1, inputName, frameId, data, tensor, input; | ||
var _a, pred, data_1, inputName, frameId, data, tensor, input, size, dtype, elementShape, dynamicSize, clearAfterRead, identicalElementShapes, name_1, tensorArray, id, index, writeTensor, writeTensorArray, readId, readIndex, readTensorArray, gatherId, gatherIndices, gatherDtype, gatherTensorArray, scatterId, scatterIndices, scatterTensor, scatterTensorArray, concatId, concatTensorArray, concatDtype, splitId, splitTensor, lengths, splitTensorArray, sizeId, sizeTensorArray, closeId, closeTensorArray; | ||
return __generator(this, function (_b) { | ||
@@ -54,4 +56,13 @@ switch (_b.label) { | ||
case 'nextIteration': return [3, 7]; | ||
case 'tensorArray': return [3, 8]; | ||
case 'tensorArrayWrite': return [3, 9]; | ||
case 'tensorArrayRead': return [3, 10]; | ||
case 'tensorArrayGather': return [3, 11]; | ||
case 'tensorArrayScatter': return [3, 12]; | ||
case 'tensorArrayConcat': return [3, 13]; | ||
case 'tensorArraySplit': return [3, 14]; | ||
case 'tensorArraySize': return [3, 15]; | ||
case 'tensorArrayClose': return [3, 16]; | ||
} | ||
return [3, 8]; | ||
return [3, 17]; | ||
case 1: return [2, [utils_1.getParamValue('pred', node, tensorMap, context)]]; | ||
@@ -79,3 +90,60 @@ case 2: | ||
return [2, [input]]; | ||
case 8: throw TypeError("Node type " + node.op + " is not implemented"); | ||
case 8: | ||
size = utils_1.getParamValue('size', node, tensorMap, context); | ||
dtype = utils_1.getParamValue('dtype', node, tensorMap, context); | ||
elementShape = utils_1.getParamValue('elementShape', node, tensorMap, context); | ||
dynamicSize = utils_1.getParamValue('dynamicSize', node, tensorMap, context); | ||
clearAfterRead = utils_1.getParamValue('clearAfterRead', node, tensorMap, context); | ||
identicalElementShapes = utils_1.getParamValue('identicalElementShapes', node, tensorMap, context); | ||
name_1 = utils_1.getParamValue('name', node, tensorMap, context); | ||
tensorArray = new tensor_array_1.TensorArray(name_1, dtype, size, elementShape, identicalElementShapes, dynamicSize, clearAfterRead); | ||
context.addTensorArray(tensorArray); | ||
return [2, [tfjs_core_1.scalar(tensorArray.id), tfjs_core_1.scalar(1.0)]]; | ||
case 9: | ||
id = utils_1.getParamValue('tensorArrayId', node, tensorMap, context); | ||
index = utils_1.getParamValue('index', node, tensorMap, context); | ||
writeTensor = utils_1.getParamValue('tensor', node, tensorMap, context); | ||
writeTensorArray = context.getTensorArray(id); | ||
writeTensorArray.write(index, writeTensor); | ||
return [2, [tfjs_core_1.scalar(1.0)]]; | ||
case 10: | ||
readId = utils_1.getParamValue('tensorArrayId', node, tensorMap, context); | ||
readIndex = utils_1.getParamValue('index', node, tensorMap, context); | ||
readTensorArray = context.getTensorArray(readId); | ||
return [2, [readTensorArray.read(readIndex)]]; | ||
case 11: | ||
gatherId = utils_1.getParamValue('tensorArrayId', node, tensorMap, context); | ||
gatherIndices = utils_1.getParamValue('indices', node, tensorMap, context); | ||
gatherDtype = utils_1.getParamValue('dtype', node, tensorMap, context); | ||
gatherTensorArray = context.getTensorArray(gatherId); | ||
return [2, [gatherTensorArray.gather(gatherIndices, gatherDtype)]]; | ||
case 12: | ||
scatterId = utils_1.getParamValue('tensorArrayId', node, tensorMap, context); | ||
scatterIndices = utils_1.getParamValue('indices', node, tensorMap, context); | ||
scatterTensor = utils_1.getParamValue('tensor', node, tensorMap, context); | ||
scatterTensorArray = context.getTensorArray(scatterId); | ||
scatterTensorArray.scatter(scatterIndices, scatterTensor); | ||
return [2, [tfjs_core_1.scalar(1.0)]]; | ||
case 13: | ||
concatId = utils_1.getParamValue('tensorArrayId', node, tensorMap, context); | ||
concatTensorArray = context.getTensorArray(concatId); | ||
concatDtype = utils_1.getParamValue('dtype', node, tensorMap, context); | ||
return [2, [concatTensorArray.concat(concatDtype)]]; | ||
case 14: | ||
splitId = utils_1.getParamValue('tensorArrayId', node, tensorMap, context); | ||
splitTensor = utils_1.getParamValue('tensor', node, tensorMap, context); | ||
lengths = utils_1.getParamValue('lengths', node, tensorMap, context); | ||
splitTensorArray = context.getTensorArray(splitId); | ||
splitTensorArray.split(lengths, splitTensor); | ||
return [2, [tfjs_core_1.scalar(1.0)]]; | ||
case 15: | ||
sizeId = utils_1.getParamValue('tensorArrayId', node, tensorMap, context); | ||
sizeTensorArray = context.getTensorArray(sizeId); | ||
return [2, [tfjs_core_1.scalar(sizeTensorArray.size(), 'int32')]]; | ||
case 16: | ||
closeId = utils_1.getParamValue('tensorArrayId', node, tensorMap, context); | ||
closeTensorArray = context.getTensorArray(closeId); | ||
closeTensorArray.clearAndClose(); | ||
return [2, []]; | ||
case 17: throw TypeError("Node type " + node.op + " is not implemented"); | ||
} | ||
@@ -82,0 +150,0 @@ }); |
@@ -34,3 +34,11 @@ "use strict"; | ||
var endMask = utils_1.getParamValue('endMask', node, tensorMap, context); | ||
return [tfc.stridedSlice(utils_1.getParamValue('x', node, tensorMap, context), begin, end, strides, beginMask, endMask)]; | ||
var tensor = utils_1.getParamValue('x', node, tensorMap, context); | ||
if (begin.length === 1 && tensor.shape.length > 1) { | ||
for (var i = 1; i < tensor.shape.length; i++) { | ||
begin.push(0); | ||
end.push(tensor.shape[i]); | ||
strides.push(strides[0]); | ||
} | ||
} | ||
return [tfc.stridedSlice(tensor, begin, end, strides, beginMask, endMask)]; | ||
} | ||
@@ -37,0 +45,0 @@ case 'stack': { |
@@ -107,3 +107,259 @@ [ | ||
] | ||
}, | ||
{ | ||
"tfOpName": "TensorArrayV3", | ||
"dlOpName": "tensorArray", | ||
"category": "control", | ||
"params": [ | ||
{ | ||
"tfInputIndex": 0, | ||
"dlParamName": "size", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfParamName": "dtype", | ||
"dlParamName": "dtype", | ||
"type": "dtype" | ||
}, | ||
{ | ||
"tfParamName": "element_shape", | ||
"dlParamName": "elementShape", | ||
"type": "shape" | ||
}, | ||
{ | ||
"tfParamName": "dynamic_size", | ||
"dlParamName": "dynamicSize", | ||
"type": "bool" | ||
}, | ||
{ | ||
"tfParamName": "clear_after_read", | ||
"dlParamName": "clearAfterRead", | ||
"type": "bool" | ||
}, | ||
{ | ||
"tfParamName": "identical_element_shapes", | ||
"dlParamName": "identicalElementShapes", | ||
"type": "bool" | ||
}, | ||
{ | ||
"tfParamName": "tensor_array_name", | ||
"dlParamName": "name", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"tfOpName": "TensorArrayWriteV3", | ||
"dlOpName": "tensorArrayWrite", | ||
"category": "control", | ||
"params": [ | ||
{ | ||
"tfInputIndex": 0, | ||
"dlParamName": "tensorArrayId", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfInputIndex": 1, | ||
"dlParamName": "index", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfInputIndex": 2, | ||
"dlParamName": "tensor", | ||
"type": "tensor" | ||
}, | ||
{ | ||
"tfInputIndex": 3, | ||
"dlParamName": "flowIn", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfParamName": "T", | ||
"dlParamName": "dtype", | ||
"type": "dtype", | ||
"notSupported": true | ||
} | ||
] | ||
}, | ||
{ | ||
"tfOpName": "TensorArrayReadV3", | ||
"dlOpName": "tensorArrayRead", | ||
"category": "control", | ||
"params": [ | ||
{ | ||
"tfInputIndex": 0, | ||
"dlParamName": "tensorArrayId", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfInputIndex": 1, | ||
"dlParamName": "index", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfInputIndex": 2, | ||
"dlParamName": "flowIn", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfParamName": "dtype", | ||
"dlParamName": "dtype", | ||
"type": "dtype", | ||
"notSupported": true | ||
} | ||
] | ||
}, | ||
{ | ||
"tfOpName": "TensorArrayGatherV3", | ||
"dlOpName": "tensorArrayGather", | ||
"category": "control", | ||
"params": [ | ||
{ | ||
"tfInputIndex": 0, | ||
"dlParamName": "tensorArrayId", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfInputIndex": 1, | ||
"dlParamName": "indices", | ||
"type": "number[]" | ||
}, | ||
{ | ||
"tfInputIndex": 2, | ||
"dlParamName": "flowIn", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfParamName": "dtype", | ||
"dlParamName": "dtype", | ||
"type": "dtype" | ||
}, | ||
{ | ||
"tfParamName": "element_shape", | ||
"dlParamName": "elementShape", | ||
"type": "shape" | ||
} | ||
] | ||
}, | ||
{ | ||
"tfOpName": "TensorArrayScatterV3", | ||
"dlOpName": "tensorArrayScatter", | ||
"category": "control", | ||
"params": [ | ||
{ | ||
"tfInputIndex": 0, | ||
"dlParamName": "tensorArrayId", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfInputIndex": 1, | ||
"dlParamName": "indices", | ||
"type": "number[]" | ||
}, | ||
{ | ||
"tfInputIndex": 2, | ||
"dlParamName": "tensor", | ||
"type": "number[]" | ||
}, | ||
{ | ||
"tfInputIndex": 3, | ||
"dlParamName": "flowIn", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfParamName": "T", | ||
"dlParamName": "dtype", | ||
"type": "dtype" | ||
} | ||
] | ||
}, | ||
{ | ||
"tfOpName": "TensorArrayConcatV3", | ||
"dlOpName": "tensorArrayConcat", | ||
"category": "control", | ||
"params": [ | ||
{ | ||
"tfInputIndex": 0, | ||
"dlParamName": "tensorArrayId", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfInputIndex": 1, | ||
"dlParamName": "flowIn", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfParamName": "dtype", | ||
"dlParamName": "dtype", | ||
"type": "dtype" | ||
}, | ||
{ | ||
"tfParamName": "element_shape_except0", | ||
"dlParamName": "elementShapeExcept0", | ||
"type": "shape", | ||
"notSupported": true | ||
} | ||
] | ||
}, | ||
{ | ||
"tfOpName": "TensorArraySplitV3", | ||
"dlOpName": "tensorArraySplit", | ||
"category": "control", | ||
"params": [ | ||
{ | ||
"tfInputIndex": 0, | ||
"dlParamName": "tensorArrayId", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfInputIndex": 1, | ||
"dlParamName": "tensor", | ||
"type": "tensor" | ||
}, | ||
{ | ||
"tfInputIndex": 2, | ||
"dlParamName": "lengths", | ||
"type": "number[]" | ||
}, | ||
{ | ||
"tfInputIndex": 3, | ||
"dlParamName": "flowIn", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfParamName": "T", | ||
"dlParamName": "dtype", | ||
"type": "dtype" | ||
} | ||
] | ||
}, | ||
{ | ||
"tfOpName": "TensorArraySizeV3", | ||
"dlOpName": "tensorArraySize", | ||
"category": "control", | ||
"params": [ | ||
{ | ||
"tfInputIndex": 0, | ||
"dlParamName": "tensorArrayId", | ||
"type": "number" | ||
}, | ||
{ | ||
"tfInputIndex": 1, | ||
"dlParamName": "flowIn", | ||
"type": "number" | ||
} | ||
] | ||
}, | ||
{ | ||
"tfOpName": "TensorArrayCloseV3", | ||
"dlOpName": "tensorArrayClose", | ||
"category": "control", | ||
"params": [ | ||
{ | ||
"tfInputIndex": 0, | ||
"dlParamName": "tensorArrayId", | ||
"type": "number" | ||
} | ||
] | ||
} | ||
] |
@@ -1,2 +0,2 @@ | ||
declare const version = "0.5.1"; | ||
declare const version = "0.5.2"; | ||
export { version }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var version = '0.5.1'; | ||
var version = '0.5.2'; | ||
exports.version = version; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@tensorflow/tfjs-converter", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Tensorflow model converter for javascript", | ||
@@ -17,6 +17,6 @@ "main": "dist/index.js", | ||
"peerDependencies": { | ||
"@tensorflow/tfjs-core": "~0.12.0" | ||
"@tensorflow/tfjs-core": "~0.12.4" | ||
}, | ||
"devDependencies": { | ||
"@tensorflow/tfjs-core": "~0.12.0", | ||
"@tensorflow/tfjs-core": "~0.12.4", | ||
"@types/jasmine": "~2.8.6", | ||
@@ -23,0 +23,0 @@ "@types/node-fetch": "1.6.9", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
939254
18975