@tensorflow/tfjs-layers
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -751,6 +751,2 @@ "use strict"; | ||
common_1.checkDataFormat(dataFormat); | ||
if (dilationRate !== 1) { | ||
throw new errors_1.NotImplementedError("dilationRate = " + dilationRate + " is not implemented for 1D " + | ||
"convolution yet."); | ||
} | ||
if (x.shape.length !== 3) { | ||
@@ -775,3 +771,3 @@ throw new errors_1.ValueError("The input of a conv1dWithBias operation should be 3, but is " + | ||
} | ||
var y = tfc.conv1d(x, kernel, strides, padding === 'same' ? 'same' : 'valid'); | ||
var y = tfc.conv1d(x, kernel, strides, padding === 'same' ? 'same' : 'valid', 'NWC', dilationRate); | ||
if (bias != null) { | ||
@@ -805,5 +801,2 @@ y = biasAdd(y, bias); | ||
common_1.checkDataFormat(dataFormat); | ||
if (dilationRate != null) { | ||
throw new errors_1.NotImplementedError('Support for non-default dilation rate is not implemented yet.'); | ||
} | ||
if (ndim(x) !== 3 && ndim(x) !== 4) { | ||
@@ -822,3 +815,3 @@ throw new errors_1.ValueError("conv2dWithBias expects input to be of rank 3 or 4, but received " + | ||
} | ||
y = tfc.conv2d(y, kernel, strides, padding === 'same' ? 'same' : 'valid'); | ||
y = tfc.conv2d(y, kernel, strides, padding === 'same' ? 'same' : 'valid', 'NHWC', dilationRate); | ||
if (bias != null) { | ||
@@ -825,0 +818,0 @@ y = biasAdd(y, bias); |
@@ -42,3 +42,2 @@ import { Scalar, Tensor } from '@tensorflow/tfjs-core'; | ||
private totals; | ||
private scalarCache; | ||
constructor(); | ||
@@ -45,0 +44,0 @@ onEpochBegin(epoch: number, logs?: UnresolvedLogs): Promise<void>; |
@@ -281,5 +281,3 @@ "use strict"; | ||
function BaseLogger() { | ||
var _this = _super.call(this) || this; | ||
_this.scalarCache = {}; | ||
return _this; | ||
return _super.call(this) || this; | ||
} | ||
@@ -286,0 +284,0 @@ BaseLogger.prototype.onEpochBegin = function (epoch, logs) { |
@@ -11,3 +11,4 @@ export declare type DataFormat = 'channelsFirst' | 'channelsLast'; | ||
export declare function nameScope<T>(name: string, fn: () => T): T; | ||
export declare function getUniqueTensorName(prefix: string): string; | ||
export declare function getScopedTensorName(tensorName: string): string; | ||
export declare function getUniqueTensorName(scopedName: string): string; | ||
export declare function isValidTensorName(name: string): boolean; |
@@ -61,17 +61,25 @@ "use strict"; | ||
} | ||
function getUniqueTensorName(prefix) { | ||
if (!isValidTensorName(prefix)) { | ||
throw new Error('Not a valid tensor name: \'' + prefix + '\''); | ||
function getScopedTensorName(tensorName) { | ||
if (!isValidTensorName(tensorName)) { | ||
throw new Error('Not a valid tensor name: \'' + tensorName + '\''); | ||
} | ||
prefix = currentNameScopePrefix() + prefix; | ||
if (!nameMap.has(prefix)) { | ||
nameMap.set(prefix, 0); | ||
return currentNameScopePrefix() + tensorName; | ||
} | ||
exports.getScopedTensorName = getScopedTensorName; | ||
function getUniqueTensorName(scopedName) { | ||
if (!isValidTensorName(scopedName)) { | ||
throw new Error('Not a valid tensor name: \'' + scopedName + '\''); | ||
} | ||
var index = nameMap.get(prefix); | ||
nameMap.set(prefix, nameMap.get(prefix) + 1); | ||
if (!nameMap.has(scopedName)) { | ||
nameMap.set(scopedName, 0); | ||
} | ||
var index = nameMap.get(scopedName); | ||
nameMap.set(scopedName, nameMap.get(scopedName) + 1); | ||
if (index > 0) { | ||
return prefix + '_' + index; | ||
var result = scopedName + '_' + index; | ||
nameMap.set(result, 1); | ||
return result; | ||
} | ||
else { | ||
return prefix; | ||
return scopedName; | ||
} | ||
@@ -78,0 +86,0 @@ } |
@@ -908,4 +908,4 @@ "use strict"; | ||
throw new errors_1.ValueError("When passing validation data, it must contain 2 (valX, valY) " + | ||
"or 3 (valX, valY, valSampleWeight) items, however it contains " + | ||
(config.validationData.length + " items")); | ||
"or 3 (valX, valY, valSampleWeight) items; " + | ||
(config.validationData + " is invalid.")); | ||
} | ||
@@ -912,0 +912,0 @@ valStandardized = this.standardizeUserData(valX, valY, true, batchSize); |
@@ -6,3 +6,3 @@ import { Constraint, MaxNormConfig, MinMaxNormConfig, UnitNormConfig } from './constraints'; | ||
import { ELULayerConfig, LeakyReLULayerConfig, SoftmaxLayerConfig, ThresholdedReLULayerConfig } from './layers/advanced_activations'; | ||
import { ConvLayerConfig } from './layers/convolutional'; | ||
import { ConvLayerConfig, SeparableConvLayerConfig } from './layers/convolutional'; | ||
import { DepthwiseConv2DLayerConfig } from './layers/convolutional_depthwise'; | ||
@@ -38,2 +38,3 @@ import { ActivationLayerConfig, DenseLayerConfig, DropoutLayerConfig, RepeatVectorLayerConfig } from './layers/core'; | ||
static conv2dTranspose(config: ConvLayerConfig): Layer; | ||
static separableConv2d(config: SeparableConvLayerConfig): Layer; | ||
static depthwiseConv2d(config: DepthwiseConv2DLayerConfig): Layer; | ||
@@ -54,3 +55,7 @@ static activation(config: ActivationLayerConfig): Layer; | ||
static zeroPadding2d(config: ZeroPadding2DLayerConfig): Layer; | ||
static averagePooling1d(config: Pooling1DLayerConfig): Layer; | ||
static avgPool1d(config: Pooling1DLayerConfig): Layer; | ||
static avgPooling1d(config: Pooling1DLayerConfig): Layer; | ||
static averagePooling2d(config: Pooling2DLayerConfig): Layer; | ||
static avgPool2d(config: Pooling2DLayerConfig): Layer; | ||
static avgPooling2d(config: Pooling2DLayerConfig): Layer; | ||
@@ -57,0 +62,0 @@ static globalAveragePooling1d(config: LayerConfig): Layer; |
@@ -93,2 +93,5 @@ "use strict"; | ||
}; | ||
LayerExports.separableConv2d = function (config) { | ||
return new convolutional_1.SeparableConv2D(config); | ||
}; | ||
LayerExports.depthwiseConv2d = function (config) { | ||
@@ -139,7 +142,19 @@ return new convolutional_depthwise_1.DepthwiseConv2D(config); | ||
}; | ||
LayerExports.averagePooling1d = function (config) { | ||
return new pooling_1.AveragePooling1D(config); | ||
}; | ||
LayerExports.avgPool1d = function (config) { | ||
return LayerExports.averagePooling1d(config); | ||
}; | ||
LayerExports.avgPooling1d = function (config) { | ||
return new pooling_1.AvgPooling1D(config); | ||
return LayerExports.averagePooling1d(config); | ||
}; | ||
LayerExports.averagePooling2d = function (config) { | ||
return new pooling_1.AveragePooling2D(config); | ||
}; | ||
LayerExports.avgPool2d = function (config) { | ||
return LayerExports.averagePooling2d(config); | ||
}; | ||
LayerExports.avgPooling2d = function (config) { | ||
return new pooling_1.AvgPooling2D(config); | ||
return LayerExports.averagePooling2d(config); | ||
}; | ||
@@ -274,2 +289,11 @@ LayerExports.globalAveragePooling1d = function (config) { | ||
namespace: 'layers', | ||
useDocsFrom: 'SeparableConv2D', | ||
configParamIndices: [0] | ||
}) | ||
], LayerExports, "separableConv2d", null); | ||
__decorate([ | ||
tfjs_core_1.doc({ | ||
heading: 'Layers', | ||
subheading: 'Convolutional', | ||
namespace: 'layers', | ||
useDocsFrom: 'DepthwiseConv2D', | ||
@@ -410,6 +434,6 @@ configParamIndices: [0] | ||
namespace: 'layers', | ||
useDocsFrom: 'AvgPooling1D', | ||
useDocsFrom: 'AveragePooling1D', | ||
configParamIndices: [0] | ||
}) | ||
], LayerExports, "avgPooling1d", null); | ||
], LayerExports, "averagePooling1d", null); | ||
__decorate([ | ||
@@ -420,6 +444,6 @@ tfjs_core_1.doc({ | ||
namespace: 'layers', | ||
useDocsFrom: 'AvgPooling2D', | ||
useDocsFrom: 'AveragePooling2D', | ||
configParamIndices: [0] | ||
}) | ||
], LayerExports, "avgPooling2d", null); | ||
], LayerExports, "averagePooling2d", null); | ||
__decorate([ | ||
@@ -426,0 +450,0 @@ tfjs_core_1.doc({ |
@@ -16,3 +16,3 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
dataFormat?: DataFormat; | ||
dilationRate?: number | number[]; | ||
dilationRate?: number | [number, number]; | ||
activation?: string; | ||
@@ -35,3 +35,3 @@ useBias?: boolean; | ||
protected readonly dataFormat: DataFormat; | ||
protected readonly dilationRate: number | number[]; | ||
protected readonly dilationRate: number | [number, number]; | ||
protected readonly activation: ActivationFn; | ||
@@ -67,2 +67,31 @@ protected readonly useBias: boolean; | ||
} | ||
export interface SeparableConvLayerConfig extends ConvLayerConfig { | ||
depthMultiplier?: number; | ||
depthwiseInitializer?: InitializerIdentifier | Initializer; | ||
pointwiseInitializer?: InitializerIdentifier | Initializer; | ||
depthwiseRegularizer?: RegularizerIdentifier | Regularizer; | ||
pointwiseRegularizer?: RegularizerIdentifier | Regularizer; | ||
depthwiseConstraint?: ConstraintIdentifier | Constraint; | ||
pointwiseConstraint?: ConstraintIdentifier | Constraint; | ||
} | ||
export declare class SeparableConv extends Conv { | ||
readonly depthMultiplier: number; | ||
protected readonly depthwiseInitializer?: Initializer; | ||
protected readonly depthwiseRegularizer?: Regularizer; | ||
protected readonly depthwiseConstraint?: Constraint; | ||
protected readonly pointwiseInitializer?: Initializer; | ||
protected readonly pointwiseRegularizer?: Regularizer; | ||
protected readonly pointwiseConstraint?: Constraint; | ||
readonly DEFAULT_DEPTHWISE_INITIALIZER: InitializerIdentifier; | ||
readonly DEFAULT_POINTWISE_INITIALIZER: InitializerIdentifier; | ||
protected depthwiseKernel: LayerVariable; | ||
protected pointwiseKernel: LayerVariable; | ||
constructor(rank: number, config?: SeparableConvLayerConfig); | ||
build(inputShape: Shape | Shape[]): void; | ||
call(inputs: Tensor | Tensor[], kwargs: any): Tensor | Tensor[]; | ||
getConfig(): ConfigDict; | ||
} | ||
export declare class SeparableConv2D extends SeparableConv { | ||
constructor(config?: SeparableConvLayerConfig); | ||
} | ||
export declare class Conv1D extends Conv { | ||
@@ -69,0 +98,0 @@ constructor(config: ConvLayerConfig); |
@@ -14,3 +14,2 @@ "use strict"; | ||
var tfjs_core_1 = require("@tensorflow/tfjs-core"); | ||
var _ = require("underscore"); | ||
var activations_1 = require("../activations"); | ||
@@ -49,8 +48,15 @@ var K = require("../backend/tfjs_backend"); | ||
_this.dilationRate = config.dilationRate == null ? 1 : config.dilationRate; | ||
if (!(_this.dilationRate === 1 || | ||
(Array.isArray(_this.dilationRate) && | ||
_.isEqual(_.uniq(_this.dilationRate), [1])))) { | ||
throw new errors_1.NotImplementedError('Non-default dilation is not implemented for convolution layers ' + | ||
'yet.'); | ||
if (_this.rank === 1 && Array.isArray(_this.dilationRate)) { | ||
throw new errors_1.ValueError("dilationRate must be a number for 1D convolution, but " + | ||
("received " + JSON.stringify(_this.dilationRate))); | ||
} | ||
if (_this.rank === 2) { | ||
if (typeof _this.dilationRate === 'number') { | ||
_this.dilationRate = [_this.dilationRate, _this.dilationRate]; | ||
} | ||
else if (_this.dilationRate.length !== 2) { | ||
throw new errors_1.ValueError("dilationRate must be a number or array of two numbers for 2D " + | ||
("convolution, but received " + JSON.stringify(_this.dilationRate))); | ||
} | ||
} | ||
_this.activation = activations_1.getActivation(config.activation); | ||
@@ -90,6 +96,6 @@ _this.useBias = config.useBias == null ? true : config.useBias; | ||
if (this.rank === 1) { | ||
outputs = K.conv1dWithBias(inputs, this.kernel.read(), biasValue, this.strides[0], this.padding, this.dataFormat); | ||
outputs = K.conv1dWithBias(inputs, this.kernel.read(), biasValue, this.strides[0], this.padding, this.dataFormat, this.dilationRate); | ||
} | ||
else if (this.rank === 2) { | ||
outputs = K.conv2dWithBias(inputs, this.kernel.read(), biasValue, this.strides, this.padding, this.dataFormat); | ||
outputs = K.conv2dWithBias(inputs, this.kernel.read(), biasValue, this.strides, this.padding, this.dataFormat, this.dilationRate); | ||
} | ||
@@ -281,2 +287,124 @@ else if (this.rank === 3) { | ||
generic_utils.ClassNameMap.register('Conv2DTranspose', Conv2DTranspose); | ||
var SeparableConv = (function (_super) { | ||
__extends(SeparableConv, _super); | ||
function SeparableConv(rank, config) { | ||
var _this = _super.call(this, rank, config) || this; | ||
_this.DEFAULT_DEPTHWISE_INITIALIZER = 'glorotUniform'; | ||
_this.DEFAULT_POINTWISE_INITIALIZER = 'glorotUniform'; | ||
_this.depthwiseKernel = null; | ||
_this.pointwiseKernel = null; | ||
if (config.filters == null) { | ||
throw new errors_1.ValueError('The `filters` configuration field is required by SeparableConv, ' + | ||
'but is unspecified.'); | ||
} | ||
if (config.kernelInitializer != null || config.kernelRegularizer != null || | ||
config.kernelConstraint != null) { | ||
throw new errors_1.ValueError('Fields kernelInitializer, kernelRegularizer and kernelConstraint ' + | ||
'are invalid for SeparableConv2D. Use depthwiseInitializer, ' + | ||
'depthwiseRegularizer, depthwiseConstraint, pointwiseInitializer, ' + | ||
'pointwiseRegularizer and pointwiseConstraint instead.'); | ||
} | ||
if (config.padding != null && config.padding !== 'same' && | ||
config.padding !== 'valid') { | ||
throw new errors_1.ValueError("SeparableConv" + _this.rank + "D supports only padding modes: " + | ||
("'same' and 'valid', but received " + JSON.stringify(config.padding))); | ||
} | ||
_this.depthMultiplier = | ||
config.depthMultiplier == null ? 1 : config.depthMultiplier; | ||
_this.depthwiseInitializer = initializers_1.getInitializer(config.depthwiseInitializer || _this.DEFAULT_DEPTHWISE_INITIALIZER); | ||
_this.depthwiseRegularizer = regularizers_1.getRegularizer(config.depthwiseRegularizer); | ||
_this.depthwiseConstraint = constraints_1.getConstraint(config.depthwiseConstraint); | ||
_this.pointwiseInitializer = initializers_1.getInitializer(config.depthwiseInitializer || _this.DEFAULT_POINTWISE_INITIALIZER); | ||
_this.pointwiseRegularizer = regularizers_1.getRegularizer(config.pointwiseRegularizer); | ||
_this.pointwiseConstraint = constraints_1.getConstraint(config.pointwiseConstraint); | ||
return _this; | ||
} | ||
SeparableConv.prototype.build = function (inputShape) { | ||
inputShape = generic_utils.getExactlyOneShape(inputShape); | ||
if (inputShape.length < this.rank + 2) { | ||
throw new errors_1.ValueError("Inputs to SeparableConv" + this.rank + "D should have rank " + | ||
(this.rank + 2 + ", but received input shape: ") + | ||
("" + JSON.stringify(inputShape))); | ||
} | ||
var channelAxis = this.dataFormat === 'channelsFirst' ? 1 : inputShape.length - 1; | ||
if (inputShape[channelAxis] == null || inputShape[channelAxis] < 0) { | ||
throw new errors_1.ValueError("The channel dimension of the inputs should be defined, " + | ||
("but found " + JSON.stringify(inputShape[channelAxis]))); | ||
} | ||
var inputDim = inputShape[channelAxis]; | ||
var depthwiseKernelShape = this.kernelSize.concat([inputDim, this.depthMultiplier]); | ||
var pointwiseKernelShape = []; | ||
for (var i = 0; i < this.rank; ++i) { | ||
pointwiseKernelShape.push(1); | ||
} | ||
pointwiseKernelShape.push(inputDim * this.depthMultiplier, this.filters); | ||
var trainable = true; | ||
this.depthwiseKernel = this.addWeight('depthwise_kernel', depthwiseKernelShape, types_1.DType.float32, this.depthwiseInitializer, this.depthwiseRegularizer, trainable, this.depthwiseConstraint); | ||
this.pointwiseKernel = this.addWeight('pointwise_kernel', pointwiseKernelShape, types_1.DType.float32, this.pointwiseInitializer, this.pointwiseRegularizer, trainable, this.pointwiseConstraint); | ||
if (this.useBias) { | ||
this.bias = this.addWeight('bias', [this.filters], types_1.DType.float32, this.biasInitializer, this.biasRegularizer, trainable, this.biasConstraint); | ||
} | ||
else { | ||
this.bias = null; | ||
} | ||
this.inputSpec = | ||
[new topology_1.InputSpec({ ndim: this.rank + 2, axes: (_a = {}, _a[channelAxis] = inputDim, _a) })]; | ||
this.built = true; | ||
var _a; | ||
}; | ||
SeparableConv.prototype.call = function (inputs, kwargs) { | ||
inputs = generic_utils.getExactlyOneTensor(inputs); | ||
var output; | ||
if (this.rank === 1) { | ||
throw new errors_1.NotImplementedError('1D separable convolution is not implemented yet.'); | ||
} | ||
else if (this.rank === 2) { | ||
if (this.dataFormat === 'channelsFirst') { | ||
inputs = K.transpose(inputs, [0, 2, 3, 1]); | ||
} | ||
output = tfjs_core_1.separableConv2d(inputs, this.depthwiseKernel.read(), this.pointwiseKernel.read(), this.strides, this.padding, this.dilationRate, 'NHWC'); | ||
} | ||
if (this.useBias) { | ||
output = K.biasAdd(output, this.bias.read(), this.dataFormat); | ||
} | ||
if (this.activation != null) { | ||
output = this.activation(output); | ||
} | ||
if (this.dataFormat === 'channelsFirst') { | ||
output = K.transpose(output, [0, 3, 1, 2]); | ||
} | ||
return output; | ||
}; | ||
SeparableConv.prototype.getConfig = function () { | ||
var config = _super.prototype.getConfig.call(this); | ||
delete config['rank']; | ||
delete config['kernelInitializer']; | ||
delete config['kernelRegularizer']; | ||
delete config['kernelConstraint']; | ||
config['depthwiseInitializer'] = | ||
initializers_1.serializeInitializer(this.depthwiseInitializer); | ||
config['pointwiseInitializer'] = | ||
initializers_1.serializeInitializer(this.pointwiseInitializer); | ||
config['depthwiseRegularizer'] = | ||
regularizers_1.serializeRegularizer(this.depthwiseRegularizer); | ||
config['pointwiseRegularizer'] = | ||
regularizers_1.serializeRegularizer(this.pointwiseRegularizer); | ||
config['depthwiseConstraint'] = | ||
constraints_1.serializeConstraint(this.depthwiseConstraint); | ||
config['pointwiseConstraint'] = | ||
constraints_1.serializeConstraint(this.pointwiseConstraint); | ||
return config; | ||
}; | ||
return SeparableConv; | ||
}(Conv)); | ||
exports.SeparableConv = SeparableConv; | ||
var SeparableConv2D = (function (_super) { | ||
__extends(SeparableConv2D, _super); | ||
function SeparableConv2D(config) { | ||
return _super.call(this, 2, config) || this; | ||
} | ||
return SeparableConv2D; | ||
}(SeparableConv)); | ||
exports.SeparableConv2D = SeparableConv2D; | ||
generic_utils.ClassNameMap.register('SeparableConv2D', SeparableConv2D); | ||
var Conv1D = (function (_super) { | ||
@@ -283,0 +411,0 @@ __extends(Conv1D, _super); |
@@ -24,3 +24,3 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
} | ||
export declare class AvgPooling1D extends Pooling1D { | ||
export declare class AveragePooling1D extends Pooling1D { | ||
constructor(config: Pooling1DLayerConfig); | ||
@@ -50,3 +50,3 @@ protected poolingFunction(inputs: Tensor, poolSize: [number, number], strides: [number, number], padding: PaddingMode, dataFormat: DataFormat): Tensor; | ||
} | ||
export declare class AvgPooling2D extends Pooling2D { | ||
export declare class AveragePooling2D extends Pooling2D { | ||
constructor(config: Pooling2DLayerConfig); | ||
@@ -53,0 +53,0 @@ protected poolingFunction(inputs: Tensor, poolSize: [number, number], strides: [number, number], padding: PaddingMode, dataFormat: DataFormat): Tensor; |
@@ -73,8 +73,8 @@ "use strict"; | ||
generic_utils.ClassNameMap.register('MaxPooling1D', MaxPooling1D); | ||
var AvgPooling1D = (function (_super) { | ||
__extends(AvgPooling1D, _super); | ||
function AvgPooling1D(config) { | ||
var AveragePooling1D = (function (_super) { | ||
__extends(AveragePooling1D, _super); | ||
function AveragePooling1D(config) { | ||
return _super.call(this, config) || this; | ||
} | ||
AvgPooling1D.prototype.poolingFunction = function (inputs, poolSize, strides, padding, dataFormat) { | ||
AveragePooling1D.prototype.poolingFunction = function (inputs, poolSize, strides, padding, dataFormat) { | ||
common_1.checkDataFormat(dataFormat); | ||
@@ -84,6 +84,6 @@ common_1.checkPaddingMode(padding); | ||
}; | ||
return AvgPooling1D; | ||
return AveragePooling1D; | ||
}(Pooling1D)); | ||
exports.AvgPooling1D = AvgPooling1D; | ||
generic_utils.ClassNameMap.register('AvgPooling1D', AvgPooling1D); | ||
exports.AveragePooling1D = AveragePooling1D; | ||
generic_utils.ClassNameMap.register('AveragePooling1D', AveragePooling1D); | ||
var Pooling2D = (function (_super) { | ||
@@ -156,8 +156,8 @@ __extends(Pooling2D, _super); | ||
generic_utils.ClassNameMap.register('MaxPooling2D', MaxPooling2D); | ||
var AvgPooling2D = (function (_super) { | ||
__extends(AvgPooling2D, _super); | ||
function AvgPooling2D(config) { | ||
var AveragePooling2D = (function (_super) { | ||
__extends(AveragePooling2D, _super); | ||
function AveragePooling2D(config) { | ||
return _super.call(this, config) || this; | ||
} | ||
AvgPooling2D.prototype.poolingFunction = function (inputs, poolSize, strides, padding, dataFormat) { | ||
AveragePooling2D.prototype.poolingFunction = function (inputs, poolSize, strides, padding, dataFormat) { | ||
common_1.checkDataFormat(dataFormat); | ||
@@ -167,6 +167,6 @@ common_1.checkPaddingMode(padding); | ||
}; | ||
return AvgPooling2D; | ||
return AveragePooling2D; | ||
}(Pooling2D)); | ||
exports.AvgPooling2D = AvgPooling2D; | ||
generic_utils.ClassNameMap.register('AvgPooling2D', AvgPooling2D); | ||
exports.AveragePooling2D = AveragePooling2D; | ||
generic_utils.ClassNameMap.register('AveragePooling2D', AveragePooling2D); | ||
var GlobalPooling1D = (function (_super) { | ||
@@ -173,0 +173,0 @@ __extends(GlobalPooling1D, _super); |
@@ -12,3 +12,2 @@ import { Tensor } from '@tensorflow/tfjs-core'; | ||
readonly layer: Layer; | ||
private inputMap; | ||
constructor(config: WrapperLayerConfig); | ||
@@ -15,0 +14,0 @@ build(inputShape: Shape | Shape[]): void; |
@@ -23,3 +23,2 @@ "use strict"; | ||
_this.layer = config.layer; | ||
_this.inputMap = {}; | ||
return _this; | ||
@@ -26,0 +25,0 @@ } |
@@ -64,5 +64,5 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var modelTopology, tsConfig, model, weightValues, skipMismatches, isNamedTensorMap; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
var modelTopology, tsConfig, model, weightValues, uniqueWeightValues, _i, _a, weight, skipMismatches, isNamedTensorMap; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
@@ -76,9 +76,14 @@ modelTopology = modelAndWeightsConfig.modelTopology; | ||
if (!(modelAndWeightsConfig.weightsManifest != null)) return [3, 2]; | ||
return [4, tfjs_core_1.loadWeights(modelAndWeightsConfig.weightsManifest, modelAndWeightsConfig.pathPrefix, model.weights.map(function (weight) { return weight.name; }))]; | ||
return [4, tfjs_core_1.loadWeights(modelAndWeightsConfig.weightsManifest, modelAndWeightsConfig.pathPrefix, model.weights.map(function (weight) { return weight.originalName; }))]; | ||
case 1: | ||
weightValues = _a.sent(); | ||
weightValues = _b.sent(); | ||
uniqueWeightValues = {}; | ||
for (_i = 0, _a = model.weights; _i < _a.length; _i++) { | ||
weight = _a[_i]; | ||
uniqueWeightValues[weight.name] = weightValues[weight.originalName]; | ||
} | ||
skipMismatches = null; | ||
isNamedTensorMap = true; | ||
model.loadWeights(weightValues, skipMismatches, isNamedTensorMap); | ||
_a.label = 2; | ||
model.loadWeights(uniqueWeightValues, skipMismatches, isNamedTensorMap); | ||
_b.label = 2; | ||
case 2: return [2, model]; | ||
@@ -85,0 +90,0 @@ } |
@@ -24,2 +24,3 @@ import * as tfc from '@tensorflow/tfjs-core'; | ||
readonly name?: string; | ||
readonly originalName?: string; | ||
nodeIndex: number; | ||
@@ -34,2 +35,3 @@ tensorIndex: number; | ||
readonly name?: string; | ||
readonly originalName?: string; | ||
protected val: Tensor; | ||
@@ -44,2 +46,3 @@ constructor(val: Tensor, name?: string); | ||
readonly name: string; | ||
readonly originalName: string; | ||
readonly trainable: boolean; | ||
@@ -46,0 +49,0 @@ protected readonly val: tfc.Variable; |
@@ -28,3 +28,4 @@ "use strict"; | ||
if (name != null) { | ||
this.name = common_1.getUniqueTensorName(name); | ||
this.originalName = common_1.getScopedTensorName(name); | ||
this.name = common_1.getUniqueTensorName(this.originalName); | ||
} | ||
@@ -45,3 +46,4 @@ } | ||
if (name != null) { | ||
this.name = common_1.getUniqueTensorName(name); | ||
this.originalName = common_1.getScopedTensorName(name); | ||
this.name = common_1.getUniqueTensorName(this.originalName); | ||
} | ||
@@ -74,4 +76,5 @@ } | ||
this.id = _nextUniqueTensorId++; | ||
this.name = | ||
common_1.getUniqueTensorName(name == null ? DEFAULT_VARIABLE_NAME_PREFIX : name); | ||
name = name == null ? DEFAULT_VARIABLE_NAME_PREFIX : name; | ||
this.originalName = common_1.getScopedTensorName(name); | ||
this.name = common_1.getUniqueTensorName(this.originalName); | ||
this.trainable = trainable; | ||
@@ -78,0 +81,0 @@ this.constraint = constraint; |
@@ -1,2 +0,2 @@ | ||
declare const version = "0.3.0"; | ||
declare const version = "0.4.0"; | ||
export { version }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var version = '0.3.0'; | ||
var version = '0.4.0'; | ||
exports.version = version; |
{ | ||
"name": "@tensorflow/tfjs-layers", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "TensorFlow layers API in JavaScript", | ||
@@ -9,3 +9,3 @@ "private": false, | ||
"devDependencies": { | ||
"@tensorflow/tfjs-core": "0.6.1", | ||
"@tensorflow/tfjs-core": "0.7.1", | ||
"@types/jasmine": "~2.5.53", | ||
@@ -29,5 +29,4 @@ "@types/underscore": "^1.8.7", | ||
"tslint": "~5.6.0", | ||
"tslint-no-circular-imports": "^0.2.1", | ||
"typedoc": "~0.8.0", | ||
"typescript": "2.4.2", | ||
"typescript": "2.7.2", | ||
"uglify-js": "~3.0.28", | ||
@@ -34,0 +33,0 @@ "watchify": "~3.9.0" |
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
2228617
23
38309