use crate::Error;
use super::{Layer, LayerSpec, LinearSpec};
use crate::dnn::nnet::LinearLayer;
use crate::dnn::weights::WeightList;
pub const BLOB_FILE: &str = "dred_rdovae_dec.bin";
pub const DEC_DENSE1_OUT_SIZE: usize = 96;
pub const DEC_GLU1_OUT_SIZE: usize = 64;
pub const DEC_GLU2_OUT_SIZE: usize = 64;
pub const DEC_GLU3_OUT_SIZE: usize = 64;
pub const DEC_GLU4_OUT_SIZE: usize = 64;
pub const DEC_GLU5_OUT_SIZE: usize = 64;
pub const DEC_HIDDEN_INIT_OUT_SIZE: usize = 128;
pub const DEC_OUTPUT_OUT_SIZE: usize = 80;
pub const DEC_CONV_DENSE1_OUT_SIZE: usize = 32;
pub const DEC_CONV_DENSE2_OUT_SIZE: usize = 32;
pub const DEC_CONV_DENSE3_OUT_SIZE: usize = 32;
pub const DEC_CONV_DENSE4_OUT_SIZE: usize = 32;
pub const DEC_CONV_DENSE5_OUT_SIZE: usize = 32;
pub const DEC_GRU_INIT_OUT_SIZE: usize = 320;
pub const DEC_GRU1_OUT_SIZE: usize = 64;
pub const DEC_GRU1_STATE_SIZE: usize = 64;
pub const DEC_GRU2_OUT_SIZE: usize = 64;
pub const DEC_GRU2_STATE_SIZE: usize = 64;
pub const DEC_GRU3_OUT_SIZE: usize = 64;
pub const DEC_GRU3_STATE_SIZE: usize = 64;
pub const DEC_GRU4_OUT_SIZE: usize = 64;
pub const DEC_GRU4_STATE_SIZE: usize = 64;
pub const DEC_GRU5_OUT_SIZE: usize = 64;
pub const DEC_GRU5_STATE_SIZE: usize = 64;
pub const DEC_CONV1_OUT_SIZE: usize = 32;
pub const DEC_CONV1_IN_SIZE: usize = 32;
pub const DEC_CONV1_STATE_SIZE: usize = 32;
pub const DEC_CONV2_OUT_SIZE: usize = 32;
pub const DEC_CONV2_IN_SIZE: usize = 32;
pub const DEC_CONV2_STATE_SIZE: usize = 32;
pub const DEC_CONV3_OUT_SIZE: usize = 32;
pub const DEC_CONV3_IN_SIZE: usize = 32;
pub const DEC_CONV3_STATE_SIZE: usize = 32;
pub const DEC_CONV4_OUT_SIZE: usize = 32;
pub const DEC_CONV4_IN_SIZE: usize = 32;
pub const DEC_CONV4_STATE_SIZE: usize = 32;
pub const DEC_CONV5_OUT_SIZE: usize = 32;
pub const DEC_CONV5_IN_SIZE: usize = 32;
pub const DEC_CONV5_STATE_SIZE: usize = 32;
pub const LAYERS: [LayerSpec; 29] = [
LayerSpec::Linear(LinearSpec {
name: "dec_dense1",
bias: Some("dec_dense1_bias"),
subias: None,
weights: None,
float_weights: Some("dec_dense1_weights_float"),
weights_idx: None,
diag: None,
scale: None,
nb_inputs: 26,
nb_outputs: 96,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_glu1",
bias: Some("dec_glu1_bias"),
subias: Some("dec_glu1_subias"),
weights: Some("dec_glu1_weights_int8"),
float_weights: Some("dec_glu1_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_glu1_scale"),
nb_inputs: 64,
nb_outputs: 64,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_glu2",
bias: Some("dec_glu2_bias"),
subias: Some("dec_glu2_subias"),
weights: Some("dec_glu2_weights_int8"),
float_weights: Some("dec_glu2_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_glu2_scale"),
nb_inputs: 64,
nb_outputs: 64,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_glu3",
bias: Some("dec_glu3_bias"),
subias: Some("dec_glu3_subias"),
weights: Some("dec_glu3_weights_int8"),
float_weights: Some("dec_glu3_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_glu3_scale"),
nb_inputs: 64,
nb_outputs: 64,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_glu4",
bias: Some("dec_glu4_bias"),
subias: Some("dec_glu4_subias"),
weights: Some("dec_glu4_weights_int8"),
float_weights: Some("dec_glu4_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_glu4_scale"),
nb_inputs: 64,
nb_outputs: 64,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_glu5",
bias: Some("dec_glu5_bias"),
subias: Some("dec_glu5_subias"),
weights: Some("dec_glu5_weights_int8"),
float_weights: Some("dec_glu5_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_glu5_scale"),
nb_inputs: 64,
nb_outputs: 64,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_hidden_init",
bias: Some("dec_hidden_init_bias"),
subias: None,
weights: None,
float_weights: Some("dec_hidden_init_weights_float"),
weights_idx: None,
diag: None,
scale: None,
nb_inputs: 50,
nb_outputs: 128,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_output",
bias: Some("dec_output_bias"),
subias: Some("dec_output_subias"),
weights: Some("dec_output_weights_int8"),
float_weights: Some("dec_output_weights_float"),
weights_idx: Some("dec_output_weights_idx"),
diag: None,
scale: Some("dec_output_scale"),
nb_inputs: 576,
nb_outputs: 80,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_conv_dense1",
bias: Some("dec_conv_dense1_bias"),
subias: Some("dec_conv_dense1_subias"),
weights: Some("dec_conv_dense1_weights_int8"),
float_weights: Some("dec_conv_dense1_weights_float"),
weights_idx: Some("dec_conv_dense1_weights_idx"),
diag: None,
scale: Some("dec_conv_dense1_scale"),
nb_inputs: 160,
nb_outputs: 32,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_conv_dense2",
bias: Some("dec_conv_dense2_bias"),
subias: Some("dec_conv_dense2_subias"),
weights: Some("dec_conv_dense2_weights_int8"),
float_weights: Some("dec_conv_dense2_weights_float"),
weights_idx: Some("dec_conv_dense2_weights_idx"),
diag: None,
scale: Some("dec_conv_dense2_scale"),
nb_inputs: 256,
nb_outputs: 32,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_conv_dense3",
bias: Some("dec_conv_dense3_bias"),
subias: Some("dec_conv_dense3_subias"),
weights: Some("dec_conv_dense3_weights_int8"),
float_weights: Some("dec_conv_dense3_weights_float"),
weights_idx: Some("dec_conv_dense3_weights_idx"),
diag: None,
scale: Some("dec_conv_dense3_scale"),
nb_inputs: 352,
nb_outputs: 32,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_conv_dense4",
bias: Some("dec_conv_dense4_bias"),
subias: Some("dec_conv_dense4_subias"),
weights: Some("dec_conv_dense4_weights_int8"),
float_weights: Some("dec_conv_dense4_weights_float"),
weights_idx: Some("dec_conv_dense4_weights_idx"),
diag: None,
scale: Some("dec_conv_dense4_scale"),
nb_inputs: 448,
nb_outputs: 32,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_conv_dense5",
bias: Some("dec_conv_dense5_bias"),
subias: Some("dec_conv_dense5_subias"),
weights: Some("dec_conv_dense5_weights_int8"),
float_weights: Some("dec_conv_dense5_weights_float"),
weights_idx: Some("dec_conv_dense5_weights_idx"),
diag: None,
scale: Some("dec_conv_dense5_scale"),
nb_inputs: 544,
nb_outputs: 32,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_gru_init",
bias: Some("dec_gru_init_bias"),
subias: Some("dec_gru_init_subias"),
weights: Some("dec_gru_init_weights_int8"),
float_weights: Some("dec_gru_init_weights_float"),
weights_idx: Some("dec_gru_init_weights_idx"),
diag: None,
scale: Some("dec_gru_init_scale"),
nb_inputs: 128,
nb_outputs: 320,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_gru1_input",
bias: Some("dec_gru1_input_bias"),
subias: Some("dec_gru1_input_subias"),
weights: Some("dec_gru1_input_weights_int8"),
float_weights: Some("dec_gru1_input_weights_float"),
weights_idx: Some("dec_gru1_input_weights_idx"),
diag: None,
scale: Some("dec_gru1_input_scale"),
nb_inputs: 96,
nb_outputs: 192,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_gru1_recurrent",
bias: Some("dec_gru1_recurrent_bias"),
subias: Some("dec_gru1_recurrent_subias"),
weights: Some("dec_gru1_recurrent_weights_int8"),
float_weights: Some("dec_gru1_recurrent_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_gru1_recurrent_scale"),
nb_inputs: 64,
nb_outputs: 192,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_gru2_input",
bias: Some("dec_gru2_input_bias"),
subias: Some("dec_gru2_input_subias"),
weights: Some("dec_gru2_input_weights_int8"),
float_weights: Some("dec_gru2_input_weights_float"),
weights_idx: Some("dec_gru2_input_weights_idx"),
diag: None,
scale: Some("dec_gru2_input_scale"),
nb_inputs: 192,
nb_outputs: 192,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_gru2_recurrent",
bias: Some("dec_gru2_recurrent_bias"),
subias: Some("dec_gru2_recurrent_subias"),
weights: Some("dec_gru2_recurrent_weights_int8"),
float_weights: Some("dec_gru2_recurrent_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_gru2_recurrent_scale"),
nb_inputs: 64,
nb_outputs: 192,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_gru3_input",
bias: Some("dec_gru3_input_bias"),
subias: Some("dec_gru3_input_subias"),
weights: Some("dec_gru3_input_weights_int8"),
float_weights: Some("dec_gru3_input_weights_float"),
weights_idx: Some("dec_gru3_input_weights_idx"),
diag: None,
scale: Some("dec_gru3_input_scale"),
nb_inputs: 288,
nb_outputs: 192,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_gru3_recurrent",
bias: Some("dec_gru3_recurrent_bias"),
subias: Some("dec_gru3_recurrent_subias"),
weights: Some("dec_gru3_recurrent_weights_int8"),
float_weights: Some("dec_gru3_recurrent_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_gru3_recurrent_scale"),
nb_inputs: 64,
nb_outputs: 192,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_gru4_input",
bias: Some("dec_gru4_input_bias"),
subias: Some("dec_gru4_input_subias"),
weights: Some("dec_gru4_input_weights_int8"),
float_weights: Some("dec_gru4_input_weights_float"),
weights_idx: Some("dec_gru4_input_weights_idx"),
diag: None,
scale: Some("dec_gru4_input_scale"),
nb_inputs: 384,
nb_outputs: 192,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_gru4_recurrent",
bias: Some("dec_gru4_recurrent_bias"),
subias: Some("dec_gru4_recurrent_subias"),
weights: Some("dec_gru4_recurrent_weights_int8"),
float_weights: Some("dec_gru4_recurrent_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_gru4_recurrent_scale"),
nb_inputs: 64,
nb_outputs: 192,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_gru5_input",
bias: Some("dec_gru5_input_bias"),
subias: Some("dec_gru5_input_subias"),
weights: Some("dec_gru5_input_weights_int8"),
float_weights: Some("dec_gru5_input_weights_float"),
weights_idx: Some("dec_gru5_input_weights_idx"),
diag: None,
scale: Some("dec_gru5_input_scale"),
nb_inputs: 480,
nb_outputs: 192,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_gru5_recurrent",
bias: Some("dec_gru5_recurrent_bias"),
subias: Some("dec_gru5_recurrent_subias"),
weights: Some("dec_gru5_recurrent_weights_int8"),
float_weights: Some("dec_gru5_recurrent_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_gru5_recurrent_scale"),
nb_inputs: 64,
nb_outputs: 192,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_conv1",
bias: Some("dec_conv1_bias"),
subias: Some("dec_conv1_subias"),
weights: Some("dec_conv1_weights_int8"),
float_weights: Some("dec_conv1_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_conv1_scale"),
nb_inputs: 64,
nb_outputs: 32,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_conv2",
bias: Some("dec_conv2_bias"),
subias: Some("dec_conv2_subias"),
weights: Some("dec_conv2_weights_int8"),
float_weights: Some("dec_conv2_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_conv2_scale"),
nb_inputs: 64,
nb_outputs: 32,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_conv3",
bias: Some("dec_conv3_bias"),
subias: Some("dec_conv3_subias"),
weights: Some("dec_conv3_weights_int8"),
float_weights: Some("dec_conv3_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_conv3_scale"),
nb_inputs: 64,
nb_outputs: 32,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_conv4",
bias: Some("dec_conv4_bias"),
subias: Some("dec_conv4_subias"),
weights: Some("dec_conv4_weights_int8"),
float_weights: Some("dec_conv4_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_conv4_scale"),
nb_inputs: 64,
nb_outputs: 32,
}),
LayerSpec::Linear(LinearSpec {
name: "dec_conv5",
bias: Some("dec_conv5_bias"),
subias: Some("dec_conv5_subias"),
weights: Some("dec_conv5_weights_int8"),
float_weights: Some("dec_conv5_weights_float"),
weights_idx: None,
diag: None,
scale: Some("dec_conv5_scale"),
nb_inputs: 64,
nb_outputs: 32,
}),
];
#[derive(Clone, Copy, Default)]
pub struct RdovaeDec<'w> {
pub dec_dense1: LinearLayer<'w>,
pub dec_glu1: LinearLayer<'w>,
pub dec_glu2: LinearLayer<'w>,
pub dec_glu3: LinearLayer<'w>,
pub dec_glu4: LinearLayer<'w>,
pub dec_glu5: LinearLayer<'w>,
pub dec_hidden_init: LinearLayer<'w>,
pub dec_output: LinearLayer<'w>,
pub dec_conv_dense1: LinearLayer<'w>,
pub dec_conv_dense2: LinearLayer<'w>,
pub dec_conv_dense3: LinearLayer<'w>,
pub dec_conv_dense4: LinearLayer<'w>,
pub dec_conv_dense5: LinearLayer<'w>,
pub dec_gru_init: LinearLayer<'w>,
pub dec_gru1_input: LinearLayer<'w>,
pub dec_gru1_recurrent: LinearLayer<'w>,
pub dec_gru2_input: LinearLayer<'w>,
pub dec_gru2_recurrent: LinearLayer<'w>,
pub dec_gru3_input: LinearLayer<'w>,
pub dec_gru3_recurrent: LinearLayer<'w>,
pub dec_gru4_input: LinearLayer<'w>,
pub dec_gru4_recurrent: LinearLayer<'w>,
pub dec_gru5_input: LinearLayer<'w>,
pub dec_gru5_recurrent: LinearLayer<'w>,
pub dec_conv1: LinearLayer<'w>,
pub dec_conv2: LinearLayer<'w>,
pub dec_conv3: LinearLayer<'w>,
pub dec_conv4: LinearLayer<'w>,
pub dec_conv5: LinearLayer<'w>,
}
impl<'w> RdovaeDec<'w> {
pub fn init(list: &WeightList<'w>) -> Result<Self, Error> {
Ok(RdovaeDec {
dec_dense1: LAYERS[0].linear(list)?,
dec_glu1: LAYERS[1].linear(list)?,
dec_glu2: LAYERS[2].linear(list)?,
dec_glu3: LAYERS[3].linear(list)?,
dec_glu4: LAYERS[4].linear(list)?,
dec_glu5: LAYERS[5].linear(list)?,
dec_hidden_init: LAYERS[6].linear(list)?,
dec_output: LAYERS[7].linear(list)?,
dec_conv_dense1: LAYERS[8].linear(list)?,
dec_conv_dense2: LAYERS[9].linear(list)?,
dec_conv_dense3: LAYERS[10].linear(list)?,
dec_conv_dense4: LAYERS[11].linear(list)?,
dec_conv_dense5: LAYERS[12].linear(list)?,
dec_gru_init: LAYERS[13].linear(list)?,
dec_gru1_input: LAYERS[14].linear(list)?,
dec_gru1_recurrent: LAYERS[15].linear(list)?,
dec_gru2_input: LAYERS[16].linear(list)?,
dec_gru2_recurrent: LAYERS[17].linear(list)?,
dec_gru3_input: LAYERS[18].linear(list)?,
dec_gru3_recurrent: LAYERS[19].linear(list)?,
dec_gru4_input: LAYERS[20].linear(list)?,
dec_gru4_recurrent: LAYERS[21].linear(list)?,
dec_gru5_input: LAYERS[22].linear(list)?,
dec_gru5_recurrent: LAYERS[23].linear(list)?,
dec_conv1: LAYERS[24].linear(list)?,
dec_conv2: LAYERS[25].linear(list)?,
dec_conv3: LAYERS[26].linear(list)?,
dec_conv4: LAYERS[27].linear(list)?,
dec_conv5: LAYERS[28].linear(list)?,
})
}
pub fn layers(&self) -> [Layer<'_, 'w>; 29] {
[
Layer::Linear(&self.dec_dense1),
Layer::Linear(&self.dec_glu1),
Layer::Linear(&self.dec_glu2),
Layer::Linear(&self.dec_glu3),
Layer::Linear(&self.dec_glu4),
Layer::Linear(&self.dec_glu5),
Layer::Linear(&self.dec_hidden_init),
Layer::Linear(&self.dec_output),
Layer::Linear(&self.dec_conv_dense1),
Layer::Linear(&self.dec_conv_dense2),
Layer::Linear(&self.dec_conv_dense3),
Layer::Linear(&self.dec_conv_dense4),
Layer::Linear(&self.dec_conv_dense5),
Layer::Linear(&self.dec_gru_init),
Layer::Linear(&self.dec_gru1_input),
Layer::Linear(&self.dec_gru1_recurrent),
Layer::Linear(&self.dec_gru2_input),
Layer::Linear(&self.dec_gru2_recurrent),
Layer::Linear(&self.dec_gru3_input),
Layer::Linear(&self.dec_gru3_recurrent),
Layer::Linear(&self.dec_gru4_input),
Layer::Linear(&self.dec_gru4_recurrent),
Layer::Linear(&self.dec_gru5_input),
Layer::Linear(&self.dec_gru5_recurrent),
Layer::Linear(&self.dec_conv1),
Layer::Linear(&self.dec_conv2),
Layer::Linear(&self.dec_conv3),
Layer::Linear(&self.dec_conv4),
Layer::Linear(&self.dec_conv5),
]
}
}