MCPcopy
hub / github.com/tensorflow/tfjs / constructor

Method constructor

tfjs-layers/src/layers/normalization.ts:489–524  ·  view source on GitHub ↗
(args?: LayerNormalizationLayerArgs)

Source from the content-addressed store, hash-verified

487 private beta: LayerVariable;
488
489 constructor(args?: LayerNormalizationLayerArgs) {
490 if (args == null) {
491 args = {};
492 }
493 super(args);
494
495 this.axis = args.axis == null ? -1 : args.axis;
496 if (typeof this.axis === 'number') {
497 if (!Number.isInteger(this.axis)) {
498 throw new Error(
499 `Expected axis to be an integer, but received ${this.axis}`);
500 }
501 } else if (Array.isArray(this.axis)) {
502 for (const axis of this.axis) {
503 if (!Number.isInteger(axis)) {
504 throw new Error(
505 `Expected axis to be an array of integers, ` +
506 `but received ${JSON.stringify(this.axis)}`);
507 }
508 }
509 } else {
510 throw new Error(
511 `Expected axis to be an integer or an array of integers, ` +
512 `but received ${JSON.stringify(this.axis)}`);
513 }
514
515 this.epsilon = args.epsilon == null ? 1e-3 : args.epsilon;
516 this.center = args.center == null ? true : args.center;
517 this.scale = args.scale == null ? true : args.scale;
518 this.betaInitializer = getInitializer(args.betaInitializer || 'zeros');
519 this.gammaInitializer = getInitializer(args.gammaInitializer || 'ones');
520 this.betaRegularizer = getRegularizer(args.betaRegularizer);
521 this.gammaRegularizer = getRegularizer(args.gammaRegularizer);
522
523 this.supportsMasking = true;
524 }
525
526 public override build(inputShape: Shape|Shape[]): void {
527 inputShape = getExactlyOneShape(inputShape);

Callers

nothing calls this directly

Calls 2

getInitializerFunction · 0.90
getRegularizerFunction · 0.90

Tested by

no test coverage detected