Giter Club home page Giter Club logo

Comments (13)

fxia22 avatar fxia22 commented on June 18, 2024

You can use transpose: img = img.transpose(1,2).transpose(2,3), this should change BCHW layout to BHWC

from stn.pytorch.

thnkim avatar thnkim commented on June 18, 2024

But, transpose(1,2).transpose(2,3) seems not to rearrange the internal array.
torch.FloatTensor(1,2,3,4).stride() and torch.FloatTensor(1,2,3,4).transpose(1,2).transpose(2,3).stride() are (24, 12, 4, 1) and (24, 4, 1, 12), respectively, while torch.FloatTensor(1,3,4,2).stride() is (24, 8, 2, 1).

So if I run the code, at line 44 and 45 in my_lib.c,

real yf = grids_data[b*grids_strideBatch + yOut*grids_strideHeight + xOut*grids_strideWidth];
real xf = grids_data[b*grids_strideBatch + yOut*grids_strideHeight + xOut*grids_strideWidth + 1];

xf is not valid, because grids_strideWidth is still 1.

I guess it needs to be like

real xf = grids_data[b*grids_strideBatch + yOut*grids_strideHeight + xOut*grids_strideWidth + 1*grids_strideChannel];

although I have not tested it.

from stn.pytorch.

fxia22 avatar fxia22 commented on June 18, 2024

transpose(1,2).transpose(2,3) changes the internal array, you can use .size() to check, I have been using that all the time. test_conv_stn.ipynb actually uses that fyi.

On a separate note, I guess BCHW should be the standard because it follows pytorch conv layers convention. I probably will have a version for that later. Let me know what you think.

from stn.pytorch.

fxia22 avatar fxia22 commented on June 18, 2024

Oh sorry I misunderstood, you are talking about permutation for grid rather than image. Hmm, I always use the grid generator to generate grid in BHWC format directly so never run into the problem you mentioned.

from stn.pytorch.

thnkim avatar thnkim commented on June 18, 2024

Thank you. Meanwhile I'll use permute (or transpose) and then contiguous(). It seems to work properly so far :)

from stn.pytorch.

junyanz avatar junyanz commented on June 18, 2024

Thank Fei for the nice work. Do you have any update on BCHW support?

from stn.pytorch.

fxia22 avatar fxia22 commented on June 18, 2024

@junyanz Hi Junyan, thank you for your interest, it is likely to be added after the NIPS deadline. We do find the majority of users need BCHW instead of BHWC and will thus prioritize it :D .

from stn.pytorch.

junyanz avatar junyanz commented on June 18, 2024

@fxia22 Thanks for your prompt response. Good luck with your NIPS submission.

from stn.pytorch.

fxia22 avatar fxia22 commented on June 18, 2024

BCHW support added. example can be found in test.py

from stn.pytorch.

junyanz avatar junyanz commented on June 18, 2024

Thanks a lot!

from stn.pytorch.

edgarriba avatar edgarriba commented on June 18, 2024

@fxia22 to go from BHWC to BCHW just use img.permute(0, 3, 1, 2)

from stn.pytorch.

fxia22 avatar fxia22 commented on June 18, 2024

@edgarriba Thanks for your suggestion. As discussed above, the problem of BCHW for STN is that BCHW layout is not suitable for coalescing. Permutation itself doesn't change the memory layout, but .contiguous() after permute will work.

from stn.pytorch.

edgarriba avatar edgarriba commented on June 18, 2024

ah, right. Permute just recompute strides

from stn.pytorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.