@tensorflow/tfjs-layers
Advanced tools
Comparing version 0.7.4 to 0.7.5
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var _epsilon = 1e-7; | ||
var tfjs_core_1 = require("@tensorflow/tfjs-core"); | ||
var _epsilon = tfjs_core_1.ENV.get('EPSILON'); | ||
function epsilon() { | ||
@@ -5,0 +6,0 @@ return _epsilon; |
import { Scalar, serialization, Tensor } from '@tensorflow/tfjs-core'; | ||
import { JsonDict, Kwargs, NamedTensorMap, Shape } from '../types'; | ||
import { LayerVariable } from '../variables'; | ||
import { Layer, Node, SymbolicTensor, DisposeResult } from './topology'; | ||
import { DisposeResult, Layer, Node, SymbolicTensor } from './topology'; | ||
export declare function loadWeightsFromJson(weightsJSON: JsonDict, layers: Layer[], skipMismatch?: boolean): void; | ||
@@ -55,2 +55,3 @@ export declare function loadWeightsFromNamedTensorMap(weights: NamedTensorMap, layers: Layer[], strict?: boolean): void; | ||
readonly stateful: boolean; | ||
resetStates(): void; | ||
} |
@@ -397,6 +397,3 @@ "use strict"; | ||
this.assertNotDisposed(); | ||
var result = { | ||
refCountAfterDispose: null, | ||
numDisposedVariables: 0 | ||
}; | ||
var result = { refCountAfterDispose: null, numDisposedVariables: 0 }; | ||
if (--this._refCount === 0) { | ||
@@ -923,2 +920,12 @@ for (var _i = 0, _a = this.layers; _i < _a.length; _i++) { | ||
}); | ||
Container.prototype.resetStates = function () { | ||
var _this = this; | ||
tfjs_core_1.tidy(function () { | ||
_this.layers.forEach(function (layer) { | ||
if (layer.stateful) { | ||
layer.resetStates(); | ||
} | ||
}); | ||
}); | ||
}; | ||
return Container; | ||
@@ -925,0 +932,0 @@ }(topology_1.Layer)); |
@@ -125,2 +125,3 @@ import { DataType, Scalar, serialization, Tensor } from '@tensorflow/tfjs-core'; | ||
readonly stateful: boolean; | ||
resetStates(): void; | ||
protected assertInputCompatibility(inputs: Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[]): void; | ||
@@ -127,0 +128,0 @@ call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[]; |
@@ -285,2 +285,8 @@ "use strict"; | ||
}); | ||
Layer.prototype.resetStates = function () { | ||
if (!this.stateful) { | ||
throw new Error('Cannot call the resetStates() method of a non-stateful Layer ' + | ||
'object.'); | ||
} | ||
}; | ||
Layer.prototype.assertInputCompatibility = function (inputs) { | ||
@@ -287,0 +293,0 @@ inputs = generic_utils.toList(inputs); |
@@ -346,2 +346,5 @@ "use strict"; | ||
})(ModelLoggingVerbosity = exports.ModelLoggingVerbosity || (exports.ModelLoggingVerbosity = {})); | ||
function checkBatchSize(batchSize) { | ||
tfc.util.assert(batchSize > 0 && Number.isInteger(batchSize), "batchSize is required to be a positive integer, but got " + batchSize); | ||
} | ||
var Model = (function (_super) { | ||
@@ -536,2 +539,3 @@ __extends(Model, _super); | ||
var batchSize = config.batchSize == null ? 32 : config.batchSize; | ||
checkBatchSize(batchSize); | ||
var standardizedOuts = this.standardizeUserData(x, y, true, batchSize); | ||
@@ -688,2 +692,3 @@ var ins = standardizedOuts[0].concat(standardizedOuts[1]); | ||
var batchSize = config.batchSize == null ? 32 : config.batchSize; | ||
checkBatchSize(batchSize); | ||
return this.predictLoop(x, batchSize); | ||
@@ -776,3 +781,5 @@ }; | ||
initialEpoch: initialEpoch, | ||
samples: numTrainSamples, | ||
steps: stepsPerEpoch, | ||
batchSize: batchSize, | ||
verbose: verbose, | ||
@@ -1002,3 +1009,7 @@ doValidation: doValidation, | ||
this.isTraining = true; | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, , 3, 4]); | ||
batchSize = config.batchSize == null ? 32 : config.batchSize; | ||
checkBatchSize(batchSize); | ||
standardizedOuts = this.standardizeUserData(x, y, false, batchSize); | ||
@@ -1008,2 +1019,5 @@ inputs = standardizedOuts[0]; | ||
doValidation = false; | ||
valX = void 0; | ||
valY = void 0; | ||
valIns = void 0; | ||
needValidationDisposal = false; | ||
@@ -1092,2 +1106,4 @@ if (config.validationData != null && config.validationData.length > 0) { | ||
outLabels = this.getDedupedMetricsNames(); | ||
valFunction = void 0; | ||
callbackMetrics = void 0; | ||
if (doValidation) { | ||
@@ -1106,3 +1122,3 @@ this.makeTestFunction(); | ||
return [4, this.fitLoop(trainFunction, ins, outLabels, batchSize, config.epochs, config.verbose, callbacks, valFunction, valIns, config.shuffle, callbackMetrics, config.initialEpoch, null, null, config.yieldEvery)]; | ||
case 1: | ||
case 2: | ||
out = _a.sent(); | ||
@@ -1116,2 +1132,6 @@ if (needValidationDisposal) { | ||
return [2, out]; | ||
case 3: | ||
this.isTraining = false; | ||
return [7]; | ||
case 4: return [2]; | ||
} | ||
@@ -1118,0 +1138,0 @@ }); |
import { InputLayerConfig } from './engine/input_layer'; | ||
import { Layer, LayerConfig } from './engine/topology'; | ||
import { input } from './exports'; | ||
import { ELULayerConfig, LeakyReLULayerConfig, SoftmaxLayerConfig, ThresholdedReLULayerConfig } from './layers/advanced_activations'; | ||
import { ELULayerConfig, LeakyReLULayerConfig, ReLULayerConfig, SoftmaxLayerConfig, ThresholdedReLULayerConfig } from './layers/advanced_activations'; | ||
import { ConvLayerConfig, Cropping2DLayerConfig, SeparableConvLayerConfig, UpSampling2DLayerConfig } from './layers/convolutional'; | ||
@@ -17,2 +17,3 @@ import { DepthwiseConv2DLayerConfig } from './layers/convolutional_depthwise'; | ||
export declare function elu(config?: ELULayerConfig): Layer; | ||
export declare function reLU(config?: ReLULayerConfig): Layer; | ||
export declare function leakyReLU(config?: LeakyReLULayerConfig): Layer; | ||
@@ -19,0 +20,0 @@ export declare function softmax(config?: SoftmaxLayerConfig): Layer; |
@@ -29,2 +29,6 @@ "use strict"; | ||
exports.elu = elu; | ||
function reLU(config) { | ||
return new advanced_activations_1.ReLU(config); | ||
} | ||
exports.reLU = reLU; | ||
function leakyReLU(config) { | ||
@@ -31,0 +35,0 @@ return new advanced_activations_1.LeakyReLU(config); |
import { serialization, Tensor } from '@tensorflow/tfjs-core'; | ||
import { Layer, LayerConfig } from '../engine/topology'; | ||
import { Kwargs, Shape } from '../types'; | ||
export interface ReLULayerConfig extends LayerConfig { | ||
maxValue?: number; | ||
} | ||
export declare class ReLU extends Layer { | ||
static className: string; | ||
maxValue: number; | ||
constructor(config?: ReLULayerConfig); | ||
call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[]; | ||
computeOutputShape(inputShape: Shape | Shape[]): Shape | Shape[]; | ||
getConfig(): serialization.ConfigDict; | ||
} | ||
export interface LeakyReLULayerConfig extends LayerConfig { | ||
@@ -5,0 +16,0 @@ alpha?: number; |
@@ -20,2 +20,34 @@ "use strict"; | ||
var types_utils_1 = require("../utils/types_utils"); | ||
var ReLU = (function (_super) { | ||
__extends(ReLU, _super); | ||
function ReLU(config) { | ||
var _this = _super.call(this, config == null ? {} : config) || this; | ||
_this.supportsMasking = true; | ||
if (config != null) { | ||
_this.maxValue = config.maxValue; | ||
} | ||
return _this; | ||
} | ||
ReLU.prototype.call = function (inputs, kwargs) { | ||
inputs = types_utils_1.getExactlyOneTensor(inputs); | ||
var output = tfjs_core_1.relu(inputs); | ||
if (this.maxValue != null) { | ||
output = tfjs_core_1.clipByValue(output, 0, this.maxValue); | ||
} | ||
return output; | ||
}; | ||
ReLU.prototype.computeOutputShape = function (inputShape) { | ||
return inputShape; | ||
}; | ||
ReLU.prototype.getConfig = function () { | ||
var config = { maxValue: this.maxValue }; | ||
var baseConfig = _super.prototype.getConfig.call(this); | ||
Object.assign(config, baseConfig); | ||
return config; | ||
}; | ||
ReLU.className = 'ReLU'; | ||
return ReLU; | ||
}(topology_1.Layer)); | ||
exports.ReLU = ReLU; | ||
tfjs_core_1.serialization.SerializationMap.register(ReLU); | ||
var LeakyReLU = (function (_super) { | ||
@@ -22,0 +54,0 @@ __extends(LeakyReLU, _super); |
@@ -15,5 +15,5 @@ "use strict"; | ||
var tfjs_core_1 = require("@tensorflow/tfjs-core"); | ||
var state_1 = require("../backend/state"); | ||
var K = require("../backend/tfjs_backend"); | ||
var topology_1 = require("../engine/topology"); | ||
var state_1 = require("../backend/state"); | ||
var errors_1 = require("../errors"); | ||
@@ -207,6 +207,5 @@ var generic_utils = require("../utils/generic_utils"); | ||
return tfjs_core_1.tidy(function () { | ||
var output = tfc.zeros(inputs[0].shape); | ||
for (var _i = 0, inputs_3 = inputs; _i < inputs_3.length; _i++) { | ||
var input = inputs_3[_i]; | ||
output = tfc.add(output, input); | ||
var output = inputs[0].clone(); | ||
for (var i = 1; i < inputs.length; ++i) { | ||
output = tfc.add(output, inputs[i]); | ||
} | ||
@@ -238,6 +237,5 @@ return output; | ||
return tfjs_core_1.tidy(function () { | ||
var output = tfc.ones(inputs[0].shape); | ||
for (var _i = 0, inputs_4 = inputs; _i < inputs_4.length; _i++) { | ||
var input = inputs_4[_i]; | ||
output = tfc.mul(output, input); | ||
var output = inputs[0].clone(); | ||
for (var i = 1; i < inputs.length; ++i) { | ||
output = tfc.mul(output, inputs[i]); | ||
} | ||
@@ -269,6 +267,5 @@ return output; | ||
return tfjs_core_1.tidy(function () { | ||
var output = tfc.zeros(inputs[0].shape); | ||
for (var _i = 0, inputs_5 = inputs; _i < inputs_5.length; _i++) { | ||
var input = inputs_5[_i]; | ||
output = tfc.add(output, input); | ||
var output = inputs[0].clone(); | ||
for (var i = 1; i < inputs.length; ++i) { | ||
output = tfc.add(output, inputs[i]); | ||
} | ||
@@ -275,0 +272,0 @@ return tfc.mul(state_1.getScalar(1 / inputs.length), output); |
@@ -39,2 +39,3 @@ import * as tfc from '@tensorflow/tfjs-core'; | ||
states: Tensor[]; | ||
private keptStates; | ||
private numConstants; | ||
@@ -41,0 +42,0 @@ constructor(config: RNNLayerConfig); |
@@ -117,3 +117,10 @@ "use strict"; | ||
if (fn == null) { | ||
throw new errors_1.ValueError("Unknown " + printableModuleName + ": " + identifier); | ||
throw new errors_1.ValueError("Unknown " + printableModuleName + ": " + identifier + ". " + | ||
"This may be due to one of the following reasons:\n" + | ||
("1. The " + printableModuleName + " is defined in Python, in which ") + | ||
"case it needs to be ported to TensorFlow.js or your JavaScript " + | ||
"code.\n" + | ||
("2. The custom " + printableModuleName + " is defined in JavaScript, ") + | ||
"but is not registered properly with " + | ||
"tf.serialization.registerClass()."); | ||
} | ||
@@ -142,3 +149,10 @@ } | ||
if (cls == null) { | ||
throw new errors_1.ValueError("Unknown " + printableModuleName + ": " + className); | ||
throw new errors_1.ValueError("Unknown " + printableModuleName + ": " + className + ". " + | ||
"This may be due to one of the following reasons:\n" + | ||
("1. The " + printableModuleName + " is defined in Python, in which ") + | ||
"case it needs to be ported to TensorFlow.js or your JavaScript " + | ||
"code.\n" + | ||
("2. The custom " + printableModuleName + " is defined in JavaScript, ") + | ||
"but is not registered properly with " + | ||
"tf.serialization.registerClass()."); | ||
} | ||
@@ -145,0 +159,0 @@ if (fromConfig != null) { |
@@ -1,2 +0,2 @@ | ||
declare const version = "0.7.4"; | ||
declare const version = "0.7.5"; | ||
export { version }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var version = '0.7.4'; | ||
var version = '0.7.5'; | ||
exports.version = version; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@tensorflow/tfjs-layers", | ||
"version": "0.7.4", | ||
"version": "0.7.5", | ||
"description": "TensorFlow layers API in JavaScript", | ||
@@ -13,3 +13,3 @@ "private": false, | ||
"devDependencies": { | ||
"@tensorflow/tfjs-core": "~0.12.11", | ||
"@tensorflow/tfjs-core": "~0.12.15", | ||
"@types/jasmine": "~2.5.53", | ||
@@ -49,4 +49,4 @@ "clang-format": "~1.2.2", | ||
"peerDependencies": { | ||
"@tensorflow/tfjs-core": "~0.12.11" | ||
"@tensorflow/tfjs-core": "~0.12.15" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5559691
26860