#![allow(dead_code)]
use tinymind::int8::{LUT_SIZE, QAvgPool2D, QConv2D, QDense, Requantizer, apply_lut, qrelu};
pub type Input = [[[i8; 2]; 11]; 9];
pub const NUM_OUTPUTS: usize = 2;
pub const INPUT_SCALE: f32 = 0.007843138;
pub const INPUT_ZERO_POINT: i8 = -1;
pub const RELU1_SCALE: f32 = 0.0047058826;
pub const RELU1_ZERO_POINT: i8 = -128;
pub const POOL1_SCALE: f32 = 0.0047058826;
pub const POOL1_ZERO_POINT: i8 = -128;
pub const FLAT_SCALE: f32 = 0.0047058826;
pub const FLAT_ZERO_POINT: i8 = -128;
pub const RELU2_SCALE: f32 = 0.0032607613;
pub const RELU2_ZERO_POINT: i8 = -1;
pub const FC2_SCALE: f32 = 0.0034576417;
pub const FC2_ZERO_POINT: i8 = 86;
pub const OUT_SCALE: f32 = 0.0078125;
pub const OUT_ZERO_POINT: i8 = 0;
pub const OUTPUT_SCALE: f32 = OUT_SCALE;
pub const OUTPUT_ZERO_POINT: i8 = OUT_ZERO_POINT;
pub static CONV1_WEIGHTS: [[[[i8; 2]; 2]; 3]; 5] = [
[
[[0, 111], [-48, -32]],
[[79, -79], [-64, 48]],
[[-111, -95], [16, 127]],
],
[
[[-127, -16], [95, 111]],
[[-48, 64], [79, -79]],
[[32, 48], [-111, 0]],
],
[
[[16, 127], [-32, -16]],
[[95, -64], [-48, 64]],
[[-95, -79], [32, -127]],
],
[
[[-111, 0], [111, 127]],
[[-32, 79], [95, -64]],
[[48, 64], [-95, 16]],
],
[
[[32, -127], [-16, 0]],
[[111, -48], [-32, 79]],
[[-79, -64], [48, -111]],
],
];
pub static CONV1_BIASES: [i32; 5] = [-8096, 4048, -4048, 8096, 0];
pub static CONV1: QConv2D<'static, 2, 3, 2, 5, 2, 1, 0, 0, 0, 0> = QConv2D {
weights: &CONV1_WEIGHTS,
biases: Some(&CONV1_BIASES),
input_zero_point: -1,
requantizer: Requantizer {
multiplier: 1803660800,
shift: 7,
zero_point: -128,
qmin: -128,
qmax: 127,
},
};
pub static POOL1: QAvgPool2D<2, 2, 2, 2> = QAvgPool2D {
qmin: -128,
qmax: 127,
};
pub static FC1_WEIGHTS: [[i8; 50]; 6] = [
[
79, -79, 32, 48, -111, 0, 16, 127, -32, -16, 95, -64, -48, 64, -95, -79, 32, -127, -111, 0,
111, 127, -32, 79, 95, -64, 48, 64, -95, 16, 32, -127, -16, 0, 111, -48, -32, 79, -79, -64,
48, -111, -95, 16, 127, -127, -16, 95, 111, -48,
],
[
64, 79, -79, 32, 48, -111, 0, 16, 127, -32, -16, 95, -64, -48, 64, -95, -79, 32, -127,
-111, 0, 111, 127, -32, 79, 95, -64, 48, 64, -95, 16, 32, -127, -16, 0, 111, -48, -32, 79,
-79, -64, 48, -111, -95, 16, 127, -127, -16, 95, 111,
],
[
-48, 64, 79, -79, 32, 48, -111, 0, 16, 127, -32, -16, 95, -64, -48, 64, -95, -79, 32, -127,
-111, 0, 111, 127, -32, 79, 95, -64, 48, 64, -95, 16, 32, -127, -16, 0, 111, -48, -32, 79,
-79, -64, 48, -111, -95, 16, 127, -127, -16, 95,
],
[
111, -48, 64, 79, -79, 32, 48, -111, 0, 16, 127, -32, -16, 95, -64, -48, 64, -95, -79, 32,
-127, -111, 0, 111, 127, -32, 79, 95, -64, 48, 64, -95, 16, 32, -127, -16, 0, 111, -48,
-32, 79, -79, -64, 48, -111, -95, 16, 127, -127, -16,
],
[
95, 111, -48, 64, 79, -79, 32, 48, -111, 0, 16, 127, -32, -16, 95, -64, -48, 64, -95, -79,
32, -127, -111, 0, 111, 127, -32, 79, 95, -64, 48, 64, -95, 16, 32, -127, -16, 0, 111, -48,
-32, 79, -79, -64, 48, -111, -95, 16, 127, -127,
],
[
-16, 95, 111, -48, 64, 79, -79, 32, 48, -111, 0, 16, 127, -32, -16, 95, -64, -48, 64, -95,
-79, 32, -127, -111, 0, 111, 127, -32, 79, 95, -64, 48, 64, -95, 16, 32, -127, -16, 0, 111,
-48, -32, 79, -79, -64, 48, -111, -95, 16, 127,
],
];
pub static FC1_BIASES: [i32; 6] = [-13494, 26987, 0, -26987, 13494, -13494];
pub static FC1: QDense<'static, 50, 6> = QDense {
weights: &FC1_WEIGHTS,
biases: Some(&FC1_BIASES),
input_zero_point: -128,
requantizer: Requantizer {
multiplier: 1561810020,
shift: 8,
zero_point: -1,
qmin: -128,
qmax: 127,
},
};
pub static FC2_WEIGHTS: [[i8; 6]; 2] = [[-111, 0, 111, 127, -32, 79], [95, -64, 48, 64, -95, 16]];
pub static FC2_BIASES: [i32; 2] = [0, -9737];
pub static FC2: QDense<'static, 6, 2> = QDense {
weights: &FC2_WEIGHTS,
biases: Some(&FC2_BIASES),
input_zero_point: -1,
requantizer: Requantizer {
multiplier: 2041150979,
shift: 7,
zero_point: 86,
qmin: -128,
qmax: 127,
},
};
pub static OUT_LUT: [i8; LUT_SIZE] = [
-81, -80, -80, -80, -79, -79, -79, -79, -78, -78, -78, -78, -77, -77, -77, -76, -76, -76, -76,
-75, -75, -75, -74, -74, -74, -73, -73, -73, -73, -72, -72, -72, -71, -71, -71, -70, -70, -70,
-70, -69, -69, -69, -68, -68, -68, -67, -67, -67, -66, -66, -66, -65, -65, -65, -64, -64, -64,
-63, -63, -63, -62, -62, -62, -61, -61, -61, -60, -60, -60, -59, -59, -59, -58, -58, -58, -57,
-57, -56, -56, -56, -55, -55, -55, -54, -54, -54, -53, -53, -52, -52, -52, -51, -51, -51, -50,
-50, -50, -49, -49, -48, -48, -48, -47, -47, -46, -46, -46, -45, -45, -45, -44, -44, -43, -43,
-43, -42, -42, -41, -41, -41, -40, -40, -39, -39, -39, -38, -38, -37, -37, -37, -36, -36, -35,
-35, -35, -34, -34, -33, -33, -32, -32, -32, -31, -31, -30, -30, -30, -29, -29, -28, -28, -27,
-27, -27, -26, -26, -25, -25, -24, -24, -24, -23, -23, -22, -22, -21, -21, -21, -20, -20, -19,
-19, -18, -18, -18, -17, -17, -16, -16, -15, -15, -15, -14, -14, -13, -13, -12, -12, -11, -11,
-11, -10, -10, -9, -9, -8, -8, -8, -7, -7, -6, -6, -5, -5, -4, -4, -4, -3, -3, -2, -2, -1, -1,
0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 11, 11, 11, 12,
12, 13, 13, 14, 14, 15, 15, 15, 16, 16, 17, 17, 18, 18,
];
pub fn forward(input: &Input) -> [i8; NUM_OUTPUTS] {
let mut x0 = [[[0i8; 5]; 10]; 4];
CONV1.forward(input, &mut x0);
let mut x2 = [[[0i8; 5]; 5]; 2];
POOL1.forward(&x0, &mut x2);
let mut x4 = [0i8; 50];
for (out, &v) in x4.iter_mut().zip(x2.iter().flatten().flatten()) {
*out = v;
}
let x9 = FC1.forward(&x4).map(|v| qrelu(v, RELU2_ZERO_POINT));
let x10 = FC2.forward(&x9);
x10.map(|v| apply_lut(v, &OUT_LUT))
}