# Converting 2D to 1D module

**URL:** <https://discuss.pytorch.org/t/converting-2d-to-1d-module/25796>\
**Category:** Uncategorized\
**Created:** [September 23, 2018, 8:49pm UTC](https://discuss.pytorch.org/t/converting-2d-to-1d-module/25796 "2018-09-23T20:49:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dagcilibili](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dagcilibili/32/6747_2.png) [@dagcilibili](https://discuss.pytorch.org/u/dagcilibili)\
**Post date:** [September 23, 2018, 8:49pm UTC](https://discuss.pytorch.org/t/converting-2d-to-1d-module/25796/1 "2018-09-23T20:49:05Z")

</div>

The `nn.sequential` module simplifies writing models very nicely. However, when I need to convert from 2D tensors to 1D tensors before the fully connected layers I use `view` function which cannot be used within the `sequential`. I know I can create my own `2d_to_1d` module and feed it into `sequential` but wanted to know if there is a better way to do this. So my question is, what is the best way to change dimensions of a tensor and still use `sequential` to create a single module that does the whole pipeline?

---

<div class="post-metadata">

**Author:** ![Neda](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/neda/32/7779_2.png) [@Neda](https://discuss.pytorch.org/u/Neda)\
**Post date:** [November 12, 2018, 6:43pm UTC](https://discuss.pytorch.org/t/converting-2d-to-1d-module/25796/2 "2018-11-12T18:43:29Z")

</div>

I have a same problem. did you find any solution for this?

---

<div class="post-metadata">

**Author:** ![justusschock](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/justusschock/32/4637_2.png) [@justusschock](https://discuss.pytorch.org/u/justusschock)\
**Post date:** [November 12, 2018, 7:32pm UTC](https://discuss.pytorch.org/t/converting-2d-to-1d-module/25796/3 "2018-11-12T19:32:33Z")

</div>

You could create a wrapper module like this:

```auto
class Flatten(torch.nn.Module):
    def __init__ (self):
        super(). __init__ ()

    def forward(x) 
        return x.view(x.size(0), -1) 

```

And pass an instance of this module to the Sequential model before the fully connected layers.
