#![allow(dead_code)]
use tinymind::int8::{
QConv2D, QDense, QDepthwiseConv2D, QGlobalAvgPool2D, QMaxPool2D, QPointwiseConv2D, QSoftmax,
Requantizer,
};
pub type Input = [[[i8; 1]; 12]; 12];
pub const NUM_OUTPUTS: usize = 3;
pub const INPUT_SCALE: f32 = 0.007843138;
pub const INPUT_ZERO_POINT: i8 = -1;
pub const RELU1_SCALE: f32 = 0.011801419;
pub const RELU1_ZERO_POINT: i8 = -128;
pub const POOL1_SCALE: f32 = 0.011801419;
pub const POOL1_ZERO_POINT: i8 = -128;
pub const RELU2_SCALE: f32 = 0.010787795;
pub const RELU2_ZERO_POINT: i8 = -128;
pub const RELU3_SCALE: f32 = 0.0009883966;
pub const RELU3_ZERO_POINT: i8 = -1;
pub const GAP_SCALE: f32 = 0.0009883966;
pub const GAP_ZERO_POINT: i8 = -1;
pub const FC1_SCALE: f32 = 0.0033405602;
pub const FC1_ZERO_POINT: i8 = 127;
pub const PROBS_SCALE: f32 = 0.00390625;
pub const PROBS_ZERO_POINT: i8 = -128;
pub const OUTPUT_SCALE: f32 = PROBS_SCALE;
pub const OUTPUT_ZERO_POINT: i8 = PROBS_ZERO_POINT;
pub static BN1_WEIGHTS: [[[[i8; 1]; 3]; 3]; 4] = [
[
[[-27], [37], [-55]],
[[-46], [18], [-73]],
[[-64], [0], [64]],
],
[
[[127], [-32], [79]],
[[95], [-64], [48]],
[[64], [-95], [16]],
],
[
[[19], [-76], [-9]],
[[0], [66], [-28]],
[[-19], [47], [-47]],
],
[
[[-30], [22], [-52]],
[[-45], [7], [60]],
[[-60], [-7], [45]],
],
];
pub static BN1_BIASES: [i32; 4] = [-5398, 12144, 7526, -6515];
pub static BN1: QConv2D<'static, 1, 3, 3, 4, 1, 1, 1, 1, 1, 1> = QConv2D {
weights: &BN1_WEIGHTS,
biases: Some(&BN1_BIASES),
input_zero_point: -1,
requantizer: Requantizer {
multiplier: 1078824586,
shift: 7,
zero_point: -128,
qmin: -128,
qmax: 127,
},
};
pub static POOL1: QMaxPool2D<2, 2, 2, 2> = QMaxPool2D;
pub static BN2_WEIGHTS: [[[i8; 3]; 3]; 4] = [
[[21, -82, -10], [0, 72, -31], [-21, 51, -51]],
[[-18, 14, -32], [-28, 5, 37], [-37, -5, 28]],
[[127, -54, 73], [91, -91, 36], [54, -127, 0]],
[[9, 71, -18], [-9, 53, -36], [-27, 36, -53]],
];
pub static BN2_BIASES: [i32; 4] = [-1739, -8329, 9628, -3013];
pub static BN2_REQUANTIZERS: [Requantizer; 4] = [Requantizer {
multiplier: 1831202441,
shift: 7,
zero_point: -128,
qmin: -128,
qmax: 127,
}; 4];
pub static BN2: QDepthwiseConv2D<'static, 4, 3, 3, 1, 1, 1, 1, 1, 1> = QDepthwiseConv2D {
weights: &BN2_WEIGHTS,
biases: Some(&BN2_BIASES),
input_zero_point: -128,
requantizers: &BN2_REQUANTIZERS,
};
pub static CONV3_WEIGHTS: [[i8; 4]; 8] = [
[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],
];
pub static CONV3_BIASES: [i32; 8] = [2943, -2943, 5886, 0, -5886, 2943, -2943, 5886];
pub static CONV3: QPointwiseConv2D<'static, 4, 8> = QPointwiseConv2D {
weights: &CONV3_WEIGHTS,
biases: Some(&CONV3_BIASES),
input_zero_point: -128,
requantizer: Requantizer {
multiplier: 1476446082,
shift: 4,
zero_point: -1,
qmin: -1,
qmax: 127,
},
};
pub static GAP: QGlobalAvgPool2D = QGlobalAvgPool2D {
qmin: -128,
qmax: 127,
};
pub static FC1_WEIGHTS: [[i8; 8]; 3] = [
[-79, 32, -127, -111, 0, 111, 127, -32],
[79, 95, -64, 48, 64, -95, 16, 32],
[-127, -16, 0, 111, -48, -32, 79, -79],
];
pub static FC1_BIASES: [i32; 3] = [32123, 0, -32123];
pub static FC1: QDense<'static, 8, 3> = QDense {
weights: &FC1_WEIGHTS,
biases: Some(&FC1_BIASES),
input_zero_point: -1,
requantizer: Requantizer {
multiplier: 1280790316,
shift: 8,
zero_point: 127,
qmin: -128,
qmax: 127,
},
};
pub static PROBS: QSoftmax = QSoftmax {
input_multiplier: 1836492416,
input_left_shift: 18,
diff_min: -7936,
};
pub fn forward(input: &Input) -> [i8; NUM_OUTPUTS] {
let mut x0 = [[[0i8; 4]; 12]; 12];
BN1.forward(input, &mut x0);
let mut x2 = [[[0i8; 4]; 6]; 6];
POOL1.forward(&x0, &mut x2);
let mut x4 = [[[0i8; 4]; 6]; 6];
BN2.forward(&x2, &mut x4);
let mut x6 = [[[0i8; 8]; 6]; 6];
CONV3.forward(&x4, &mut x6);
let x8 = GAP.forward(&x6);
let x9 = FC1.forward(&x8);
PROBS.forward(&x9)
}