# Transpose axes when making CustomDataset

**URL:** <https://discuss.pytorch.org/t/transpose-axes-when-making-customdataset/54750>\
**Category:** vision\
**Created:** [August 30, 2019, 7:23am UTC](https://discuss.pytorch.org/t/transpose-axes-when-making-customdataset/54750 "2019-08-30T07:23:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidlee](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/davidlee/32/12812_2.png) [@davidlee](https://discuss.pytorch.org/u/davidlee)\
**Post date:** [August 30, 2019, 7:23am UTC](https://discuss.pytorch.org/t/transpose-axes-when-making-customdataset/54750/1 "2019-08-30T07:23:25Z")

</div>

![6](https://discuss.pytorch.org/uploads/default/original/2X/1/14d69e06799ddb53e08a0c482f47d0abc5cf4c59.png)

Hello PyTorch!

Im making custom dataset class and im wondering how i can make the dimension of the batch from dataloader in [10, 100, 13] not [100,10,13], with transpose((1,0,2)), where should i put transpose in my custom dataset??

Please help me!!

---

<div class="post-metadata">

**Author:** ![mmisiur](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mmisiur/32/10162_2.png) [@mmisiur](https://discuss.pytorch.org/u/mmisiur)\
**Post date:** [August 30, 2019, 7:30am UTC](https://discuss.pytorch.org/t/transpose-axes-when-making-customdataset/54750/2 "2019-08-30T07:30:03Z")

</div>

Have you read [this thread](https://discuss.pytorch.org/t/swap-axes-in-pytorch/970)?

---

<div class="post-metadata">

**Author:** ![davidlee](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/davidlee/32/12812_2.png) [@davidlee](https://discuss.pytorch.org/u/davidlee)\
**Post date:** [August 30, 2019, 7:32am UTC](https://discuss.pytorch.org/t/transpose-axes-when-making-customdataset/54750/3 "2019-08-30T07:32:21Z")

</div>

Hello,

I knew how to transpose the axes with transpose((1,0,2) but ,

Im wondering where should i put this to Custom Dataset class.

Thanks,

---

<div class="post-metadata">

**Author:** ![mmisiur](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mmisiur/32/10162_2.png) [@mmisiur](https://discuss.pytorch.org/u/mmisiur)\
**Post date:** [August 30, 2019, 8:57am UTC](https://discuss.pytorch.org/t/transpose-axes-when-making-customdataset/54750/4 "2019-08-30T08:57:52Z")

</div>

I don’t think that putting it in `Dataset` will change anything since batch construction is the task of `DataLoader`, so your `i1.shape` (specifically `100`), comes directly form it . Moreover PyTorch normal format is NCHW, (the batch dimension is in the 0th position, then colour, height and width), so DataLoader will make it that way. I think the easiest way is to transpose it after getting batch from `DataLoader`. I don’t know if that satisfy you, or you have to explicitly put this in `DataLoader`. If you have to put it in `DataLoader` I think you can do it via `collate_fn` ([docs](https://pytorch.org/docs/stable/data.html#dataloader-collate-fn)), but I don’t have experience with that.
