@tensorflow/tfjs-layers
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -6,2 +6,3 @@ import { Scalar, Tensor, Tensor1D, Tensor2D } from '@tensorflow/tfjs-core'; | ||
import { epsilon as common_epsilon } from './common'; | ||
export declare function disposeScalarCache(): void; | ||
export declare function setBackend(requestedBackend: 'cpu' | 'webgl'): void; | ||
@@ -33,2 +34,3 @@ export declare function getBackend(): 'cpu' | 'webgl'; | ||
export declare function sliceAlongLastAxis(array: Tensor, start: number, size: number): Tensor; | ||
export declare function normalizeBatchInTraining(x: Tensor, gamma: Tensor, beta: Tensor, reductionAxes: number[], epsilon?: number): [Tensor, Tensor, Tensor]; | ||
export declare function concatenate(tensors: Tensor[], axis?: number): Tensor; | ||
@@ -35,0 +37,0 @@ export declare function concatAlongFirstAxis(a: Tensor, b: Tensor): Tensor; |
@@ -5,3 +5,2 @@ "use strict"; | ||
var tfjs_core_1 = require("@tensorflow/tfjs-core"); | ||
var _ = require("underscore"); | ||
var common_1 = require("../common"); | ||
@@ -24,2 +23,3 @@ var errors_1 = require("../errors"); | ||
} | ||
exports.disposeScalarCache = disposeScalarCache; | ||
function setBackend(requestedBackend) { | ||
@@ -206,4 +206,4 @@ tfc.setBackend(requestedBackend); | ||
default: | ||
throw new errors_1.ValueError("sliceAlongFirstAxis() received an unsupported subtype of Tensor: " + | ||
("" + array.constructor.name)); | ||
throw new errors_1.ValueError("sliceAlongFirstAxis() received an unsupported tensor rank: " + | ||
("" + array.rank)); | ||
} | ||
@@ -223,7 +223,51 @@ } | ||
default: | ||
throw new errors_1.ValueError("sliceAlongLastAxis() received an unsupported subtype of Tensor: " + | ||
("" + array.constructor.name)); | ||
throw new errors_1.ValueError("sliceAlongLastAxis() received an unsupported tensor rank: " + | ||
("" + array.rank)); | ||
} | ||
} | ||
exports.sliceAlongLastAxis = sliceAlongLastAxis; | ||
function regularNormalizeBatchInTraining(x, gamma, beta, reductionAxes, epsilon) { | ||
if (epsilon === void 0) { epsilon = 1e-3; } | ||
return tfjs_core_1.tidy(function () { | ||
var meanAndVariance = tfc.moments(x, reductionAxes); | ||
var mean = meanAndVariance.mean; | ||
var variance = meanAndVariance.variance; | ||
var normed = batchNormalization(x, mean, variance, beta, gamma, epsilon); | ||
return [normed, mean, variance]; | ||
}); | ||
} | ||
function broadcastNormalizeBatchInTraining(x, gamma, beta, reductionAxes, epsilon) { | ||
if (epsilon === void 0) { epsilon = 1e-3; } | ||
return tfjs_core_1.tidy(function () { | ||
var meanAndVariance = tfc.moments(x, reductionAxes); | ||
var mean = meanAndVariance.mean; | ||
var variance = meanAndVariance.variance; | ||
var targetShape = []; | ||
for (var _i = 0, _a = math_utils.range(0, ndim(x)); _i < _a.length; _i++) { | ||
var axis = _a[_i]; | ||
if (reductionAxes.indexOf(axis) !== -1) { | ||
targetShape.push(1); | ||
} | ||
else { | ||
targetShape.push(x.shape[axis]); | ||
} | ||
} | ||
var broadcastMean = reshape(mean, targetShape); | ||
var broadcastVariance = reshape(variance, targetShape); | ||
var broadcastGamma = gamma == null ? null : reshape(gamma, targetShape); | ||
var broadcastBeta = beta == null ? null : reshape(beta, targetShape); | ||
var normed = batchNormalization(x, broadcastMean, broadcastVariance, broadcastBeta, broadcastGamma, epsilon); | ||
return [normed, mean, variance]; | ||
}); | ||
} | ||
function normalizeBatchInTraining(x, gamma, beta, reductionAxes, epsilon) { | ||
if (epsilon === void 0) { epsilon = 1e-3; } | ||
if (tfjs_core_1.util.arraysEqual(reductionAxes.slice().sort(), math_utils.range(0, ndim(x) - 1))) { | ||
return regularNormalizeBatchInTraining(x, gamma, beta, reductionAxes, epsilon); | ||
} | ||
else { | ||
return broadcastNormalizeBatchInTraining(x, gamma, beta, reductionAxes, epsilon); | ||
} | ||
} | ||
exports.normalizeBatchInTraining = normalizeBatchInTraining; | ||
function concatenate(tensors, axis) { | ||
@@ -258,4 +302,4 @@ if (axis === void 0) { axis = -1; } | ||
default: | ||
throw new errors_1.ValueError('concatAlongFirstAxis() received an unsupported subtype of ' + | ||
'Tensor: ' + a.constructor.name); | ||
throw new errors_1.ValueError('concatAlongFirstAxis() received an unsupported tensor rank: ' + | ||
a.rank); | ||
} | ||
@@ -497,3 +541,4 @@ } | ||
} | ||
return tfc.oneHot(indices, numClasses); | ||
indices = indices.toInt(); | ||
return tfc.oneHot(indices, numClasses).toFloat(); | ||
} | ||
@@ -513,4 +558,7 @@ exports.oneHot = oneHot; | ||
if (Array.isArray(indices)) { | ||
indices = tfjs_core_1.tensor1d(indices); | ||
indices = tfjs_core_1.tensor1d(indices, 'int32'); | ||
} | ||
else { | ||
indices = indices.toInt(); | ||
} | ||
return tfc.gather(reference, indices, axis); | ||
@@ -597,9 +645,9 @@ } | ||
if (ndim(x) === 2) { | ||
out = tfc.batchNormalization2d(x, mean, variance, epsilon); | ||
out = tfc.batchNormalization2d(x, mean, variance, epsilon, gamma, beta); | ||
} | ||
else if (ndim(x) === 3) { | ||
out = tfc.batchNormalization3d(x, mean, variance, epsilon); | ||
out = tfc.batchNormalization3d(x, mean, variance, epsilon, gamma, beta); | ||
} | ||
else if (ndim(x) === 4) { | ||
out = tfc.batchNormalization4d(x, mean, variance, epsilon); | ||
out = tfc.batchNormalization4d(x, mean, variance, epsilon, gamma, beta); | ||
} | ||
@@ -610,8 +658,2 @@ else { | ||
} | ||
if (gamma != null) { | ||
out = multiply(out, gamma); | ||
} | ||
if (beta != null) { | ||
out = add(out, beta); | ||
} | ||
return out; | ||
@@ -724,3 +766,3 @@ } | ||
function dropout(x, level, noiseShape, seed) { | ||
if (noiseShape != null && !_.isEqual(x.shape, noiseShape)) { | ||
if (noiseShape != null && !tfjs_core_1.util.arraysEqual(x.shape, noiseShape)) { | ||
throw new errors_1.NotImplementedError('Non-default noise shape is not implemented yet: ' + | ||
@@ -919,3 +961,3 @@ JSON.stringify(noiseShape)); | ||
output = clip(output, exports.epsilon(), 1 - exports.epsilon()); | ||
return tfc.neg(tfc.sum(tfc.mul(target, tfc.log(output)), shape(output).length - 1)); | ||
return tfc.neg(tfc.sum(tfc.mul(target.toFloat(), tfc.log(output)), shape(output).length - 1)); | ||
} | ||
@@ -925,3 +967,3 @@ exports.categoricalCrossentropy = categoricalCrossentropy; | ||
if (fromLogits === void 0) { fromLogits = false; } | ||
var flatTarget = tfc.floor(flatten(target)); | ||
var flatTarget = tfc.floor(flatten(target)).toInt(); | ||
var outputShape = shape(output); | ||
@@ -974,3 +1016,3 @@ var oneHotTarget = reshape(tfc.oneHot(flatTarget, outputShape[outputShape.length - 1]), outputShape); | ||
} | ||
var axes = [1, 0].concat(_.range(2, ndim)); | ||
var axes = [1, 0].concat(math_utils.range(2, ndim)); | ||
inputs = transpose(inputs, axes); | ||
@@ -1011,3 +1053,4 @@ if (mask != null) { | ||
lastOutput, | ||
transpose(outputs, [1, 0].concat(_.range(2, outputs.shape.length))), states | ||
transpose(outputs, [1, 0].concat(math_utils.range(2, outputs.shape.length))), | ||
states | ||
]; | ||
@@ -1014,0 +1057,0 @@ } |
import { Tensor } from '@tensorflow/tfjs-core'; | ||
import { ConfigDict, ConfigDictValue } from './types'; | ||
export declare abstract class Constraint { | ||
import { ConfigDict, ConfigDictValue, Serializable } from './types'; | ||
export declare abstract class Constraint extends Serializable { | ||
abstract apply(w: Tensor): Tensor; | ||
@@ -18,2 +18,3 @@ getConfig(): ConfigDict; | ||
apply(w: Tensor): Tensor; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -29,2 +30,3 @@ } | ||
apply(w: Tensor): Tensor; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -34,2 +36,3 @@ } | ||
apply(w: Tensor): Tensor; | ||
getClassName(): string; | ||
} | ||
@@ -53,2 +56,3 @@ export interface MinMaxNormConfig { | ||
apply(w: Tensor): Tensor; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -55,0 +59,0 @@ } |
@@ -21,2 +21,3 @@ "use strict"; | ||
var K = require("./backend/tfjs_backend"); | ||
var types_1 = require("./types"); | ||
var generic_utils_1 = require("./utils/generic_utils"); | ||
@@ -26,4 +27,6 @@ function calcL2Norms(w, axis) { | ||
} | ||
var Constraint = (function () { | ||
var Constraint = (function (_super) { | ||
__extends(Constraint, _super); | ||
function Constraint() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
@@ -37,3 +40,3 @@ Constraint.prototype.getConfig = function () { | ||
return Constraint; | ||
}()); | ||
}(types_1.Serializable)); | ||
exports.Constraint = Constraint; | ||
@@ -56,2 +59,5 @@ var MaxNorm = (function (_super) { | ||
}; | ||
MaxNorm.prototype.getClassName = function () { | ||
return 'MaxNorm'; | ||
}; | ||
MaxNorm.prototype.getConfig = function () { | ||
@@ -75,2 +81,5 @@ return { maxValue: this.maxValue, axis: this.axis }; | ||
}; | ||
UnitNorm.prototype.getClassName = function () { | ||
return 'UnitNorm'; | ||
}; | ||
UnitNorm.prototype.getConfig = function () { | ||
@@ -91,2 +100,5 @@ return { axis: this.axis }; | ||
}; | ||
NonNeg.prototype.getClassName = function () { | ||
return 'NonNeg'; | ||
}; | ||
return NonNeg; | ||
@@ -117,2 +129,5 @@ }(Constraint)); | ||
}; | ||
MinMaxNorm.prototype.getClassName = function () { | ||
return 'MinMaxNorm'; | ||
}; | ||
MinMaxNorm.prototype.getConfig = function () { | ||
@@ -119,0 +134,0 @@ return { |
@@ -5,3 +5,3 @@ import { Scalar, Tensor } from '@tensorflow/tfjs-core'; | ||
import { Regularizer } from '../regularizers'; | ||
import { ConfigDict, DType, JsonDict, LayerVariable, NamedTensorMap, RegularizerFn, Shape, SymbolicTensor, TensorInterface } from '../types'; | ||
import { ConfigDict, DType, JsonDict, LayerVariable, NamedTensorMap, RegularizerFn, Serializable, Shape, SymbolicTensor, TensorInterface } from '../types'; | ||
import * as generic_utils from '../utils/generic_utils'; | ||
@@ -70,3 +70,3 @@ export declare type Op = (x: LayerVariable) => LayerVariable; | ||
export declare type CallHook = (inputs: Tensor | Tensor[], kwargs: any) => void; | ||
export declare class Layer { | ||
export declare abstract class Layer extends Serializable { | ||
name: string; | ||
@@ -136,2 +136,3 @@ inputSpec: InputSpec[]; | ||
apply(inputs: Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[], kwargs?: any): Tensor | Tensor[] | SymbolicTensor; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -152,3 +153,3 @@ } | ||
} | ||
export declare class Container extends Layer { | ||
export declare abstract class Container extends Layer { | ||
inputs: SymbolicTensor[]; | ||
@@ -155,0 +156,0 @@ outputs: SymbolicTensor[]; |
@@ -56,2 +56,4 @@ import { Optimizer, Scalar, Tensor, Tensor1D } from '@tensorflow/tfjs-core'; | ||
[outputName: string]: string; | ||
} | LossOrMetricFn | LossOrMetricFn[] | { | ||
[outputName: string]: LossOrMetricFn; | ||
}; | ||
@@ -66,2 +68,4 @@ metrics?: string[] | { | ||
[outputName: string]: string; | ||
} | LossOrMetricFn | LossOrMetricFn[] | { | ||
[outputName: string]: LossOrMetricFn; | ||
}; | ||
@@ -80,2 +84,3 @@ lossFunctions: LossOrMetricFn[]; | ||
constructor(config: ContainerConfig); | ||
getClassName(): string; | ||
compile(config: ModelCompileConfig): void; | ||
@@ -82,0 +87,0 @@ private checkTrainableWeightsConsistency(); |
@@ -56,3 +56,2 @@ "use strict"; | ||
var tfjs_core_1 = require("@tensorflow/tfjs-core"); | ||
var _ = require("underscore"); | ||
var K = require("../backend/tfjs_backend"); | ||
@@ -65,2 +64,3 @@ var callbacks_1 = require("../callbacks"); | ||
var generic_utils_1 = require("../utils/generic_utils"); | ||
var math_utils_1 = require("../utils/math_utils"); | ||
var executor_1 = require("./executor"); | ||
@@ -176,5 +176,5 @@ var topology_1 = require("./topology"); | ||
function checkArrayLengths(inputs, targets, weights) { | ||
var setX = _.unique(inputs.map(function (input) { return input.shape[0]; })); | ||
var setX = generic_utils_1.unique(inputs.map(function (input) { return input.shape[0]; })); | ||
setX.sort(); | ||
var setY = _.unique(targets.map(function (target) { return target.shape[0]; })); | ||
var setY = generic_utils_1.unique(targets.map(function (target) { return target.shape[0]; })); | ||
setY.sort(); | ||
@@ -191,3 +191,3 @@ if (setX.length > 1) { | ||
} | ||
if (setX.length > 0 && setY.length > 0 && !_.isEqual(setX, setY)) { | ||
if (setX.length > 0 && setY.length > 0 && !tfjs_core_1.util.arraysEqual(setX, setY)) { | ||
throw new errors_1.ValueError("Input Tensors should have the same number of samples as target " + | ||
@@ -219,3 +219,3 @@ ("Tensors. Found " + setX[0] + " input sample(s) and " + setY[0] + " target ") + | ||
} | ||
if (_.contains(keyLosses, loss)) { | ||
if (keyLosses.indexOf(loss) !== -1) { | ||
var slicedYShape = y.shape.slice(1); | ||
@@ -269,3 +269,3 @@ var slicedShape = shape.slice(1); | ||
else { | ||
return K.gather(arrays, indices); | ||
return K.gather(arrays, indices.dtype === 'int32' ? indices : indices.toInt()); | ||
} | ||
@@ -357,2 +357,5 @@ } | ||
} | ||
Model.prototype.getClassName = function () { | ||
return 'Model'; | ||
}; | ||
Model.prototype.compile = function (config) { | ||
@@ -374,6 +377,7 @@ var _this = this; | ||
var lossFunctions = []; | ||
if (!Array.isArray(config.loss) && typeof config.loss !== 'string') { | ||
if (!Array.isArray(config.loss) && typeof config.loss !== 'string' && | ||
typeof config.loss !== 'function') { | ||
config.loss = config.loss; | ||
for (var name_3 in config.loss) { | ||
if (!_.contains(this.outputNames, name_3)) { | ||
if (this.outputNames.indexOf(name_3) === -1) { | ||
throw new errors_1.ValueError("Unknown entry in loss dictionary: \"" + name_3 + "\". Only expect the " + | ||
@@ -398,3 +402,4 @@ ("following keys: " + this.outputNames)); | ||
} | ||
lossFunctions = config.loss.map(function (l) { return losses.get(l); }); | ||
var theLosses = config.loss; | ||
lossFunctions = theLosses.map(function (l) { return losses.get(l); }); | ||
} | ||
@@ -679,3 +684,3 @@ else { | ||
if (numTrainSamples != null) { | ||
indexArray = _.range(numTrainSamples); | ||
indexArray = math_utils_1.range(0, numTrainSamples); | ||
} | ||
@@ -706,3 +711,3 @@ this.history = new callbacks_1.History(); | ||
_loop_4 = function (epoch) { | ||
var epochLogs, epochIndexArray, epochIndexArray1D_1, batches_1, _loop_5, batchIndex; | ||
var epochLogs, epochIndexArray1D_1, batches_1, _loop_5, batchIndex; | ||
return __generator(this, function (_a) { | ||
@@ -714,3 +719,2 @@ switch (_a.label) { | ||
epochLogs = {}; | ||
epochIndexArray = indexArray; | ||
if (!(stepsPerEpoch != null)) return [3, 2]; | ||
@@ -723,5 +727,5 @@ throw new errors_1.NotImplementedError('stepsPerEpoch mode is not implemented yet.'); | ||
else if (shuffle) { | ||
epochIndexArray = _.shuffle(indexArray); | ||
tfjs_core_1.util.shuffle(indexArray); | ||
} | ||
epochIndexArray1D_1 = tfjs_core_1.tensor1d(epochIndexArray); | ||
epochIndexArray1D_1 = tfjs_core_1.tensor1d(indexArray); | ||
batches_1 = makeBatches(numTrainSamples, batchSize); | ||
@@ -826,3 +830,3 @@ _loop_5 = function (batchIndex) { | ||
var batches = makeBatches(numSamples, batchSize); | ||
var indexArray = tfjs_core_1.tensor1d(_.range(numSamples)); | ||
var indexArray = tfjs_core_1.tensor1d(math_utils_1.range(0, numSamples)); | ||
for (var batchIndex = 0; batchIndex < batches.length; ++batchIndex) { | ||
@@ -829,0 +833,0 @@ var batchStart = batches[batchIndex][0]; |
@@ -0,1 +1,2 @@ | ||
import { Tensor } from '@tensorflow/tfjs-core'; | ||
import { Constraint, MaxNormConfig, MinMaxNormConfig, UnitNormConfig } from './constraints'; | ||
@@ -8,3 +9,3 @@ import { ContainerConfig, InputConfig, InputLayerConfig, Layer, LayerConfig } from './engine/topology'; | ||
import { DepthwiseConv2DLayerConfig } from './layers/convolutional_depthwise'; | ||
import { ActivationLayerConfig, DenseLayerConfig, DropoutLayerConfig, RepeatVectorLayerConfig } from './layers/core'; | ||
import { ActivationLayerConfig, DenseLayerConfig, DropoutLayerConfig, RepeatVectorLayerConfig, ReshapeLayerConfig } from './layers/core'; | ||
import { EmbeddingLayerConfig } from './layers/embeddings'; | ||
@@ -16,3 +17,3 @@ import { ConcatenateLayerConfig } from './layers/merge'; | ||
import { GRUCellLayerConfig, GRULayerConfig, LSTMCellLayerConfig, LSTMLayerConfig, RNNCell, RNNLayerConfig, SimpleRNNCellLayerConfig, SimpleRNNLayerConfig, StackedRNNCellsConfig } from './layers/recurrent'; | ||
import { BidirectionalLayerConfig, WrapperLayerConfig } from './layers/wrappers'; | ||
import { BidirectionalLayerConfig, Wrapper, WrapperLayerConfig } from './layers/wrappers'; | ||
import { Sequential, SequentialConfig } from './models'; | ||
@@ -35,3 +36,3 @@ import { L1Config, L1L2Config, L2Config, Regularizer } from './regularizers'; | ||
static softmax(config?: SoftmaxLayerConfig): Layer; | ||
static thresohldedReLU(config?: ThresholdedReLULayerConfig): Layer; | ||
static thresholdedReLU(config?: ThresholdedReLULayerConfig): Layer; | ||
static conv1d(config: ConvLayerConfig): Layer; | ||
@@ -47,6 +48,7 @@ static conv2d(config: ConvLayerConfig): Layer; | ||
static repeatVector(config: RepeatVectorLayerConfig): Layer; | ||
static reshape(config: ReshapeLayerConfig): Layer; | ||
static embedding(config: EmbeddingLayerConfig): Layer; | ||
static add(config?: LayerConfig): Layer; | ||
static average(config?: LayerConfig): Layer; | ||
static concatenate(config: ConcatenateLayerConfig): Layer; | ||
static concatenate(config?: ConcatenateLayerConfig): Layer; | ||
static maximum(config?: LayerConfig): Layer; | ||
@@ -56,3 +58,3 @@ static minimum(config?: LayerConfig): Layer; | ||
static batchNormalization(config: BatchNormalizationLayerConfig): Layer; | ||
static zeroPadding2d(config: ZeroPadding2DLayerConfig): Layer; | ||
static zeroPadding2d(config?: ZeroPadding2DLayerConfig): Layer; | ||
static averagePooling1d(config: Pooling1DLayerConfig): Layer; | ||
@@ -78,3 +80,3 @@ static avgPool1d(config: Pooling1DLayerConfig): Layer; | ||
static stackedRNNCells(config: StackedRNNCellsConfig): RNNCell; | ||
static bidirectional(config: BidirectionalLayerConfig): Layer; | ||
static bidirectional(config: BidirectionalLayerConfig): Wrapper; | ||
static timeDistributed(config: WrapperLayerConfig): Layer; | ||
@@ -103,2 +105,16 @@ } | ||
} | ||
export declare class MetricExports { | ||
static binaryAccuracy(yTrue: Tensor, yPred: Tensor): Tensor; | ||
static binaryCrossentropy(yTrue: Tensor, yPred: Tensor): Tensor; | ||
static categoricalAccuracy(yTrue: Tensor, yPred: Tensor): Tensor; | ||
static categoricalCrossentropy(yTrue: Tensor, yPred: Tensor): Tensor; | ||
static cosineProximity(yTrue: Tensor, yPred: Tensor): Tensor; | ||
meanAbsoluteError(yTrue: Tensor, yPred: Tensor): Tensor; | ||
meanAbsolutePercentageError(yTrue: Tensor, yPred: Tensor): Tensor; | ||
MAPE(yTrue: Tensor, yPred: Tensor): Tensor; | ||
mape(yTrue: Tensor, yPred: Tensor): Tensor; | ||
static meanSquaredError(yTrue: Tensor, yPred: Tensor): Tensor; | ||
static MSE(yTrue: Tensor, yPred: Tensor): Tensor; | ||
static mse(yTrue: Tensor, yPred: Tensor): Tensor; | ||
} | ||
export declare class RegularizerExports { | ||
@@ -105,0 +121,0 @@ static l1l2(config?: L1L2Config): Regularizer; |
@@ -25,2 +25,4 @@ "use strict"; | ||
var wrappers_1 = require("./layers/wrappers"); | ||
var losses_1 = require("./losses"); | ||
var metrics_1 = require("./metrics"); | ||
var models_1 = require("./models"); | ||
@@ -82,3 +84,3 @@ var regularizers_1 = require("./regularizers"); | ||
}; | ||
LayerExports.thresohldedReLU = function (config) { | ||
LayerExports.thresholdedReLU = function (config) { | ||
return new advanced_activations_1.ThresholdedReLU(config); | ||
@@ -116,2 +118,5 @@ }; | ||
}; | ||
LayerExports.reshape = function (config) { | ||
return new core_1.Reshape(config); | ||
}; | ||
LayerExports.embedding = function (config) { | ||
@@ -257,3 +262,3 @@ return new embeddings_1.Embedding(config); | ||
}) | ||
], LayerExports, "thresohldedReLU", null); | ||
], LayerExports, "thresholdedReLU", null); | ||
__decorate([ | ||
@@ -354,2 +359,11 @@ tfjs_core_1.doc({ | ||
namespace: 'layers', | ||
useDocsFrom: 'Reshape', | ||
configParamIndices: [0] | ||
}) | ||
], LayerExports, "reshape", null); | ||
__decorate([ | ||
tfjs_core_1.doc({ | ||
heading: 'Layers', | ||
subheading: 'Basic', | ||
namespace: 'layers', | ||
useDocsFrom: 'Embedding', | ||
@@ -784,2 +798,96 @@ configParamIndices: [0] | ||
exports.InitializerExports = InitializerExports; | ||
var MetricExports = (function () { | ||
function MetricExports() { | ||
} | ||
MetricExports.binaryAccuracy = function (yTrue, yPred) { | ||
return metrics_1.binaryAccuracy(yTrue, yPred); | ||
}; | ||
MetricExports.binaryCrossentropy = function (yTrue, yPred) { | ||
return metrics_1.binaryCrossentropy(yTrue, yPred); | ||
}; | ||
MetricExports.categoricalAccuracy = function (yTrue, yPred) { | ||
return metrics_1.categoricalAccuracy(yTrue, yPred); | ||
}; | ||
MetricExports.categoricalCrossentropy = function (yTrue, yPred) { | ||
return losses_1.categoricalCrossentropy(yTrue, yPred); | ||
}; | ||
MetricExports.cosineProximity = function (yTrue, yPred) { | ||
return losses_1.cosineProximity(yTrue, yPred); | ||
}; | ||
MetricExports.prototype.meanAbsoluteError = function (yTrue, yPred) { | ||
return losses_1.meanAbsoluteError(yTrue, yPred); | ||
}; | ||
MetricExports.prototype.meanAbsolutePercentageError = function (yTrue, yPred) { | ||
return losses_1.meanAbsolutePercentageError(yTrue, yPred); | ||
}; | ||
MetricExports.prototype.MAPE = function (yTrue, yPred) { | ||
return losses_1.meanAbsolutePercentageError(yTrue, yPred); | ||
}; | ||
MetricExports.prototype.mape = function (yTrue, yPred) { | ||
return losses_1.meanAbsolutePercentageError(yTrue, yPred); | ||
}; | ||
MetricExports.meanSquaredError = function (yTrue, yPred) { | ||
return losses_1.meanSquaredError(yTrue, yPred); | ||
}; | ||
MetricExports.MSE = function (yTrue, yPred) { | ||
return losses_1.meanSquaredError(yTrue, yPred); | ||
}; | ||
MetricExports.mse = function (yTrue, yPred) { | ||
return losses_1.meanSquaredError(yTrue, yPred); | ||
}; | ||
__decorate([ | ||
tfjs_core_1.doc({ | ||
heading: 'Metrics', | ||
namespace: 'metrics', | ||
useDocsFrom: 'meanAbsoluteError' | ||
}) | ||
], MetricExports.prototype, "meanAbsoluteError", null); | ||
__decorate([ | ||
tfjs_core_1.doc({ | ||
heading: 'Metrics', | ||
namespace: 'metrics', | ||
useDocsFrom: 'meanAbsolutePercentageError' | ||
}) | ||
], MetricExports.prototype, "meanAbsolutePercentageError", null); | ||
__decorate([ | ||
tfjs_core_1.doc({ heading: 'Metrics', namespace: 'metrics', useDocsFrom: 'binaryAccuracy' }) | ||
], MetricExports, "binaryAccuracy", null); | ||
__decorate([ | ||
tfjs_core_1.doc({ | ||
heading: 'Metrics', | ||
namespace: 'metrics', | ||
useDocsFrom: 'binaryCrossentropy' | ||
}) | ||
], MetricExports, "binaryCrossentropy", null); | ||
__decorate([ | ||
tfjs_core_1.doc({ | ||
heading: 'Metrics', | ||
namespace: 'metrics', | ||
useDocsFrom: 'categoricalAccuracy' | ||
}) | ||
], MetricExports, "categoricalAccuracy", null); | ||
__decorate([ | ||
tfjs_core_1.doc({ | ||
heading: 'Metrics', | ||
namespace: 'metrics', | ||
useDocsFrom: 'categoricalCrossentropy' | ||
}) | ||
], MetricExports, "categoricalCrossentropy", null); | ||
__decorate([ | ||
tfjs_core_1.doc({ | ||
heading: 'Metrics', | ||
namespace: 'metrics', | ||
useDocsFrom: 'cosineProximity' | ||
}) | ||
], MetricExports, "cosineProximity", null); | ||
__decorate([ | ||
tfjs_core_1.doc({ | ||
heading: 'Metrics', | ||
namespace: 'metrics', | ||
useDocsFrom: 'meanSquaredError' | ||
}) | ||
], MetricExports, "meanSquaredError", null); | ||
return MetricExports; | ||
}()); | ||
exports.MetricExports = MetricExports; | ||
var RegularizerExports = (function () { | ||
@@ -786,0 +894,0 @@ function RegularizerExports() { |
import * as backend from './backend/tfjs_backend'; | ||
import { ConstraintExports, InitializerExports, LayerExports, ModelExports, RegularizerExports } from './exports'; | ||
import { ConstraintExports, InitializerExports, LayerExports, MetricExports, ModelExports, RegularizerExports } from './exports'; | ||
export { Callback, CallbackList, CustomCallback, CustomCallbackConfig, Logs } from './callbacks'; | ||
@@ -7,3 +7,3 @@ export { Model, ModelCompileConfig, ModelEvaluateConfig, ModelFitConfig, ModelPredictConfig } from './engine/training'; | ||
export { ModelAndWeightsConfig, Sequential, SequentialConfig } from './models'; | ||
export { SymbolicTensor } from './types'; | ||
export { Shape, SymbolicTensor } from './types'; | ||
export { version as version_layers } from './version'; | ||
@@ -18,2 +18,3 @@ export { backend }; | ||
export declare const initializers: typeof InitializerExports; | ||
export declare const metrics: typeof MetricExports; | ||
export declare const regularizers: typeof RegularizerExports; |
@@ -27,2 +27,3 @@ "use strict"; | ||
exports.initializers = exports_1.InitializerExports; | ||
exports.metrics = exports_1.MetricExports; | ||
exports.regularizers = exports_1.RegularizerExports; |
import { Tensor } from '@tensorflow/tfjs-core'; | ||
import { DType, Shape } from './types'; | ||
import { DType, Serializable, Shape } from './types'; | ||
import { ConfigDict, ConfigDictValue } from './types'; | ||
@@ -11,3 +11,3 @@ import { Constructor } from './utils/generic_utils'; | ||
export declare function checkDistribution(value?: string): void; | ||
export declare abstract class Initializer { | ||
export declare abstract class Initializer extends Serializable { | ||
static fromConfig<T>(cls: Constructor<T>, config: ConfigDict): T; | ||
@@ -19,5 +19,7 @@ fromConfigUsesCustomObjects(): boolean; | ||
export declare class Zeros extends Initializer { | ||
getClassName(): string; | ||
apply(shape: Shape, dtype?: DType): Tensor; | ||
} | ||
export declare class Ones extends Initializer { | ||
getClassName(): string; | ||
apply(shape: Shape, dtype?: DType): Tensor; | ||
@@ -32,2 +34,3 @@ } | ||
apply(shape: Shape, dtype?: DType): Tensor; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -48,2 +51,3 @@ } | ||
apply(shape: Shape, dtype?: DType): Tensor; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -64,2 +68,3 @@ } | ||
apply(shape: Shape, dtype?: DType): Tensor; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -80,2 +85,3 @@ } | ||
apply(shape: Shape, dtype?: DType): Tensor; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -90,2 +96,3 @@ } | ||
apply(shape: Shape, dtype?: DType): Tensor; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -106,2 +113,3 @@ } | ||
apply(shape: Shape, dtype?: DType): Tensor; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -133,2 +141,3 @@ } | ||
apply(shape: Shape, dtype?: DType): Tensor; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -135,0 +144,0 @@ } |
@@ -20,3 +20,2 @@ "use strict"; | ||
var tfjs_core_1 = require("@tensorflow/tfjs-core"); | ||
var _ = require("underscore"); | ||
var K = require("./backend/tfjs_backend"); | ||
@@ -50,4 +49,6 @@ var common_1 = require("./common"); | ||
exports.checkDistribution = checkDistribution; | ||
var Initializer = (function () { | ||
var Initializer = (function (_super) { | ||
__extends(Initializer, _super); | ||
function Initializer() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
@@ -67,3 +68,3 @@ Initializer.fromConfig = function (cls, config) { | ||
return Initializer; | ||
}()); | ||
}(types_1.Serializable)); | ||
exports.Initializer = Initializer; | ||
@@ -75,2 +76,5 @@ var Zeros = (function (_super) { | ||
} | ||
Zeros.prototype.getClassName = function () { | ||
return 'Zeros'; | ||
}; | ||
Zeros.prototype.apply = function (shape, dtype) { | ||
@@ -88,2 +92,5 @@ return K.zeros(shape, dtype); | ||
} | ||
Ones.prototype.getClassName = function () { | ||
return 'Ones'; | ||
}; | ||
Ones.prototype.apply = function (shape, dtype) { | ||
@@ -106,2 +113,5 @@ return K.ones(shape, dtype); | ||
}; | ||
Constant.prototype.getClassName = function () { | ||
return 'Constant'; | ||
}; | ||
Constant.prototype.getConfig = function () { | ||
@@ -130,2 +140,5 @@ return { | ||
}; | ||
RandomUniform.prototype.getClassName = function () { | ||
return 'RandomUniform'; | ||
}; | ||
RandomUniform.prototype.getConfig = function () { | ||
@@ -152,2 +165,5 @@ return { minval: this.minval, maxval: this.maxval, seed: this.seed }; | ||
}; | ||
RandomNormal.prototype.getClassName = function () { | ||
return 'RandomNormal'; | ||
}; | ||
RandomNormal.prototype.getConfig = function () { | ||
@@ -174,2 +190,5 @@ return { mean: this.mean, stddev: this.stddev, seed: this.seed }; | ||
}; | ||
TruncatedNormal.prototype.getClassName = function () { | ||
return 'TruncatedNormal'; | ||
}; | ||
TruncatedNormal.prototype.getConfig = function () { | ||
@@ -198,2 +217,5 @@ return { mean: this.mean, stddev: this.stddev, seed: this.seed }; | ||
}; | ||
Identity.prototype.getClassName = function () { | ||
return 'Identity'; | ||
}; | ||
Identity.prototype.getConfig = function () { | ||
@@ -215,3 +237,3 @@ return { gain: this.gain.get() }; | ||
} | ||
else if (_.contains([3, 4, 5], shape.length)) { | ||
else if ([3, 4, 5].indexOf(shape.length) !== -1) { | ||
if (dataFormat === 'channelsFirst') { | ||
@@ -273,2 +295,5 @@ var receptiveFieldSize = math_utils_1.arrayProd(shape, 2); | ||
}; | ||
VarianceScaling.prototype.getClassName = function () { | ||
return 'VarianceScaling'; | ||
}; | ||
VarianceScaling.prototype.getConfig = function () { | ||
@@ -359,2 +384,5 @@ return { | ||
}; | ||
Orthogonal.prototype.getClassName = function () { | ||
return 'Orthogonal'; | ||
}; | ||
Orthogonal.prototype.getConfig = function () { | ||
@@ -361,0 +389,0 @@ return { |
@@ -13,2 +13,3 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
computeOutputShape(inputShape: Shape | Shape[]): Shape | Shape[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -25,2 +26,3 @@ } | ||
computeOutputShape(inputShape: Shape | Shape[]): Shape | Shape[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -38,2 +40,3 @@ } | ||
computeOutputShape(inputShape: Shape | Shape[]): Shape | Shape[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -50,3 +53,4 @@ } | ||
computeOutputShape(inputShape: Shape | Shape[]): Shape | Shape[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
} |
@@ -39,2 +39,5 @@ "use strict"; | ||
}; | ||
LeakyReLU.prototype.getClassName = function () { | ||
return 'LeakyReLU'; | ||
}; | ||
LeakyReLU.prototype.getConfig = function () { | ||
@@ -72,2 +75,5 @@ var config = { alpha: this.alpha }; | ||
}; | ||
ELU.prototype.getClassName = function () { | ||
return 'ELU'; | ||
}; | ||
ELU.prototype.getConfig = function () { | ||
@@ -102,2 +108,5 @@ var config = { alpha: this.alpha }; | ||
}; | ||
ThresholdedReLU.prototype.getClassName = function () { | ||
return 'ThresholdedReLU'; | ||
}; | ||
ThresholdedReLU.prototype.getConfig = function () { | ||
@@ -131,2 +140,5 @@ var config = { theta: this.theta }; | ||
}; | ||
Softmax.prototype.getClassName = function () { | ||
return 'Softmax'; | ||
}; | ||
Softmax.prototype.getConfig = function () { | ||
@@ -133,0 +145,0 @@ var config = { axis: this.axis }; |
@@ -21,2 +21,3 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
constructor(config: DepthwiseConv2DLayerConfig); | ||
getClassName(): string; | ||
build(inputShape: Shape | Shape[]): void; | ||
@@ -23,0 +24,0 @@ call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; |
@@ -34,2 +34,5 @@ "use strict"; | ||
} | ||
DepthwiseConv2D.prototype.getClassName = function () { | ||
return 'DepthwiseConv2D'; | ||
}; | ||
DepthwiseConv2D.prototype.build = function (inputShape) { | ||
@@ -36,0 +39,0 @@ inputShape = generic_utils_1.getExactlyOneShape(inputShape); |
@@ -55,2 +55,3 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
constructor(config: ConvLayerConfig); | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -61,2 +62,3 @@ } | ||
constructor(config: ConvLayerConfig); | ||
getClassName(): string; | ||
build(inputShape: Shape | Shape[]): void; | ||
@@ -91,2 +93,3 @@ call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -96,6 +99,8 @@ } | ||
constructor(config?: SeparableConvLayerConfig); | ||
getClassName(): string; | ||
} | ||
export declare class Conv1D extends Conv { | ||
constructor(config: ConvLayerConfig); | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
} |
@@ -163,2 +163,5 @@ "use strict"; | ||
} | ||
Conv2D.prototype.getClassName = function () { | ||
return 'Conv2D'; | ||
}; | ||
Conv2D.prototype.getConfig = function () { | ||
@@ -184,2 +187,5 @@ var config = _super.prototype.getConfig.call(this); | ||
} | ||
Conv2DTranspose.prototype.getClassName = function () { | ||
return 'Conv2DTranspose'; | ||
}; | ||
Conv2DTranspose.prototype.build = function (inputShape) { | ||
@@ -379,2 +385,5 @@ inputShape = generic_utils.getExactlyOneShape(inputShape); | ||
}; | ||
SeparableConv.prototype.getClassName = function () { | ||
return 'SeparableConv'; | ||
}; | ||
SeparableConv.prototype.getConfig = function () { | ||
@@ -408,2 +417,5 @@ var config = _super.prototype.getConfig.call(this); | ||
} | ||
SeparableConv2D.prototype.getClassName = function () { | ||
return 'SeparableConv2D'; | ||
}; | ||
return SeparableConv2D; | ||
@@ -420,2 +432,5 @@ }(SeparableConv)); | ||
} | ||
Conv1D.prototype.getClassName = function () { | ||
return 'Conv1D'; | ||
}; | ||
Conv1D.prototype.getConfig = function () { | ||
@@ -422,0 +437,0 @@ var config = _super.prototype.getConfig.call(this); |
@@ -22,2 +22,3 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -56,2 +57,3 @@ } | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -62,2 +64,3 @@ } | ||
computeOutputShape(inputShape: Shape | Shape[]): Shape | Shape[]; | ||
getClassName(): string; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
@@ -71,2 +74,3 @@ } | ||
constructor(config: ActivationLayerConfig); | ||
getClassName(): string; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
@@ -85,2 +89,3 @@ } | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -94,3 +99,4 @@ } | ||
computeOutputShape(inputShape: Shape): Shape; | ||
getClassName(): string; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
} |
@@ -13,3 +13,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var _ = require("underscore"); | ||
var tfjs_core_1 = require("@tensorflow/tfjs-core"); | ||
var activations_1 = require("../activations"); | ||
@@ -55,3 +55,4 @@ var K = require("../backend/tfjs_backend"); | ||
var input = generic_utils.getExactlyOneTensor(inputs); | ||
if (this.noiseShape != null && !_.isEqual(input.shape, this.noiseShape)) { | ||
if (this.noiseShape != null && | ||
!tfjs_core_1.util.arraysEqual(input.shape, this.noiseShape)) { | ||
throw new errors_1.NotImplementedError('Non-default noise shape is not implemented in Dropout layer yet: ' + | ||
@@ -68,2 +69,5 @@ JSON.stringify(this.noiseShape)); | ||
}; | ||
Dropout.prototype.getClassName = function () { | ||
return 'Dropout'; | ||
}; | ||
Dropout.prototype.getConfig = function () { | ||
@@ -148,2 +152,5 @@ var config = { | ||
}; | ||
Dense.prototype.getClassName = function () { | ||
return 'Dense'; | ||
}; | ||
Dense.prototype.getConfig = function () { | ||
@@ -190,2 +197,5 @@ var config = { | ||
}; | ||
Flatten.prototype.getClassName = function () { | ||
return 'Flatten'; | ||
}; | ||
Flatten.prototype.call = function (inputs, kwargs) { | ||
@@ -207,2 +217,5 @@ this.invokeCallHook(inputs, kwargs); | ||
} | ||
Activation.prototype.getClassName = function () { | ||
return 'Activation'; | ||
}; | ||
Activation.prototype.call = function (inputs, kwargs) { | ||
@@ -232,2 +245,5 @@ this.invokeCallHook(inputs, kwargs); | ||
}; | ||
RepeatVector.prototype.getClassName = function () { | ||
return 'RepeatVector'; | ||
}; | ||
RepeatVector.prototype.getConfig = function () { | ||
@@ -306,2 +322,5 @@ var config = { | ||
}; | ||
Reshape.prototype.getClassName = function () { | ||
return 'Reshape'; | ||
}; | ||
Reshape.prototype.call = function (inputs, kwargs) { | ||
@@ -308,0 +327,0 @@ this.invokeCallHook(inputs, kwargs); |
@@ -33,3 +33,4 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
} |
@@ -13,3 +13,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var _ = require("underscore"); | ||
var K = require("../backend/tfjs_backend"); | ||
@@ -71,4 +70,5 @@ var constraints_1 = require("../constraints"); | ||
var i = 0; | ||
for (var _i = 0, _a = _.zip(inLens, inputShape.slice(1)); _i < _a.length; _i++) { | ||
var _b = _a[_i], s1 = _b[0], s2 = _b[1]; | ||
for (var k = 0; k < inLens.length; ++k) { | ||
var s1 = inLens[k]; | ||
var s2 = inputShape[k + 1]; | ||
if ((s1 != null) && (s2 != null) && (s1 !== s2)) { | ||
@@ -95,2 +95,5 @@ throw new errors_1.ValueError("\"inputLength\" is " + this.inputLength + ", but received " + | ||
}; | ||
Embedding.prototype.getClassName = function () { | ||
return 'Embedding'; | ||
}; | ||
Embedding.prototype.getConfig = function () { | ||
@@ -97,0 +100,0 @@ var config = { |
@@ -7,2 +7,3 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
constructor(config?: LayerConfig); | ||
getClassName(): string; | ||
protected mergeFunction(inputs: Tensor[]): Tensor; | ||
@@ -16,2 +17,3 @@ private computeElementwiseOpOutputShape(shape1, shape2); | ||
constructor(config?: LayerConfig); | ||
getClassName(): string; | ||
protected mergeFunction(inputs: Tensor[]): Tensor; | ||
@@ -22,2 +24,3 @@ } | ||
constructor(config?: LayerConfig); | ||
getClassName(): string; | ||
protected mergeFunction(inputs: Tensor[]): Tensor; | ||
@@ -28,2 +31,3 @@ } | ||
constructor(config?: LayerConfig); | ||
getClassName(): string; | ||
protected mergeFunction(inputs: Tensor[]): Tensor; | ||
@@ -34,2 +38,3 @@ } | ||
constructor(config?: LayerConfig); | ||
getClassName(): string; | ||
protected mergeFunction(inputs: Tensor[]): Tensor; | ||
@@ -40,2 +45,3 @@ } | ||
constructor(config?: LayerConfig); | ||
getClassName(): string; | ||
protected mergeFunction(inputs: Tensor[]): Tensor; | ||
@@ -51,2 +57,3 @@ } | ||
constructor(config?: ConcatenateLayerConfig); | ||
getClassName(): string; | ||
build(inputShape: Shape | Shape[]): void; | ||
@@ -53,0 +60,0 @@ protected mergeFunction(inputs: Tensor[]): Tensor; |
@@ -13,3 +13,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var _ = require("underscore"); | ||
var tfjs_core_1 = require("@tensorflow/tfjs-core"); | ||
var K = require("../backend/tfjs_backend"); | ||
@@ -27,2 +27,5 @@ var topology_1 = require("../engine/topology"); | ||
} | ||
Merge.prototype.getClassName = function () { | ||
return 'Merge'; | ||
}; | ||
Merge.prototype.mergeFunction = function (inputs) { | ||
@@ -80,3 +83,3 @@ throw new errors_1.NotImplementedError(); | ||
} | ||
batchSizes = _.uniq(batchSizes); | ||
batchSizes = generic_utils.unique(batchSizes); | ||
if (batchSizes.length > 1) { | ||
@@ -92,3 +95,4 @@ throw new errors_1.ValueError("Can not merge tensors with different batch sizes. " + | ||
var allRanks = inputShape.map(function (shape) { return shape.length; }); | ||
if (!_.contains(inputShape, null) && _.uniq(allRanks).length === 1) { | ||
if (inputShape.indexOf(null) === -1 && | ||
generic_utils.unique(allRanks).length === 1) { | ||
this.reshapeRequired = false; | ||
@@ -105,4 +109,4 @@ } | ||
var inputDims = inputs.map(function (input) { return K.ndim(input); }); | ||
if (!_.contains(inputDims, null)) { | ||
var maxNDim = _.max(inputDims); | ||
if (inputDims.indexOf(null) === -1) { | ||
var maxNDim = mathUtils.max(inputDims); | ||
for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) { | ||
@@ -134,3 +138,3 @@ var x = inputs_1[_i]; | ||
else if (xNDim > 1) { | ||
var dims = _.range(1, xNDim).concat([0]); | ||
var dims = mathUtils.range(1, xNDim).concat([0]); | ||
reshapedInputs.push(K.permuteDimensions(x, dims)); | ||
@@ -154,3 +158,3 @@ transposed = true; | ||
else if (yNDim > 1) { | ||
var dims = [yNDim - 1].concat(_.range(0, yNDim - 1)); | ||
var dims = [yNDim - 1].concat(mathUtils.range(0, yNDim - 1)); | ||
y = K.permuteDimensions(y, dims); | ||
@@ -186,3 +190,3 @@ } | ||
} | ||
batchSizes = _.uniq(batchSizes); | ||
batchSizes = generic_utils.unique(batchSizes); | ||
if (batchSizes.length === 1) { | ||
@@ -204,2 +208,5 @@ outputShape = batchSizes.concat(outputShape); | ||
} | ||
Add.prototype.getClassName = function () { | ||
return 'Add'; | ||
}; | ||
Add.prototype.mergeFunction = function (inputs) { | ||
@@ -232,2 +239,5 @@ var output = K.zeros(inputs[0].shape); | ||
} | ||
Multiply.prototype.getClassName = function () { | ||
return 'Multiply'; | ||
}; | ||
Multiply.prototype.mergeFunction = function (inputs) { | ||
@@ -260,2 +270,5 @@ var output = K.ones(inputs[0].shape); | ||
} | ||
Average.prototype.getClassName = function () { | ||
return 'Average'; | ||
}; | ||
Average.prototype.mergeFunction = function (inputs) { | ||
@@ -288,2 +301,5 @@ var output = K.zeros(inputs[0].shape); | ||
} | ||
Maximum.prototype.getClassName = function () { | ||
return 'Maximum'; | ||
}; | ||
Maximum.prototype.mergeFunction = function (inputs) { | ||
@@ -315,2 +331,5 @@ var output = inputs[0]; | ||
} | ||
Minimum.prototype.getClassName = function () { | ||
return 'Minimum'; | ||
}; | ||
Minimum.prototype.mergeFunction = function (inputs) { | ||
@@ -350,2 +369,5 @@ var output = inputs[0]; | ||
} | ||
Concatenate.prototype.getClassName = function () { | ||
return 'Concatenate'; | ||
}; | ||
Concatenate.prototype.build = function (inputShape) { | ||
@@ -376,3 +398,3 @@ if (!(Array.isArray(inputShape) && Array.isArray(inputShape[0])) || | ||
var shape = shapeSet_1[_a]; | ||
if (_.isEqual(shape, shapeWithoutConcatAxis)) { | ||
if (tfjs_core_1.util.arraysEqual(shape, shapeWithoutConcatAxis)) { | ||
exists = true; | ||
@@ -379,0 +401,0 @@ break; |
@@ -41,6 +41,8 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
private movingVariance; | ||
private stepCount; | ||
constructor(config: BatchNormalizationLayerConfig); | ||
build(inputShape: Shape | Shape[]): void; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
} |
@@ -13,3 +13,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var _ = require("underscore"); | ||
var tfjs_core_1 = require("@tensorflow/tfjs-core"); | ||
var K = require("../backend/tfjs_backend"); | ||
@@ -22,2 +22,3 @@ var constraints_1 = require("../constraints"); | ||
var generic_utils = require("../utils/generic_utils"); | ||
var math_utils_1 = require("../utils/math_utils"); | ||
var BatchNormalization = (function (_super) { | ||
@@ -43,2 +44,3 @@ __extends(BatchNormalization, _super); | ||
_this.gammaRegularizer = regularizers_1.getRegularizer(config.gammaRegularizer); | ||
_this.stepCount = 0; | ||
return _this; | ||
@@ -71,32 +73,47 @@ } | ||
var _this = this; | ||
var training = kwargs['training'] == null ? false : kwargs['training']; | ||
var input = generic_utils.getExactlyOneTensor(inputs); | ||
var inputShape = K.shape(input); | ||
var ndim = inputShape.length; | ||
var reductionAxes = _.range(ndim); | ||
var axis = this.axis >= 0 ? this.axis : (this.axis + ndim); | ||
reductionAxes.splice(axis, 1); | ||
var broadcastShape = generic_utils.pyListRepeat(1, ndim); | ||
broadcastShape[axis] = inputShape[axis]; | ||
var sortedReductionAxes = reductionAxes.slice(); | ||
sortedReductionAxes.sort(); | ||
var needsBroadcasting = !_.isEqual(sortedReductionAxes, _.range(ndim).slice(0, ndim - 1)); | ||
var normalizeInference = function () { | ||
if (needsBroadcasting) { | ||
var broadcastMovingMean = K.reshape(_this.movingMean.read(), broadcastShape); | ||
var broadcastMovingVariance = K.reshape(_this.movingVariance.read(), broadcastShape); | ||
var broadcastBeta = _this.center ? K.reshape(_this.beta.read(), broadcastShape) : null; | ||
var broadcastGamma = _this.scale ? K.reshape(_this.gamma.read(), broadcastShape) : null; | ||
return K.batchNormalization(input, broadcastMovingMean, broadcastMovingVariance, broadcastBeta, broadcastGamma, _this.epsilon); | ||
return tfjs_core_1.tidy(function () { | ||
var training = kwargs['training'] == null ? false : kwargs['training']; | ||
var input = generic_utils.getExactlyOneTensor(inputs); | ||
var inputShape = K.shape(input); | ||
var ndim = inputShape.length; | ||
var reductionAxes = math_utils_1.range(0, ndim); | ||
var axis = _this.axis >= 0 ? _this.axis : (_this.axis + ndim); | ||
reductionAxes.splice(axis, 1); | ||
var broadcastShape = generic_utils.pyListRepeat(1, ndim); | ||
broadcastShape[axis] = inputShape[axis]; | ||
var sortedReductionAxes = reductionAxes.slice(); | ||
sortedReductionAxes.sort(); | ||
var needsBroadcasting = !tfjs_core_1.util.arraysEqual(sortedReductionAxes, math_utils_1.range(0, ndim).slice(0, ndim - 1)); | ||
var normalizeInference = function () { | ||
if (needsBroadcasting) { | ||
var broadcastMovingMean = K.reshape(_this.movingMean.read(), broadcastShape); | ||
var broadcastMovingVariance = K.reshape(_this.movingVariance.read(), broadcastShape); | ||
var broadcastBeta = _this.center ? K.reshape(_this.beta.read(), broadcastShape) : null; | ||
var broadcastGamma = _this.scale ? K.reshape(_this.gamma.read(), broadcastShape) : null; | ||
return K.batchNormalization(input, broadcastMovingMean, broadcastMovingVariance, broadcastBeta, broadcastGamma, _this.epsilon); | ||
} | ||
else { | ||
return K.batchNormalization(input, _this.movingMean.read(), _this.movingVariance.read(), _this.beta == null ? null : _this.beta.read(), _this.gamma == null ? null : _this.gamma.read(), _this.epsilon); | ||
} | ||
}; | ||
if (!training) { | ||
return normalizeInference(); | ||
} | ||
else { | ||
return K.batchNormalization(input, _this.movingMean.read(), _this.movingVariance.read(), _this.beta == null ? null : _this.beta.read(), _this.gamma == null ? null : _this.gamma.read(), _this.epsilon); | ||
} | ||
}; | ||
if (!training) { | ||
return normalizeInference(); | ||
} | ||
throw new errors_1.NotImplementedError('BatchNormalization.call() has not been implemented for training ' + | ||
'mode yet.'); | ||
var _a = K.normalizeBatchInTraining(input, _this.gamma.read(), _this.beta.read(), reductionAxes, _this.epsilon), normedTraining = _a[0], mean = _a[1], variance = _a[2]; | ||
var sampleSize = math_utils_1.arrayProd(reductionAxes.map(function (axis) { return input.shape[axis]; })); | ||
var varianceDebiased = variance.mul(K.getScalar(sampleSize / (sampleSize - (1 + _this.epsilon)))); | ||
var updateMovingMeanAndVariance = function () { | ||
_this.stepCount++; | ||
var newMovingMean = tfjs_core_1.movingAverage(_this.movingMean.read(), mean, _this.momentum, _this.stepCount); | ||
_this.movingMean.write(newMovingMean); | ||
var newMovingVariance = tfjs_core_1.movingAverage(_this.movingVariance.read(), varianceDebiased, _this.momentum, _this.stepCount); | ||
_this.movingVariance.write(newMovingVariance); | ||
}; | ||
updateMovingMeanAndVariance(); | ||
return normedTraining; | ||
}); | ||
}; | ||
BatchNormalization.prototype.getClassName = function () { | ||
return 'BatchNormalization'; | ||
}; | ||
BatchNormalization.prototype.getConfig = function () { | ||
@@ -103,0 +120,0 @@ var config = { |
@@ -15,3 +15,4 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
} |
@@ -105,2 +105,5 @@ "use strict"; | ||
}; | ||
ZeroPadding2D.prototype.getClassName = function () { | ||
return 'ZeroPadding2D'; | ||
}; | ||
ZeroPadding2D.prototype.getConfig = function () { | ||
@@ -107,0 +110,0 @@ var config = { |
@@ -22,2 +22,3 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
constructor(config: Pooling1DLayerConfig); | ||
getClassName(): string; | ||
protected poolingFunction(inputs: Tensor, poolSize: [number, number], strides: [number, number], padding: PaddingMode, dataFormat: DataFormat): Tensor; | ||
@@ -27,2 +28,3 @@ } | ||
constructor(config: Pooling1DLayerConfig); | ||
getClassName(): string; | ||
protected poolingFunction(inputs: Tensor, poolSize: [number, number], strides: [number, number], padding: PaddingMode, dataFormat: DataFormat): Tensor; | ||
@@ -49,2 +51,3 @@ } | ||
constructor(config: Pooling2DLayerConfig); | ||
getClassName(): string; | ||
protected poolingFunction(inputs: Tensor, poolSize: [number, number], strides: [number, number], padding: PaddingMode, dataFormat: DataFormat): Tensor; | ||
@@ -54,2 +57,3 @@ } | ||
constructor(config: Pooling2DLayerConfig); | ||
getClassName(): string; | ||
protected poolingFunction(inputs: Tensor, poolSize: [number, number], strides: [number, number], padding: PaddingMode, dataFormat: DataFormat): Tensor; | ||
@@ -64,2 +68,3 @@ } | ||
constructor(config: LayerConfig); | ||
getClassName(): string; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
@@ -69,2 +74,3 @@ } | ||
constructor(config: LayerConfig); | ||
getClassName(): string; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
@@ -84,5 +90,7 @@ } | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
} | ||
export declare class GlobalMaxPooling2D extends GlobalPooling2D { | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
} |
@@ -64,2 +64,5 @@ "use strict"; | ||
} | ||
MaxPooling1D.prototype.getClassName = function () { | ||
return 'MaxPooling1D'; | ||
}; | ||
MaxPooling1D.prototype.poolingFunction = function (inputs, poolSize, strides, padding, dataFormat) { | ||
@@ -79,2 +82,5 @@ common_1.checkDataFormat(dataFormat); | ||
} | ||
AveragePooling1D.prototype.getClassName = function () { | ||
return 'AveragePooling1D'; | ||
}; | ||
AveragePooling1D.prototype.poolingFunction = function (inputs, poolSize, strides, padding, dataFormat) { | ||
@@ -147,2 +153,5 @@ common_1.checkDataFormat(dataFormat); | ||
} | ||
MaxPooling2D.prototype.getClassName = function () { | ||
return 'MaxPooling2D'; | ||
}; | ||
MaxPooling2D.prototype.poolingFunction = function (inputs, poolSize, strides, padding, dataFormat) { | ||
@@ -162,2 +171,5 @@ common_1.checkDataFormat(dataFormat); | ||
} | ||
AveragePooling2D.prototype.getClassName = function () { | ||
return 'AveragePooling2D'; | ||
}; | ||
AveragePooling2D.prototype.poolingFunction = function (inputs, poolSize, strides, padding, dataFormat) { | ||
@@ -193,2 +205,5 @@ common_1.checkDataFormat(dataFormat); | ||
} | ||
GlobalAveragePooling1D.prototype.getClassName = function () { | ||
return 'GlobalAveragePooling1D'; | ||
}; | ||
GlobalAveragePooling1D.prototype.call = function (inputs, kwargs) { | ||
@@ -207,2 +222,5 @@ var input = generic_utils.getExactlyOneTensor(inputs); | ||
} | ||
GlobalMaxPooling1D.prototype.getClassName = function () { | ||
return 'GlobalMaxPooling1D'; | ||
}; | ||
GlobalMaxPooling1D.prototype.call = function (inputs, kwargs) { | ||
@@ -261,2 +279,5 @@ var input = generic_utils.getExactlyOneTensor(inputs); | ||
}; | ||
GlobalAveragePooling2D.prototype.getClassName = function () { | ||
return 'GlobalAveragePooling2D'; | ||
}; | ||
return GlobalAveragePooling2D; | ||
@@ -280,2 +301,5 @@ }(GlobalPooling2D)); | ||
}; | ||
GlobalMaxPooling2D.prototype.getClassName = function () { | ||
return 'GlobalMaxPooling2D'; | ||
}; | ||
return GlobalMaxPooling2D; | ||
@@ -282,0 +306,0 @@ }(GlobalPooling2D)); |
@@ -50,2 +50,3 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
readonly nonTrainableWeights: LayerVariable[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -98,2 +99,3 @@ } | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -134,2 +136,3 @@ } | ||
readonly recurrentDropout: number; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -170,2 +173,3 @@ } | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -194,2 +198,3 @@ } | ||
readonly implementation: number; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -233,2 +238,3 @@ static fromConfig<T>(cls: generic_utils.Constructor<T>, config: ConfigDict): T; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -259,2 +265,3 @@ } | ||
readonly implementation: number; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -272,2 +279,3 @@ static fromConfig<T>(cls: generic_utils.Constructor<T>, config: ConfigDict): T; | ||
build(inputShape: Shape | Shape[]): void; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -274,0 +282,0 @@ static fromConfig<T>(cls: generic_utils.Constructor<T>, config: ConfigDict, customObjects?: ConfigDict): T; |
@@ -20,3 +20,2 @@ "use strict"; | ||
var tfjs_core_1 = require("@tensorflow/tfjs-core"); | ||
var _ = require("underscore"); | ||
var activations_1 = require("../activations"); | ||
@@ -69,3 +68,3 @@ var K = require("../backend/tfjs_backend"); | ||
var numStates = Array.isArray(this.cell.stateSize) ? this.cell.stateSize.length : 1; | ||
return _.range(numStates).map(function (x) { return null; }); | ||
return math_utils.range(0, numStates).map(function (x) { return null; }); | ||
} | ||
@@ -138,3 +137,3 @@ else { | ||
if (this.stateSpec != null) { | ||
if (!_.isEqual(this.stateSpec.map(function (spec) { return spec.shape[spec.shape.length - 1]; }), stateSize)) { | ||
if (!tfjs_core_1.util.arraysEqual(this.stateSpec.map(function (spec) { return spec.shape[spec.shape.length - 1]; }), stateSize)) { | ||
throw new errors_1.ValueError("An initialState was passed that is not compatible with " + | ||
@@ -197,3 +196,3 @@ ("cell.stateSize. Received stateSpec=" + this.stateSpec + "; ") + | ||
var expectedShape = [batchSize, dim]; | ||
if (!_.isEqual(value.shape, expectedShape)) { | ||
if (!tfjs_core_1.util.arraysEqual(value.shape, expectedShape)) { | ||
throw new errors_1.ValueError("State " + index + " is incompatible with layer " + this.name + ": " + | ||
@@ -355,2 +354,5 @@ ("expected shape=" + expectedShape + ", received shape=" + value.shape)); | ||
}); | ||
RNN.prototype.getClassName = function () { | ||
return 'RNN'; | ||
}; | ||
RNN.prototype.getConfig = function () { | ||
@@ -369,3 +371,3 @@ var config = { | ||
config.cell = { | ||
className: this.cell.constructor.name, | ||
className: this.cell.getClassName(), | ||
config: cellConfig, | ||
@@ -454,2 +456,5 @@ }; | ||
}; | ||
SimpleRNNCell.prototype.getClassName = function () { | ||
return 'SimpleRNNCell'; | ||
}; | ||
SimpleRNNCell.prototype.getConfig = function () { | ||
@@ -593,2 +598,5 @@ var config = { | ||
}); | ||
SimpleRNN.prototype.getClassName = function () { | ||
return 'SimpleRNN'; | ||
}; | ||
SimpleRNN.prototype.getConfig = function () { | ||
@@ -728,2 +736,5 @@ var config = { | ||
}; | ||
GRUCell.prototype.getClassName = function () { | ||
return 'GRUCell'; | ||
}; | ||
GRUCell.prototype.getConfig = function () { | ||
@@ -879,2 +890,5 @@ var config = { | ||
}); | ||
GRU.prototype.getClassName = function () { | ||
return 'GRU'; | ||
}; | ||
GRU.prototype.getConfig = function () { | ||
@@ -969,2 +983,5 @@ var config = { | ||
}; | ||
CustomInit.prototype.getClassName = function () { | ||
return 'CustomInit'; | ||
}; | ||
return CustomInit; | ||
@@ -1053,2 +1070,5 @@ }(initializers_1.Initializer)))(); | ||
}; | ||
LSTMCell.prototype.getClassName = function () { | ||
return 'LSTMCell'; | ||
}; | ||
LSTMCell.prototype.getConfig = function () { | ||
@@ -1212,2 +1232,5 @@ var config = { | ||
}); | ||
LSTM.prototype.getClassName = function () { | ||
return 'LSTM'; | ||
}; | ||
LSTM.prototype.getConfig = function () { | ||
@@ -1325,2 +1348,5 @@ var config = { | ||
}; | ||
StackedRNNCells.prototype.getClassName = function () { | ||
return 'StackedRNNCells'; | ||
}; | ||
StackedRNNCells.prototype.getConfig = function () { | ||
@@ -1331,3 +1357,3 @@ var cellConfigs = []; | ||
cellConfigs.push({ | ||
'className': this.constructor.name, | ||
'className': this.getClassName(), | ||
'config': cell.getConfig(), | ||
@@ -1334,0 +1360,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import { ConfigDict } from '../types'; | ||
export declare function deserialize(config: ConfigDict, customObjects?: ConfigDict): any; | ||
import { ConfigDict, Serializable } from '../types'; | ||
export declare function deserialize(config: ConfigDict, customObjects?: ConfigDict): Serializable; |
@@ -29,2 +29,3 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getClassName(): string; | ||
} | ||
@@ -59,2 +60,3 @@ export declare enum BidirectionalMergeMode { | ||
readonly nonTrainableWeights: LayerVariable[]; | ||
getClassName(): string; | ||
} |
@@ -82,3 +82,3 @@ "use strict"; | ||
'layer': { | ||
'className': this.layer.constructor.name, | ||
'className': this.layer.getClassName(), | ||
'config': this.layer.getConfig(), | ||
@@ -142,2 +142,5 @@ } | ||
}; | ||
TimeDistributed.prototype.getClassName = function () { | ||
return 'TimeDistributed'; | ||
}; | ||
return TimeDistributed; | ||
@@ -168,3 +171,4 @@ }(Wrapper)); | ||
layerConfig['goBackwards'] === true ? false : true; | ||
_this.backwardLayer = serialization_1.deserialize({ className: config.layer.constructor.name, config: layerConfig }); | ||
_this.backwardLayer = | ||
serialization_1.deserialize({ className: config.layer.getClassName(), config: layerConfig }); | ||
_this.forwardLayer.name = 'forward_' + _this.forwardLayer.name; | ||
@@ -338,2 +342,5 @@ _this.backwardLayer.name = 'backward_' + _this.backwardLayer.name; | ||
}); | ||
Bidirectional.prototype.getClassName = function () { | ||
return 'Bidirectional'; | ||
}; | ||
return Bidirectional; | ||
@@ -340,0 +347,0 @@ }(Wrapper)); |
@@ -28,2 +28,2 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
export declare const cosine: typeof cosineProximity; | ||
export declare function get(identifier: string): LossOrMetricFn; | ||
export declare function get(identifierOrFn: string | LossOrMetricFn): LossOrMetricFn; |
@@ -99,3 +99,3 @@ "use strict"; | ||
exports.cosine = cosineProximity; | ||
function get(identifier) { | ||
function get(identifierOrFn) { | ||
var lossesMap = { | ||
@@ -117,7 +117,12 @@ meanSquaredError: meanSquaredError, | ||
}; | ||
if (identifier in lossesMap) { | ||
return lossesMap[identifier]; | ||
if (typeof identifierOrFn === 'string') { | ||
if (identifierOrFn in lossesMap) { | ||
return lossesMap[identifierOrFn]; | ||
} | ||
throw new errors_1.ValueError("Unknown loss " + identifierOrFn); | ||
} | ||
throw new errors_1.ValueError("Unknown loss " + identifier); | ||
else { | ||
return identifierOrFn; | ||
} | ||
} | ||
exports.get = get; |
import { Tensor } from '@tensorflow/tfjs-core'; | ||
import { cosineProximity, meanAbsoluteError, meanAbsolutePercentageError, meanSquaredError } from './losses'; | ||
import { categoricalCrossentropy as categoricalCrossentropyLoss, cosineProximity, meanAbsoluteError, meanAbsolutePercentageError, meanSquaredError, sparseCategoricalCrossentropy as sparseCategoricalCrossentropyLoss } from './losses'; | ||
import { LossOrMetricFn } from './types'; | ||
@@ -7,5 +7,3 @@ export declare function binaryAccuracy(yTrue: Tensor, yPred: Tensor): Tensor; | ||
export declare function binaryCrossentropy(yTrue: Tensor, yPred: Tensor): Tensor; | ||
export declare function categoricalCrossentropy(yTrue: Tensor, yPred: Tensor): Tensor; | ||
export declare function sparseCategoricalAccuracy(yTrue: Tensor, yPred: Tensor): Tensor; | ||
export declare function sparseCategoricalCrossentropy(yTrue: Tensor, yPred: Tensor): Tensor; | ||
export declare function topKCategoricalAccuracy(yTrue: Tensor, yPred: Tensor): Tensor; | ||
@@ -19,3 +17,5 @@ export declare function sparseTopKCategoricalAccuracy(yTrue: Tensor, yPred: Tensor): Tensor; | ||
export declare const MAPE: typeof meanAbsolutePercentageError; | ||
export declare const categoricalCrossentropy: typeof categoricalCrossentropyLoss; | ||
export declare const cosine: typeof cosineProximity; | ||
export declare const sparseCategoricalCrossentropy: typeof sparseCategoricalCrossentropyLoss; | ||
export declare function get(identifier: string | LossOrMetricFn): LossOrMetricFn; |
@@ -18,9 +18,5 @@ "use strict"; | ||
function binaryCrossentropy(yTrue, yPred) { | ||
throw new errors_1.NotImplementedError(); | ||
return K.mean(K.binaryCrossentropy(yTrue, yPred), -1); | ||
} | ||
exports.binaryCrossentropy = binaryCrossentropy; | ||
function categoricalCrossentropy(yTrue, yPred) { | ||
throw new errors_1.NotImplementedError(); | ||
} | ||
exports.categoricalCrossentropy = categoricalCrossentropy; | ||
function sparseCategoricalAccuracy(yTrue, yPred) { | ||
@@ -30,6 +26,2 @@ throw new errors_1.NotImplementedError(); | ||
exports.sparseCategoricalAccuracy = sparseCategoricalAccuracy; | ||
function sparseCategoricalCrossentropy(yTrue, yPred) { | ||
throw new errors_1.NotImplementedError(); | ||
} | ||
exports.sparseCategoricalCrossentropy = sparseCategoricalCrossentropy; | ||
function topKCategoricalAccuracy(yTrue, yPred) { | ||
@@ -49,3 +41,5 @@ throw new errors_1.NotImplementedError(); | ||
exports.MAPE = losses_1.meanAbsolutePercentageError; | ||
exports.categoricalCrossentropy = losses_1.categoricalCrossentropy; | ||
exports.cosine = losses_1.cosineProximity; | ||
exports.sparseCategoricalCrossentropy = losses_1.sparseCategoricalCrossentropy; | ||
function get(identifier) { | ||
@@ -55,2 +49,4 @@ var metricsMap = { | ||
categoricalAccuracy: categoricalAccuracy, | ||
categoricalCrossentropy: exports.categoricalCrossentropy, | ||
sparseCategoricalCrossentropy: exports.sparseCategoricalCrossentropy, | ||
mse: exports.mse, | ||
@@ -57,0 +53,0 @@ MSE: exports.MSE, |
@@ -23,2 +23,3 @@ import { Scalar, Tensor, WeightsManifestConfig } from '@tensorflow/tfjs-core'; | ||
constructor(config?: SequentialConfig); | ||
getClassName(): string; | ||
add(layer: Layer): void; | ||
@@ -40,2 +41,3 @@ pop(): void; | ||
static fromConfig<T>(cls: generic_utils.Constructor<T>, config: ConfigDict): T; | ||
getConfig(): any; | ||
} |
@@ -138,2 +138,5 @@ "use strict"; | ||
Sequential_1 = Sequential; | ||
Sequential.prototype.getClassName = function () { | ||
return 'Sequential'; | ||
}; | ||
Sequential.prototype.add = function (layer) { | ||
@@ -322,2 +325,13 @@ if (this.outputs.length === 0) { | ||
}; | ||
Sequential.prototype.getConfig = function () { | ||
var config = []; | ||
for (var _i = 0, _a = this.layers; _i < _a.length; _i++) { | ||
var layer = _a[_i]; | ||
config.push({ | ||
className: layer.getClassName(), | ||
config: layer.getConfig(), | ||
}); | ||
} | ||
return config; | ||
}; | ||
__decorate([ | ||
@@ -324,0 +338,0 @@ tfjs_core_1.doc({ heading: 'Models', subheading: 'Classes' }) |
import { Scalar, Tensor } from '@tensorflow/tfjs-core'; | ||
import { ConfigDict, ConfigDictValue } from './types'; | ||
import { ConfigDict, ConfigDictValue, Serializable } from './types'; | ||
import * as generic_utils from './utils/generic_utils'; | ||
export declare abstract class Regularizer { | ||
export declare abstract class Regularizer extends Serializable { | ||
abstract apply(x: Tensor): Scalar; | ||
@@ -24,2 +24,3 @@ } | ||
apply(x: Tensor): Scalar; | ||
getClassName(): string; | ||
getConfig(): ConfigDict; | ||
@@ -26,0 +27,0 @@ static fromConfig(cls: generic_utils.Constructor<L1L2>, config: ConfigDict): L1L2; |
@@ -21,8 +21,11 @@ "use strict"; | ||
var K = require("./backend/tfjs_backend"); | ||
var types_1 = require("./types"); | ||
var generic_utils_1 = require("./utils/generic_utils"); | ||
var Regularizer = (function () { | ||
var Regularizer = (function (_super) { | ||
__extends(Regularizer, _super); | ||
function Regularizer() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
return Regularizer; | ||
}()); | ||
}(types_1.Serializable)); | ||
exports.Regularizer = Regularizer; | ||
@@ -53,2 +56,5 @@ var L1L2 = (function (_super) { | ||
}; | ||
L1L2.prototype.getClassName = function () { | ||
return 'L1L2'; | ||
}; | ||
L1L2.prototype.getConfig = function () { | ||
@@ -55,0 +61,0 @@ return { 'l1': this.l1.dataSync()[0], 'l2': this.l2.dataSync()[0] }; |
@@ -70,1 +70,5 @@ import * as tfc from '@tensorflow/tfjs-core'; | ||
}; | ||
export declare abstract class Serializable { | ||
abstract getClassName(): string; | ||
abstract getConfig(): ConfigDict; | ||
} |
@@ -96,1 +96,7 @@ "use strict"; | ||
exports.LayerVariable = LayerVariable; | ||
var Serializable = (function () { | ||
function Serializable() { | ||
} | ||
return Serializable; | ||
}()); | ||
exports.Serializable = Serializable; |
import { Tensor } from '@tensorflow/tfjs-core'; | ||
import { ConfigDict, ConfigDictValue, DType, Shape } from '../types'; | ||
import { ConfigDict, ConfigDictValue, DType, Serializable, Shape } from '../types'; | ||
export declare function pyListRepeat(value: any, numValues: number): any[]; | ||
@@ -35,6 +35,5 @@ export declare function pyGetAttr<T>(obj: any, attrName: string, defaultValue?: T): T; | ||
export declare function normalizeShapeList(x: Shape | Shape[]): Shape[]; | ||
export declare function isAllNullOrUndefined(iterableOrElement: {}): boolean; | ||
export declare function toSnakeCase(name: string): string; | ||
export declare function toCamelCase(identifier: string): string; | ||
export declare function serializeKerasObject(instance: any): ConfigDictValue; | ||
export declare function serializeKerasObject(instance: Serializable): ConfigDictValue; | ||
export declare function deserializeKerasObject(identifier: string | ConfigDict, moduleObjects?: { | ||
@@ -50,1 +49,4 @@ [objName: string]: any; | ||
export declare function stringToDType(dtype: string): DType; | ||
export declare function stringsEqual(xs: string[], ys: string[]): boolean; | ||
export declare function unique<T>(xs: T[]): T[]; | ||
export declare function isObjectEmpty(obj: {}): boolean; |
@@ -11,3 +11,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var _ = require("underscore"); | ||
var errors_1 = require("../errors"); | ||
@@ -34,3 +33,3 @@ var types_1 = require("../types"); | ||
} | ||
if (_.isUndefined(defaultValue)) { | ||
if (defaultValue === undefined) { | ||
throw new errors_1.AttributeError('pyGetAttr: Attempting to get attribute ' + attrName + | ||
@@ -172,6 +171,2 @@ 'with no default value defined'); | ||
exports.normalizeShapeList = normalizeShapeList; | ||
function isAllNullOrUndefined(iterableOrElement) { | ||
return _.every(toList(iterableOrElement), function (x) { return (_.isNull(x) || _.isUndefined(x)); }); | ||
} | ||
exports.isAllNullOrUndefined = isAllNullOrUndefined; | ||
function toSnakeCase(name) { | ||
@@ -201,9 +196,3 @@ var intermediate = name.replace(/(.)([A-Z][a-z0-9]+)/g, '$1_$2'); | ||
} | ||
if (instance.getConfig != null) { | ||
return { className: instance.constructor.name, config: instance.getConfig() }; | ||
} | ||
if (instance.name != null) { | ||
return instance.name; | ||
} | ||
throw new errors_1.ValueError("Cannot serialize " + instance); | ||
return { className: instance.getClassName(), config: instance.getConfig() }; | ||
} | ||
@@ -241,9 +230,9 @@ exports.serializeKerasObject = serializeKerasObject; | ||
var cls = void 0, fromConfig = void 0; | ||
if (_.has(customObjects, className)) { | ||
if (className in customObjects) { | ||
_a = customObjects.get(className), cls = _a[0], fromConfig = _a[1]; | ||
} | ||
else if (_.has(_GLOBAL_CUSTOM_OBJECTS, className)) { | ||
else if (className in _GLOBAL_CUSTOM_OBJECTS) { | ||
_b = _GLOBAL_CUSTOM_OBJECTS.className, cls = _b[0], fromConfig = _b[1]; | ||
} | ||
else if (_.has(moduleObjects, className)) { | ||
else if (className in moduleObjects) { | ||
_c = moduleObjects[className], cls = _c[0], fromConfig = _c[1]; | ||
@@ -335,1 +324,42 @@ } | ||
exports.stringToDType = stringToDType; | ||
function stringsEqual(xs, ys) { | ||
if (xs == null || ys == null) { | ||
return xs === ys; | ||
} | ||
if (xs.length !== ys.length) { | ||
return false; | ||
} | ||
for (var i = 0; i < xs.length; ++i) { | ||
if (xs[i] !== ys[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
exports.stringsEqual = stringsEqual; | ||
function unique(xs) { | ||
if (xs == null) { | ||
return xs; | ||
} | ||
var out = []; | ||
for (var _i = 0, xs_1 = xs; _i < xs_1.length; _i++) { | ||
var x = xs_1[_i]; | ||
if (out.indexOf(x) === -1) { | ||
out.push(x); | ||
} | ||
} | ||
return out; | ||
} | ||
exports.unique = unique; | ||
function isObjectEmpty(obj) { | ||
if (obj == null) { | ||
throw new errors_1.ValueError("Invalid value in obj: " + JSON.stringify(obj)); | ||
} | ||
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
exports.isObjectEmpty = isObjectEmpty; |
@@ -9,1 +9,2 @@ export declare type ArrayTypes = Uint8Array | Int32Array | Float32Array; | ||
export declare function variance(array: number[] | Float32Array): number; | ||
export declare function range(begin: number, end: number): number[]; |
@@ -5,2 +5,3 @@ "use strict"; | ||
var tfjs_core_1 = require("@tensorflow/tfjs-core"); | ||
var errors_1 = require("../errors"); | ||
function isInteger(x) { | ||
@@ -50,1 +51,12 @@ return x === parseInt(x.toString(), 10); | ||
exports.variance = variance; | ||
function range(begin, end) { | ||
if (end < begin) { | ||
throw new errors_1.ValueError("end (" + end + ") < begin (" + begin + ") is forbidden."); | ||
} | ||
var out = []; | ||
for (var i = begin; i < end; ++i) { | ||
out.push(i); | ||
} | ||
return out; | ||
} | ||
exports.range = range; |
@@ -6,7 +6,2 @@ "use strict"; | ||
var errors_1 = require("../errors"); | ||
var webgl2Features = [{ | ||
'BACKEND': 'webgl', | ||
'WEBGL_FLOAT_TEXTURE_ENABLED': true, | ||
'WEBGL_VERSION': 2 | ||
}]; | ||
function expectTensorsClose(actual, expected, epsilon) { | ||
@@ -37,3 +32,3 @@ if (actual == null) { | ||
beforeEach(function () { | ||
tfjs_backend_1.setBackend('cpu'); | ||
tfjs_backend_1.disposeScalarCache(); | ||
}); | ||
@@ -45,5 +40,5 @@ tests(); | ||
function describeMathGPU(testName, tests) { | ||
tfjs_core_1.test_util.describeWithFlags(testName, webgl2Features, function () { | ||
tfjs_core_1.test_util.describeWithFlags(testName, tfjs_core_1.test_util.WEBGL_ENVS, function () { | ||
beforeEach(function () { | ||
tfjs_backend_1.setBackend('webgl'); | ||
tfjs_backend_1.disposeScalarCache(); | ||
}); | ||
@@ -50,0 +45,0 @@ tests(); |
@@ -1,2 +0,2 @@ | ||
declare const version = "0.4.1"; | ||
declare const version = "0.5.0"; | ||
export { version }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var version = '0.4.1'; | ||
var version = '0.5.0'; | ||
exports.version = version; |
{ | ||
"name": "@tensorflow/tfjs-layers", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "TensorFlow layers API in JavaScript", | ||
@@ -9,5 +9,4 @@ "private": false, | ||
"devDependencies": { | ||
"@tensorflow/tfjs-core": "0.7.1", | ||
"@tensorflow/tfjs-core": "0.8.1", | ||
"@types/jasmine": "~2.5.53", | ||
"@types/underscore": "^1.8.7", | ||
"browserify": "~16.1.0", | ||
@@ -42,8 +41,5 @@ "clang-format": "~1.2.2", | ||
}, | ||
"dependencies": { | ||
"underscore": "~1.8.3" | ||
}, | ||
"peerDependencies": { | ||
"@tensorflow/tfjs-core": "0.7.1" | ||
"@tensorflow/tfjs-core": "0.8.1" | ||
} | ||
} |
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
2240806
1
22
38379
16
+ Added@tensorflow/tfjs-core@0.8.1(transitive)
- Removedunderscore@~1.8.3
- Removed@tensorflow/tfjs-core@0.7.1(transitive)
- Removedunderscore@1.8.3(transitive)