Files
circomlib-ml/circuits/BatchNormalization2D.circom
drCathieSo.eth 30a43a2712 Version 2.0.0 (#5)
* feat: `Poly` renamed to `ZeLU` with scaling implemented

* fix: assertion in `ZeLU`

* feat: `AveragePooling2D` with scaling

* feat: `BatchNorm` with scaling

* feat: `Conv1D` with scaling

* feat: `Conv2D` with scaling

* feat: `Dense` with scaling

* fix: assertion in `Dense`

* feat: `GlobalAveragePooling2D` with scaling

* feat: input-only `ArgMax`

* feat: input-only `Flatten2D`

* feat: input-only `GlobalMaxPooling2D`

* feat: input-only `MaxPooling2D`

* feat: input-only `ReLU`

* test: precision up to 36 decimals

* chore: clean up

* test: model1 with 36 decimals

* fix: ReLU should use `p//2` as threshold

* test: clean up

* test: mnist model with 18 decimals

* build: Update package.json version to 2.0.0

* chore: Update README with warning message
2023-10-24 02:50:34 +07:00

32 lines
959 B
Plaintext

pragma circom 2.0.0;
// BatchNormalization layer for 2D inputs
// a = gamma/(moving_var+epsilon)**.5
// b = beta-gamma*moving_mean/(moving_var+epsilon)**.5
// n = 10 to the power of the number of decimal places
template BatchNormalization2D(nRows, nCols, nChannels, n) {
signal input in[nRows][nCols][nChannels];
signal input a[nChannels];
signal input b[nChannels];
signal input out[nRows][nCols][nChannels];
signal input remainder[nRows][nCols][nChannels];
for (var i=0; i<nRows; i++) {
for (var j=0; j<nCols; j++) {
for (var k=0; k<nChannels; k++) {
assert(remainder[i][j][k] < n);
out[i][j][k] * n + remainder[i][j][k] === a[k]*in[i][j][k]+b[k];
}
}
}
}
// component main { public [ out ] } = BatchNormalization2D(1, 1, 1, 1000);
/* INPUT = {
"in": ["123"],
"a": ["234"],
"b": ["345678"],
"out": ["374"],
"remainder": ["460"]
} */