Comments (13)
You can use transpose: img = img.transpose(1,2).transpose(2,3)
, this should change BCHW layout to BHWC
from stn.pytorch.
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.
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.
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.
Thank you. Meanwhile I'll use permute (or transpose) and then contiguous(). It seems to work properly so far :)
from stn.pytorch.
Thank Fei for the nice work. Do you have any update on BCHW support?
from stn.pytorch.
@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.
@fxia22 Thanks for your prompt response. Good luck with your NIPS submission.
from stn.pytorch.
BCHW support added. example can be found in test.py
from stn.pytorch.
Thanks a lot!
from stn.pytorch.
@fxia22 to go from BHWC
to BCHW
just use img.permute(0, 3, 1, 2)
from stn.pytorch.
@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.
ah, right. Permute just recompute strides
from stn.pytorch.
Related Issues (20)
- output blank image HOT 10
- error in BilinearSampler.updateOutput: invalid device function HOT 4
- nan gradients with BCHW layout
- compatibility with DataParallel
- Bug with 'BCHW' version & Question about high CPU utilization when in GPU mode
- cuda runtime error HOT 5
- cannot compute gradients when STN is called multiple times HOT 2
- Why is there a lr parameter in AffineGridGenFunction ?
- STN added to Pytorch by Soumith Chintala HOT 4
- can you add a TPS grid generator in this awesome project~?
- Windows support ?
- Runtime error: dimension out of range HOT 1
- Upgrade to mxnet 1.0
- How can I run make.sh in my MacOSX terminal? HOT 1
- How to use stn for 3D transform? HOT 4
- how to run the demo
- How can it do backpropogation? HOT 1
- TypeError: dist must be a Distribution instance HOT 1
- Bug in gpu support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stn.pytorch.