How can I use init_with
in a for loop
?
#1371
Answered
by
antimora
zemelLeong
asked this question in
Q&A
-
for head in Self::get_heads() {
let output_channels = head.1;
match head.0.as_str() {
"reg" => {
let reg_record = &record.reg.layers;
reg = SequentialConv2d::from(vec![
Conv2dConfig::new([input_channels, head_conv], [3, 3])
.with_padding(PaddingConfig2d::Explicit(1, 1))
.init_with(reg_record[0]),
Conv2dConfig::new([head_conv, output_channels], [3, 3])
.with_padding(PaddingConfig2d::Explicit(1, 1))
.init_with(reg_record[1]),
]);
}
other => {
let seq = |r: &SequentialConv2dRecord<B>| {
let layers = &r.layers;
SequentialConv2d::from(vec![
Conv2dConfig::new([input_channels, head_conv], [3, 3])
.with_padding(PaddingConfig2d::Explicit(1, 1))
.init_with(layers[0]),
Conv2dConfig::new([head_conv, head_conv], [3, 3])
.with_padding(PaddingConfig2d::Explicit(1, 1))
.init_with(layers[1]),
Conv2dConfig::new([head_conv, head_conv], [3, 3])
.with_padding(PaddingConfig2d::Explicit(1, 1))
.init_with(layers[2]),
Conv2dConfig::new([head_conv, head_conv], [3, 3])
.with_padding(PaddingConfig2d::Explicit(1, 1))
.init_with(layers[3]),
Conv2dConfig::new([head_conv, output_channels], [1, 1])
.with_stride([1, 1])
.init_with(layers[4]),
])
};
match other {
"ax" => ax = seq(&record.ax),
"cr" => cr = seq(&record.cr),
"hm" => hm = seq(&record.hm),
"st" => st = seq(&record.st),
"wh" => wh = seq(&record.wh),
_ => panic!("Invalid head"),
}
}
}
}
Also, my model
|
Beta Was this translation helpful? Give feedback.
Answered by
antimora
Feb 27, 2024
Replies: 1 comment
-
I had the same issue and currently you cannot close records because we encourage to own the item. You can use let mut blocks = vec![];
for record_block in record.blocks.into_iter() {
blocks.push(ResidualAttentionBlock::init_with(
config.n_audio_head,
config.n_audio_state,
record_block,
));
} Regarding, your question "state weight key is not continuous". I believe the deserializer should just add items to a vector resetting the indexes (0 => 0, 2 => 1, 4=> 2, etc). The order should be preserved. I haven't tested but I implemented the deserializer myself and uses iterator to pull the items. Just make sure your struct uses |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
zemelLeong
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had the same issue and currently you cannot close records because we encourage to own the item.
You can use
.into_iter()
to own items from a vector. Here is a working example from my recent work. You can modify to use.into_iter()
iterator withnext()
if you wish to use outside loop.Regarding, your question "state weight key is not continuous". I believe the deserializer should just add items to a vector resetti…