linyu
(linyu)
June 29, 2018, 3:24am
1
For example, I would like to extract each 2 × 2 submatrix in a 3 × 3 matrix, converting them to column vector, then obtaining a new matrix. Like this:
1…2…3./././././././././1…2…4…5
4…5…6…------->…2…3…5…6
7…8…9./././././././././4…5…7…8
./././././././././././././././/5…6…8…9
and how to effectively implement the inv-process.
Thank you for your attention and answer.
SimonW
(Simon Wang)
June 29, 2018, 5:46am
2
You are looking for nn.Unfold
(otherwise commonly known as im2col). See https://pytorch.org/docs/master/nn.html#torch.nn.Unfold .
The functional form also exists and is at torch.nn.functional.unfold
.
1 Like
linyu
(linyu)
June 29, 2018, 6:18am
4
Thank you very much, you’ve been a great help to me.
linyu
(linyu)
June 29, 2018, 7:08am
5
Hi, it seems that this function only exist in pytorch_0.5 which is an unstable version. So, have you been used this version, or is there a good solution to this problem under pytorch_0.4?
SimonW
(Simon Wang)
June 29, 2018, 6:41pm
6
They are actually in 0.4.0! But we forgot to document it, and added the doc reference in 0.5.
See: https://github.com/pytorch/pytorch/blob/v0.4.0/torch/nn/modules/fold.py
2 Likes
linyu
(linyu)
June 30, 2018, 9:10am
7
Oh, yes. I have been used it. Thank you!