Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tensorflow/tfjs-converter

Package Overview
Dependencies
Maintainers
10
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tensorflow/tfjs-converter - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

3

.vscode/settings.json

@@ -25,3 +25,4 @@ // Place your settings in this file to overwrite default and user settings.

"typescript.tsdk": "node_modules/typescript/lib",
"clang-format.executable": "${workspaceRoot}/node_modules/.bin/clang-format"
"clang-format.executable": "${workspaceRoot}/node_modules/.bin/clang-format",
"python.formatting.provider": "yapf"
}

@@ -1,2 +0,2 @@

import * as tf from '@tensorflow/tfjs-core';
import * as tfc from '@tensorflow/tfjs-core';
import { NamedTensorMap } from '../data/index';

@@ -16,5 +16,5 @@ export declare class TFModel {

load(): Promise<boolean>;
eval(inputs: NamedTensorMap, outputs?: string | string[]): tf.Tensor | NamedTensorMap;
eval(inputs: NamedTensorMap, outputs?: string | string[]): tfc.Tensor | NamedTensorMap;
private convertTensorMapToTensorsMap(map);
dispose(): void;
}

@@ -54,3 +54,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var tf = require("@tensorflow/tfjs-core");
var tfc = require("@tensorflow/tfjs-core");
var index_1 = require("../data/index");

@@ -145,3 +145,3 @@ var index_2 = require("../operations/index");

this.version = graph.versions.producer + "." + graph.versions.minConsumer;
return [4, tf.loadWeights(this.weightManifest, this.pathPrefix)];
return [4, tfc.loadWeights(this.weightManifest, this.pathPrefix)];
case 2:

@@ -148,0 +148,0 @@ weightMap = _b.sent();

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tf = require("@tensorflow/tfjs-core");
var tfc = require("@tensorflow/tfjs-core");
var utils_1 = require("./utils");

@@ -8,20 +8,20 @@ exports.executeOp = function (node, tensorMap) {

case 'add': {
return [tf.add(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.add(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}
case 'mul':
return [tf.mul(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.mul(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
case 'div': {
return [tf.div(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.div(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}
case 'sub': {
return [tf.sub(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.sub(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}
case 'minimum': {
return [tf.minimum(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.minimum(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}
case 'maximum': {
return [tf.maximum(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.maximum(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}
case 'pow': {
return [tf.pow(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.pow(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}

@@ -28,0 +28,0 @@ default:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tf = require("@tensorflow/tfjs-core");
var tfc = require("@tensorflow/tfjs-core");
var utils_1 = require("./utils");

@@ -8,49 +8,49 @@ exports.executeOp = function (node, tensorMap) {

case 'abs':
return [tf.abs(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.abs(utils_1.getParamValue('x', node, tensorMap))];
case 'acos':
return [tf.acos(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.acos(utils_1.getParamValue('x', node, tensorMap))];
case 'asin':
return [tf.asin(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.asin(utils_1.getParamValue('x', node, tensorMap))];
case 'atan':
return [tf.atan(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.atan(utils_1.getParamValue('x', node, tensorMap))];
case 'ceil':
return [tf.ceil(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.ceil(utils_1.getParamValue('x', node, tensorMap))];
case 'cos':
return [tf.cos(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.cos(utils_1.getParamValue('x', node, tensorMap))];
case 'cosh':
return [tf.cosh(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.cosh(utils_1.getParamValue('x', node, tensorMap))];
case 'elu':
return [tf.elu(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.elu(utils_1.getParamValue('x', node, tensorMap))];
case 'exp':
return [tf.exp(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.exp(utils_1.getParamValue('x', node, tensorMap))];
case 'floor':
return [tf.floor(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.floor(utils_1.getParamValue('x', node, tensorMap))];
case 'log':
return [tf.log(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.log(utils_1.getParamValue('x', node, tensorMap))];
case 'relu':
return [tf.relu(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.relu(utils_1.getParamValue('x', node, tensorMap))];
case 'selu':
return [tf.selu(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.selu(utils_1.getParamValue('x', node, tensorMap))];
case 'sigmoid':
return [tf.sigmoid(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.sigmoid(utils_1.getParamValue('x', node, tensorMap))];
case 'sin':
return [tf.sin(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.sin(utils_1.getParamValue('x', node, tensorMap))];
case 'sinh': {
return [tf.sinh(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.sinh(utils_1.getParamValue('x', node, tensorMap))];
}
case 'sqrt': {
return [tf.sqrt(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.sqrt(utils_1.getParamValue('x', node, tensorMap))];
}
case 'square': {
return [tf.square(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.square(utils_1.getParamValue('x', node, tensorMap))];
}
case 'tanh': {
return [tf.tanh(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.tanh(utils_1.getParamValue('x', node, tensorMap))];
}
case 'tan':
return [tf.tan(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.tan(utils_1.getParamValue('x', node, tensorMap))];
case 'clipByValue':
return [tf.clipByValue(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('clipValueMin', node, tensorMap), utils_1.getParamValue('clipValueMax', node, tensorMap))];
return [tfc.clipByValue(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('clipValueMin', node, tensorMap), utils_1.getParamValue('clipValueMax', node, tensorMap))];
case 'rsqrt':
return [tf.div(tf.scalar(1.0, 'float32'), tf.sqrt(utils_1.getTensor(node.inputNames[0], tensorMap)))];
return [tfc.div(tfc.scalar(1.0, 'float32'), tfc.sqrt(utils_1.getTensor(node.inputNames[0], tensorMap)))];
default:

@@ -57,0 +57,0 @@ throw TypeError("Node type " + node.op + " is not implemented");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tf = require("@tensorflow/tfjs-core");
var tfc = require("@tensorflow/tfjs-core");
var utils_1 = require("./utils");

@@ -10,3 +10,6 @@ exports.executeOp = function (node, tensorMap) {

var pad = utils_1.getParamValue('pad', node, tensorMap);
return [tf.conv1d(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('filter', node, tensorMap), stride, pad)];
var dataFormat = utils_1.getParamValue('dataFormat', node, tensorMap)
.toUpperCase();
var dilation = utils_1.getParamValue('dilation', node, tensorMap);
return [tfc.conv1d(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('filter', node, tensorMap), stride, pad, dataFormat, dilation)];
}

@@ -16,3 +19,6 @@ case 'conv2d': {

var pad = utils_1.getParamValue('pad', node, tensorMap);
return [tf.conv2d(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('filter', node, tensorMap), [stride[1], stride[2]], pad)];
var dataFormat = utils_1.getParamValue('dataFormat', node, tensorMap)
.toUpperCase();
var dilations = utils_1.getParamValue('dilations', node, tensorMap);
return [tfc.conv2d(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('filter', node, tensorMap), [stride[1], stride[2]], pad, dataFormat, [dilations[0], dilations[1]])];
}

@@ -23,3 +29,3 @@ case 'conv2dTranspose': {

var pad = utils_1.getParamValue('pad', node, tensorMap);
return [tf.conv2dTranspose(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('filter', node, tensorMap), shape, [stride[1], stride[2]], pad)];
return [tfc.conv2dTranspose(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('filter', node, tensorMap), shape, [stride[1], stride[2]], pad)];
}

@@ -29,4 +35,6 @@ case 'depthwiseConv2d': {

var pad = utils_1.getParamValue('pad', node, tensorMap);
var rates = utils_1.getParamValue('rates', node, tensorMap);
return [tf.depthwiseConv2d(utils_1.getParamValue('input', node, tensorMap), utils_1.getParamValue('filter', node, tensorMap), [stride[1], stride[2]], pad, [rates[0], rates[1]])];
var dilations = utils_1.getParamValue('dilations', node, tensorMap);
var dataFormat = utils_1.getParamValue('dataFormat', node, tensorMap)
.toUpperCase();
return [tfc.depthwiseConv2d(utils_1.getParamValue('input', node, tensorMap), utils_1.getParamValue('filter', node, tensorMap), [stride[1], stride[2]], pad, dataFormat, [dilations[0], dilations[1]])];
}

@@ -37,3 +45,3 @@ case 'avgPool': {

var kernelSize = utils_1.getParamValue('kernelSize', node, tensorMap);
return [tf.avgPool(utils_1.getParamValue('x', node, tensorMap), [kernelSize[1], kernelSize[2]], [stride[1], stride[2]], pad)];
return [tfc.avgPool(utils_1.getParamValue('x', node, tensorMap), [kernelSize[1], kernelSize[2]], [stride[1], stride[2]], pad)];
}

@@ -44,3 +52,3 @@ case 'maxPool': {

var kernelSize = utils_1.getParamValue('kernelSize', node, tensorMap);
return [tf.maxPool(utils_1.getParamValue('x', node, tensorMap), [kernelSize[1], kernelSize[2]], [stride[1], stride[2]], pad)];
return [tfc.maxPool(utils_1.getParamValue('x', node, tensorMap), [kernelSize[1], kernelSize[2]], [stride[1], stride[2]], pad)];
}

@@ -47,0 +55,0 @@ default:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tf = require("@tensorflow/tfjs-core");
var tfc = require("@tensorflow/tfjs-core");
var utils_1 = require("./utils");

@@ -10,3 +10,3 @@ exports.executeOp = function (node, tensorMap) {

var value = utils_1.getParamValue('value', node, tensorMap);
return [tf.fill(shape, value)];
return [tfc.fill(shape, value)];
}

@@ -17,3 +17,3 @@ case 'linspace': {

var num = utils_1.getParamValue('num', node, tensorMap);
return [tf.linspace(start, stop_1, num)];
return [tfc.linspace(start, stop_1, num)];
}

@@ -25,12 +25,12 @@ case 'oneHot': {

var offValue = utils_1.getParamValue('offValue', node, tensorMap);
return [tf.oneHot(indices, depth, onValue, offValue)];
return [tfc.oneHot(indices, depth, onValue, offValue)];
}
case 'ones': {
return [tf.ones(utils_1.getParamValue('shape', node, tensorMap), utils_1.getParamValue('dtype', node, tensorMap))];
return [tfc.ones(utils_1.getParamValue('shape', node, tensorMap), utils_1.getParamValue('dtype', node, tensorMap))];
}
case 'onesLike': {
return [tf.onesLike(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.onesLike(utils_1.getParamValue('x', node, tensorMap))];
}
case 'randomUniform': {
return [tf.randomUniform(utils_1.getParamValue('shape', node, tensorMap), utils_1.getParamValue('minval', node, tensorMap), utils_1.getParamValue('maxval', node, tensorMap), utils_1.getParamValue('dtype', node, tensorMap))];
return [tfc.randomUniform(utils_1.getParamValue('shape', node, tensorMap), utils_1.getParamValue('minval', node, tensorMap), utils_1.getParamValue('maxval', node, tensorMap), utils_1.getParamValue('dtype', node, tensorMap))];
}

@@ -41,3 +41,3 @@ case 'range': {

var step = utils_1.getParamValue('step', node, tensorMap);
return [tf.range(start, stop_2, step, utils_1.getParamValue('dtype', node, tensorMap))];
return [tfc.range(start, stop_2, step, utils_1.getParamValue('dtype', node, tensorMap))];
}

@@ -49,9 +49,9 @@ case 'truncatedNormal': {

var seed = utils_1.getParamValue('seed', node, tensorMap);
return [tf.truncatedNormal(shape, mean, stdDev, utils_1.getParamValue('dtype', node, tensorMap), seed)];
return [tfc.truncatedNormal(shape, mean, stdDev, utils_1.getParamValue('dtype', node, tensorMap), seed)];
}
case 'zeros': {
return [tf.zeros(utils_1.getParamValue('shape', node, tensorMap), utils_1.getParamValue('dtype', node, tensorMap))];
return [tfc.zeros(utils_1.getParamValue('shape', node, tensorMap), utils_1.getParamValue('dtype', node, tensorMap))];
}
case 'zerosLike': {
return [tf.zerosLike(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.zerosLike(utils_1.getParamValue('x', node, tensorMap))];
}

@@ -58,0 +58,0 @@ default:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tf = require("@tensorflow/tfjs-core");
var tfc = require("@tensorflow/tfjs-core");
var utils_1 = require("./utils");

@@ -16,3 +16,3 @@ exports.executeOp = function (node, tensorMap) {

case 'shape':
return [tf.tensor1d(utils_1.getParamValue('x', node, tensorMap).shape, 'int32')];
return [tfc.tensor1d(utils_1.getParamValue('x', node, tensorMap).shape, 'int32')];
default:

@@ -19,0 +19,0 @@ throw TypeError("Node type " + node.op + " is not implemented");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tf = require("@tensorflow/tfjs-core");
var tfc = require("@tensorflow/tfjs-core");
var utils_1 = require("./utils");

@@ -8,27 +8,27 @@ exports.executeOp = function (node, tensorMap) {

case 'equal': {
return [tf.equal(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.equal(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}
case 'greater': {
return [tf.greater(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.greater(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}
case 'greaterEqual': {
return [tf.greaterEqual(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.greaterEqual(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}
case 'less': {
return [tf.less(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.less(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}
case 'lessEqual': {
return [tf.lessEqual(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.lessEqual(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}
case 'logicalAnd': {
return [tf.logicalAnd(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.logicalAnd(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}
case 'logicalNot': {
return [tf.logicalNot(utils_1.getParamValue('a', node, tensorMap))];
return [tfc.logicalNot(utils_1.getParamValue('a', node, tensorMap))];
}
case 'logicalOr': {
return [tf.logicalOr(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.logicalOr(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}
case 'where': {
return [tf.where(utils_1.getParamValue('condition', node, tensorMap), utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
return [tfc.where(utils_1.getParamValue('condition', node, tensorMap), utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap))];
}

@@ -35,0 +35,0 @@ default:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tf = require("@tensorflow/tfjs-core");
var tfc = require("@tensorflow/tfjs-core");
var utils_1 = require("./utils");

@@ -8,5 +8,5 @@ exports.executeOp = function (node, tensorMap) {

case 'matMul':
return [tf.matMul(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap), utils_1.getParamValue('transposeA', node, tensorMap), utils_1.getParamValue('transposeB', node, tensorMap))];
return [tfc.matMul(utils_1.getParamValue('a', node, tensorMap), utils_1.getParamValue('b', node, tensorMap), utils_1.getParamValue('transposeA', node, tensorMap), utils_1.getParamValue('transposeB', node, tensorMap))];
case 'transpose':
return [tf.transpose(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('perm', node, tensorMap))];
return [tfc.transpose(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('perm', node, tensorMap))];
default:

@@ -13,0 +13,0 @@ throw TypeError("Node type " + node.op + " is not implemented");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tf = require("@tensorflow/tfjs-core");
var tfc = require("@tensorflow/tfjs-core");
var utils_1 = require("./utils");

@@ -8,9 +8,9 @@ exports.executeOp = function (node, tensorMap) {

case 'batchNormalization': {
return [tf.batchNormalization(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('mean', node, tensorMap), utils_1.getParamValue('variance', node, tensorMap), utils_1.getParamValue('epislon', node, tensorMap), utils_1.getParamValue('scale', node, tensorMap), utils_1.getParamValue('offset', node, tensorMap))];
return [tfc.batchNormalization(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('mean', node, tensorMap), utils_1.getParamValue('variance', node, tensorMap), utils_1.getParamValue('epislon', node, tensorMap), utils_1.getParamValue('scale', node, tensorMap), utils_1.getParamValue('offset', node, tensorMap))];
}
case 'localResponseNormalization': {
return [tf.localResponseNormalization(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('radius', node, tensorMap), utils_1.getParamValue('bias', node, tensorMap), utils_1.getParamValue('alpha', node, tensorMap), utils_1.getParamValue('beta', node, tensorMap))];
return [tfc.localResponseNormalization(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('radius', node, tensorMap), utils_1.getParamValue('bias', node, tensorMap), utils_1.getParamValue('alpha', node, tensorMap), utils_1.getParamValue('beta', node, tensorMap))];
}
case 'softmax': {
return [tf.softmax(utils_1.getParamValue('x', node, tensorMap))];
return [tfc.softmax(utils_1.getParamValue('x', node, tensorMap))];
}

@@ -17,0 +17,0 @@ default:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tf = require("@tensorflow/tfjs-core");
var tfc = require("@tensorflow/tfjs-core");
var utils_1 = require("./utils");

@@ -10,3 +10,3 @@ exports.executeOp = function (node, tensorMap) {

var keepDims = utils_1.getParamValue('keepDims', node, tensorMap);
return [tf.max(utils_1.getParamValue('x', node, tensorMap), axis, keepDims)];
return [tfc.max(utils_1.getParamValue('x', node, tensorMap), axis, keepDims)];
}

@@ -16,3 +16,3 @@ case 'mean': {

var keepDims = utils_1.getParamValue('keepDims', node, tensorMap);
return [tf.mean(utils_1.getParamValue('x', node, tensorMap), axis, keepDims)];
return [tfc.mean(utils_1.getParamValue('x', node, tensorMap), axis, keepDims)];
}

@@ -22,3 +22,3 @@ case 'min': {

var keepDims = utils_1.getParamValue('keepDims', node, tensorMap);
return [tf.min(utils_1.getParamValue('x', node, tensorMap), axis, keepDims)];
return [tfc.min(utils_1.getParamValue('x', node, tensorMap), axis, keepDims)];
}

@@ -28,11 +28,11 @@ case 'sum': {

var keepDims = utils_1.getParamValue('keepDims', node, tensorMap);
return [tf.sum(utils_1.getParamValue('x', node, tensorMap), axis, keepDims)];
return [tfc.sum(utils_1.getParamValue('x', node, tensorMap), axis, keepDims)];
}
case 'argMax': {
var axis = utils_1.getParamValue('axis', node, tensorMap);
return [tf.argMax(utils_1.getParamValue('x', node, tensorMap), axis)];
return [tfc.argMax(utils_1.getParamValue('x', node, tensorMap), axis)];
}
case 'argMin': {
var axis = utils_1.getParamValue('axis', node, tensorMap);
return [tf.argMin(utils_1.getParamValue('x', node, tensorMap), axis)];
return [tfc.argMin(utils_1.getParamValue('x', node, tensorMap), axis)];
}

@@ -39,0 +39,0 @@ default:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tf = require("@tensorflow/tfjs-core");
var tfc = require("@tensorflow/tfjs-core");
var utils_1 = require("./utils");

@@ -10,3 +10,3 @@ exports.executeOp = function (node, tensorMap) {

var inputs = utils_1.getParamValue('tensors', node, tensorMap);
return [tf.concat(inputs, axis)];
return [tfc.concat(inputs, axis)];
}

@@ -17,3 +17,3 @@ case 'gather': {

var indices = utils_1.getParamValue('indices', node, tensorMap);
return [tf.gather(input, indices, axis)];
return [tfc.gather(input, indices, axis)];
}

@@ -23,3 +23,3 @@ case 'reverse': {

var input = utils_1.getParamValue('x', node, tensorMap);
return [tf.reverse(input, axis)];
return [tfc.reverse(input, axis)];
}

@@ -29,11 +29,11 @@ case 'slice': {

var size = utils_1.getParamValue('size', node, tensorMap);
return [tf.slice(utils_1.getParamValue('x', node, tensorMap), begin, size)];
return [tfc.slice(utils_1.getParamValue('x', node, tensorMap), begin, size)];
}
case 'stack': {
var axis = utils_1.getParamValue('axis', node, tensorMap);
return [tf.stack(utils_1.getParamValue('tensors', node, tensorMap), axis)];
return [tfc.stack(utils_1.getParamValue('tensors', node, tensorMap), axis)];
}
case 'tile': {
var reps = utils_1.getParamValue('reps', node, tensorMap);
return [tf.tile(utils_1.getParamValue('x', node, tensorMap), reps)];
return [tfc.tile(utils_1.getParamValue('x', node, tensorMap), reps)];
}

@@ -40,0 +40,0 @@ default:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tf = require("@tensorflow/tfjs-core");
var tfc = require("@tensorflow/tfjs-core");
var utils_1 = require("./utils");

@@ -8,17 +8,17 @@ exports.executeOp = function (node, tensorMap) {

case 'cast': {
return [tf.cast(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('dtype', node, tensorMap))];
return [tfc.cast(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('dtype', node, tensorMap))];
}
case 'expandDims': {
var axis = node.params['axis'].value;
return [tf.expandDims(utils_1.getParamValue('x', node, tensorMap), axis)];
return [tfc.expandDims(utils_1.getParamValue('x', node, tensorMap), axis)];
}
case 'squeeze': {
var axis = node.params['axis'].value;
return [tf.squeeze(utils_1.getParamValue('x', node, tensorMap), axis)];
return [tfc.squeeze(utils_1.getParamValue('x', node, tensorMap), axis)];
}
case 'reshape': {
return [tf.reshape(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('shape', node, tensorMap))];
return [tfc.reshape(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('shape', node, tensorMap))];
}
case 'pad': {
return [tf.pad(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('padding', node, tensorMap), utils_1.getParamValue('constantValue', node, tensorMap))];
return [tfc.pad(utils_1.getParamValue('x', node, tensorMap), utils_1.getParamValue('padding', node, tensorMap), utils_1.getParamValue('constantValue', node, tensorMap))];
}

@@ -25,0 +25,0 @@ default:

@@ -1,6 +0,6 @@

import * as tf from '@tensorflow/tfjs-core';
import * as tfc from '@tensorflow/tfjs-core';
import { NamedTensorsMap } from '../../data/index';
import { Node } from '../index';
export interface OpExecutor {
(node: Node, tensorMap: NamedTensorsMap): tf.Tensor[];
(node: Node, tensorMap: NamedTensorsMap): tfc.Tensor[];
}

@@ -1,5 +0,5 @@

import * as tf from '@tensorflow/tfjs-core';
import * as tfc from '@tensorflow/tfjs-core';
import { NamedTensorsMap } from '../../data/index';
import { Node, ValueType } from '../index';
export declare function getParamValue(paramName: string, node: Node, tensorMap: NamedTensorsMap): ValueType;
export declare function getTensor(name: string, tensorMap: NamedTensorsMap): tf.Tensor;
export declare function getTensor(name: string, tensorMap: NamedTensorsMap): tfc.Tensor;

@@ -109,3 +109,3 @@ [

"type": "string",
"notSupported": true
"defaultValue": "NWC"
},

@@ -122,3 +122,3 @@ {

"type": "number",
"notSupported": true
"defaultValue": 1
}

@@ -167,3 +167,3 @@ ]

"type": "string",
"notSupported": true
"defaultValue": "NHWC"
},

@@ -173,4 +173,3 @@ {

"dlParamName": "dilations",
"type": "number[]",
"notSupported": true
"type": "number[]"
}

@@ -246,7 +245,7 @@ ]

"type": "string",
"notSupported": true
"defaultValue": "NHWC"
},
{
"tfParamName": "dilations",
"dlParamName": "rates",
"dlParamName": "dilations",
"type": "number[]"

@@ -285,7 +284,7 @@ }

"type": "string",
"notSupported": true
"defaultValue": "NHWC"
},
{
"tfParamName": "dilations",
"dlParamName": "rates",
"dlParamName": "dilations",
"type": "number[]"

@@ -292,0 +291,0 @@ }

@@ -1,4 +0,4 @@

import * as tf from '@tensorflow/tfjs-core';
import * as tfc from '@tensorflow/tfjs-core';
import { NamedTensorsMap } from '../data/index';
import { Node } from './index';
export declare function executeOp(node: Node, tensorMap: NamedTensorsMap): tf.Tensor[];
export declare function executeOp(node: Node, tensorMap: NamedTensorsMap): tfc.Tensor[];

@@ -1,2 +0,2 @@

declare const version = "0.0.2";
declare const version = "0.0.3";
export { version };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var version = '0.0.2';
var version = '0.0.3';
exports.version = version;
//# sourceMappingURL=version.js.map
{
"name": "@tensorflow/tfjs-converter",
"version": "0.0.2",
"version": "0.0.3",
"description": "Tensorflow model converter for javascript",

@@ -15,6 +15,6 @@ "main": "dist/index.js",

"peerDependencies": {
"@tensorflow/tfjs-core": "0.0.1"
"@tensorflow/tfjs-core": "0.0.2"
},
"devDependencies": {
"@tensorflow/tfjs-core": "0.0.1",
"@tensorflow/tfjs-core": "0.0.2",
"@types/jasmine": "~2.8.6",

@@ -50,3 +50,2 @@ "@types/seedrandom": "~2.4.27",

"scripts": {
"prep": "yarn && mkdirp dist",
"build": "tsc && copyfiles -f src/data/compiled_api.* dist/data && copyfiles -f src/operations/op_list/*.json dist/operations/op_list && copyfiles -f src/operations/typings.d.ts dist/operations",

@@ -53,0 +52,0 @@ "build-npm": "./scripts/build-npm.sh",

# Getting started
**Tensorflow.js converter** is an open source library to load a pretrained TensorFlow model into the browser and run inference through Tensorflow.js.
It has two main pieces:
**TensorFlow.js converter** is an open source library to load a pretrained
TensorFlow [SavedModel](https://www.tensorflow.org/programmers_guide/saved_model#overview_of_saving_and_restoring_models)
into the browser and run inference through [TensorFlow.js](https://js.tensorflow.org).
1. [Coversion Python script](./scripts/convert.py), converts your Tensorflow SavedModel to web friendly format.
2. [Javascript API](./src/executor/tf_model.ts), simple one line API for inference.
## Inference with converted models
A 2-step process to import your model:
There are three types of files:
1. [A python script](./scripts/convert.py) that converts from a TensorFlow
SavedModel to a web friendly format. If you already have a converted model, or
are using an already hosted model (e.g. MobileNet), skip this step.
2. [Javascript API](./src/executor/tf_model.ts), for loading and running inference.
* web_model.pb (model)
* weights_manifest.json (weight manifest file)
* group1-shard\*of\* (collection of weight files)
## Step 1: Converting a [SavedModel](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md) to a web-friendly format
Remember to serve the manifest and weight files with the same url path.
1. Clone the github repo:
For example, we have the mobilenet models converted and served for you in following location:
```html
https://storage.cloud.google.com/tfjs-models/savedmodel/mobilenet_v1_1.0_224/optimized_model.pb
https://storage.cloud.google.com/tfjs-models/savedmodel/mobilenet_v1_1.0_224/weights_manifest.json
https://storage.cloud.google.com/tfjs-models/savedmodel/mobilenet_v1_1.0_224/group1-shard1of5
https://storage.cloud.google.com/tfjs-models/savedmodel/mobilenet_v1_1.0_224/group1-shard2of5
https://storage.cloud.google.com/tfjs-models/savedmodel/mobilenet_v1_1.0_224/group1-shard3of5
https://storage.cloud.google.com/tfjs-models/savedmodel/mobilenet_v1_1.0_224/group1-shard4of5
https://storage.cloud.google.com/tfjs-models/savedmodel/mobilenet_v1_1.0_224/group1-shard5of5
```bash
$ git clone git@github.com:tensorflow/tfjs-converter.git
```
1. Install the tfjs-converter npm package
2. Install following pip packages:
`yarn add @tensorflow/tfjs-converter` or `npm install @tensorflow/tfjs-converter`
```bash
$ pip install tensorflow numpy absl-py protobuf
```
2. Instantiate the [TFModel class](./src/executor/tf_model.ts) and run inference. [Example](./demo/mobilenet.ts)
3. Run the `convert.py` script
```bash
$ cd tfjs-converter/
$ python scripts/convert.py \
--saved_model_dir=/tmp/mobilenet/ \
--output_node_names='MobilenetV1/Predictions/Reshape_1' \
--output_graph=/tmp/mobilenet/web_model.pb \
--saved_model_tags=serve
```
```typescript
import {TFModel} from 'tfjs-converter';
| Options | Description
|---|---|
|`saved_model_dir` | Full path of the saved model directory |
|`output_node_names`| The names of the output nodes, comma separated |
|`output_graph` | Full path of the name for the output graph file|
|`saved_model_tags` | Tags of the MetaGraphDef to load, in comma separated format. Defaults to `serve`.
const MODEL_FILE_URL = 'http://example.org/models/mobilenet/web_model.pb';
const WEIGHT_MANIFEST_FILE_URL = 'http://example.org/models/mobilenet/weights_manifest.json';
### Web-friendly format
const model = new TFModel(MODEL_FILE_URL, WEIGHT_MANIFEST_FILE_URL);
const cat = document.getElementById('cat');
model.predict({input: tf.fromPixels(cat)}); // run the inference on your model.
```
The conversion script above produces 3 types of files:
* `web_model.pb` (the dataflow graph)
* `weights_manifest.json` (weight manifest file)
* `group1-shard\*of\*` (collection of binary weight files)
## Convert your own Tensorflow pre-trained model in [SavedModel](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md) format
For example, here is the MobileNet model converted and served in
following location:
### Dependencies
1. Clone the github repo:
```bash
$ git clone git@github.com:tensorflow/tfjs-converter.git
```html
https://storage.cloud.google.com/tfjs-models/savedmodel/mobilenet_v1_1.0_224/optimized_model.pb
https://storage.cloud.google.com/tfjs-models/savedmodel/mobilenet_v1_1.0_224/weights_manifest.json
https://storage.cloud.google.com/tfjs-models/savedmodel/mobilenet_v1_1.0_224/group1-shard1of5
...
https://storage.cloud.google.com/tfjs-models/savedmodel/mobilenet_v1_1.0_224/group1-shard5of5
```
2. Install following pip packages:
## Step 2: Loading and running in the browser
```bash
$ pip install tensorflow numpy absl-py protobuf
```
1. Install the tfjs-converter npm package
### Conversion
`yarn add @tensorflow/tfjs-converter` or `npm install @tensorflow/tfjs-converter`
```bash
$ cd tfjs-converter/
$ python scripts/convert.py --saved_model_dir=/tmp/mobilenet/ --output_node_names='MobilenetV1/Predictions/Reshape_1' --output_graph=/tmp/mobilenet/web_model.pb --saved_model_tags=serve
```
2. Instantiate the [TFModel class](./src/executor/tf_model.ts) and run inference.
| Options | Description | Default value |
|---|---|---|
|saved_model_dir | Full path of the saved model directory | |
|output_node_names| The names of the output nodes, comma separated | |
|output_graph | Full path of the name for the output graph file | |
|saved_model_tags |SavedModel Tags of the MetaGraphDef to load, in comma separated string format| serve |
```typescript
import * as tfc from '@tensorflow/tfjs-core';
import {TFModel} from '@tensorflow/tfjs-converter';
### Outputs
const MODEL_URL = 'https://.../mobilenet/web_model.pb';
const WEIGHTS_URL = 'https://.../mobilenet/weights_manifest.json';
This script would generate a collection of files, including model topology file, weight manifest file and weight files.
In the above example, generated files are:
const model = new TFModel(MODEL_URL, WEIGHTS_URL);
const cat = document.getElementById('cat');
model.predict({input: tfc.fromPixels(cat)});
```
* web_model.pb (model)
* weights_manifest.json (weight manifest file)
* group1-shard\*of\* (collection of weight files)
Check out our working [MobileNet demo](./demo/README.md).
You can serve these files similarly as shown in the inference [example] (./demo).
## Supported operations
### Limitations
Currently TensorFlow.js only supports a limited set of TensorFlow Ops. See the
[full list](./docs/supported_ops.md).
If your model uses an unsupported ops, the `convert.py` script will fail and
produce a list of the unsupported ops in your model. Please file issues to let us
know what ops you need support with.
Currently Tensorflow.js only supports a limit set of Tensorflow Ops, here is the [full list](./docs/supported_ops.md).
When you converting model with any unsupported Ops, the convert.py script will prompt the unsupported Ops list at the end of the execution. Please fill bugs to let us know what Ops you need support with.
## FAQ
1. What Tensorflow models does the converter currently support?
1. What TensorFlow models does the converter currently support?

@@ -114,7 +115,9 @@ Image-based models (MobileNet, SqueezeNet, add more if you tested) are the most supported. Models with control flow ops (e.g. RNNs) are not yet supported. The convert.py script will validate the model you have and show a list of unsupported ops in your model. See [this list](./docs/supported_ops.md) for which ops are currently supported.

5.
5. Why the predict() method for inference is so much slower on the first time then the subsequent calls?
The time of first call also includes the compilation time of WebGL shader programs for the model. After the first call the shader programs are cached, which makes the subsequent calls much faster. You can warm up the cache by calling the predict method with an all zero inputs, right after the completion of the model loading.
## Development
To build **Tensorflow.js converter** from source, we need to clone the project and prepare
To build **TensorFlow.js converter** from source, we need to clone the project and prepare
the dev environment:

@@ -125,3 +128,3 @@

$ cd tfjs-converter
$ yarn prep # Installs dependencies.
$ yarn # Installs dependencies.
```

@@ -128,0 +131,0 @@

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

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc