UNPKG

@tensorflow/tfjs-core

Version:

Hardware-accelerated JavaScript library for machine intelligence

27 lines 1.55 kB
import * as broadcast_util from '../../ops/broadcast_util'; var BatchNormProgram = (function () { function BatchNormProgram(xShape, meanShape, varianceShape, offsetShape, scaleShape, varianceEpsilon) { this.outputShape = []; this.supportsBroadcasting = true; this.variableNames = ['x', 'mean', 'variance']; broadcast_util.assertAndGetBroadcastShape(xShape, meanShape); broadcast_util.assertAndGetBroadcastShape(xShape, varianceShape); var offsetSnippet = '0.0'; if (offsetShape != null) { broadcast_util.assertAndGetBroadcastShape(xShape, offsetShape); this.variableNames.push('offset'); offsetSnippet = 'getOffsetAtOutCoords()'; } var scaleSnippet = '1.0'; if (scaleShape != null) { broadcast_util.assertAndGetBroadcastShape(xShape, scaleShape); this.variableNames.push('scale'); scaleSnippet = 'getScaleAtOutCoords()'; } this.outputShape = xShape; this.userCode = "\n void main() {\n float x = getXAtOutCoords();\n float mean = getMeanAtOutCoords();\n float variance = getVarianceAtOutCoords();\n float offset = " + offsetSnippet + ";\n float scale = " + scaleSnippet + ";\n float inv = scale * inversesqrt(variance + float(" + varianceEpsilon + "));\n setOutput((x - mean) * inv + offset);\n }\n "; } return BatchNormProgram; }()); export { BatchNormProgram }; //# sourceMappingURL=batchnorm_gpu.js.map