mirror of
https://github.com/socathie/circomlib-ml.git
synced 2026-04-23 03:00:32 -04:00
* 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
32 lines
959 B
Plaintext
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"]
|
|
} */ |