Skip to content

Implements volumetric (5d) affine grid generation.#8322

Closed
elistevens wants to merge 14 commits intopytorch:masterfrom
elistevens:affine_grid_volumetric_support
Closed

Implements volumetric (5d) affine grid generation.#8322
elistevens wants to merge 14 commits intopytorch:masterfrom
elistevens:affine_grid_volumetric_support

Conversation

@elistevens
Copy link
Contributor

I've implemented affine grid generation for volumetric (5d) inputs. The implementation is based off of the spatial implementation, extended by one dimension. I have a few questions about my implementation vs. the existing one that I will add inline.

I have some extensive test cases for the forward pass here: https://gist.github.com/elistevens/6e3bfb20d8d0652b83bd16b3e911285b However, they use pytest.fixture extensively, so I'm not sure the best way to incorporate them into the pytorch test suite. Suggestions? I have not tested backwards at all.

Diff probably best viewed with whitespace changes ignored.

Thanks for considering!


base_grid[:, :, :, :, 0] = w_points
base_grid[:, :, :, :, 1] = h_points
base_grid[:, :, :, :, 2] = d_points

This comment was marked as off-topic.

base_grid[:, :, :, 1] = torch.ger(linear_points, torch.ones(W)).expand_as(base_grid[:, :, :, 1])
base_grid[:, :, :, 2] = 1
ctx.base_grid = base_grid
grid = torch.bmm(base_grid.view(N, H * W, 3), theta.transpose(1, 2))

This comment was marked as off-topic.

if theta.is_cuda:
AffineGridGenerator._enforce_cudnn(theta)
assert False
ctx.is_cuda = False

This comment was marked as off-topic.

Copy link
Collaborator

@ssnl ssnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests for this too? And FYI this function should be eventually move to ATen c++ side one day, and the cudnn check logic will be a lot simpler when that happens.

if grad_grid.is_cuda:
AffineGridGenerator._enforce_cudnn(grad_grid)
if len(ctx.size) == 5:
N, C, D, H, W = ctx.size

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@yf225
Copy link
Contributor

yf225 commented Jul 10, 2018

@elistevens Let us know if you have time to address @ssnl 's comments

@elistevens
Copy link
Contributor Author

elistevens commented Jul 10, 2018 via email

@elistevens
Copy link
Contributor Author

@ssnl @yf225 I've added tests and cleaned up the implementation.

Note that I've removed all of the "if theta.is_cuda then we must use CuDNN" checks. The affine_grid_generator does CuDNN dispatch, and if the control flow gets to AffineGridGenerator at all, it will happily work on CPU or CUDA tensors without complaint (while not implemented ATM, this would make it easier to verify that the python version outputs match the CuDNN outputs).

Are there any other changes desired?

@elistevens
Copy link
Contributor Author

The jenkins builds are failing, though the tests work locally. There are going to be some extra pushes while I try and figure out what the difference is between my local setup and the formal testing. Sorry for the noise.

@elistevens
Copy link
Contributor Author

@soumith Yes, absolutely. This was intended to be a temporary measure to get around the older version issue. I'll revert it once the docker images are updated. :)

@yf225
Copy link
Contributor

yf225 commented Jul 23, 2018

@elistevens I just updated the scipy version in our docker images to 1.1.0. Do you mind reverting the change to requirements.txt and see if CI passes?

@elistevens
Copy link
Contributor Author

elistevens commented Jul 23, 2018 via email

@elistevens
Copy link
Contributor Author

In case anyone is wondering about the RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88 warnings, they're not actually a problem according to: https://stackoverflow.com/questions/40845304/runtimewarning-numpy-dtype-size-changed-may-indicate-binary-incompatibility

https://ci.pytorch.org/jenkins/job/pytorch-builds/job/pytorch-linux-trusty-pynightly-test/11964/console doesn't have scipy installed.

https://ci.pytorch.org/jenkins/job/pytorch-builds/job/pytorch-win-ws2016-cuda9-cudnn7-py3-build/13558/console

23:14:25    Creating library build\temp.win-amd64-3.6\Release\torch/csrc\_C.cp36-win_amd64.lib and object build\temp.win-amd64-3.6\Release\torch/csrc\_C.cp36-win_amd64.exp
23:14:25 Size.obj : error LNK2001: unresolved external symbol "struct torch::jit::Value * __cdecl torch::jit::insertConstant(struct torch::jit::Graph &,struct torch::jit::IValue,class at::optional<struct torch::jit::script::SourceRange>)" (?insertConstant@jit@torch@@YAPEAUValue@12@AEAUGraph@12@UIValue@12@V?$optional@USourceRange@script@jit@torch@@@at@@@Z)
23:14:25 build\lib.win-amd64-3.6\torch\_C.cp36-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals
23:14:25 error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.11.25503\\bin\\HostX86\\x64\\link.exe' failed with exit status 1120

This doesn't seem to be related to my branch. Will this test failing be a merge blocker?

I think the rest of the issues are due to integer division under python 2. Testing now.

@elistevens
Copy link
Contributor Author

The last build had a handful of errors that all seemed unrelated to my changes (missing scipy on some of the testing images, windows build error, etc.).

@ssnl Are there any other desired changes?

@ezyang
Copy link
Contributor

ezyang commented Jul 27, 2018

@pytorchbot retest this please

@elistevens
Copy link
Contributor Author

@yf225 the remaining three failures are all due to scipy being missing entirely from the relevant images. Is that something you care to fix?

@yf225
Copy link
Contributor

yf225 commented Jul 30, 2018

@elistevens We should probably use the TEST_SCIPY flag (https://github.com/pytorch/pytorch/blob/master/test/common.py#L84) to gate the tests that require scipy in test_affine.py.

@elistevens
Copy link
Contributor Author

What's the project policy on PRs with failing tests that are unrelated to the PR? Do I need all green before a merge will be considered?

I'm not sure if I should be merging master and hoping the issues get resolved, or if review of the failures is sufficient.

@elistevens
Copy link
Contributor Author

@ssnl @yf225 any further changes desired?

@@ -0,0 +1,602 @@
from __future__ import print_function, division

This comment was marked as off-topic.

@li-roy li-roy added the awaiting response (this tag is deprecated) This tag is deprecated while we figure out what to do with it label Aug 14, 2018
@soumith
Copy link
Collaborator

soumith commented Aug 14, 2018

@elistevens after Simon's comment is addressed, this PR is good to go, i.e.:

Can you fold this in test_nn and remove the comments/logging please?

@@ -1,345 +1,345 @@
#!/usr/bin/env python

This comment was marked as off-topic.

This comment was marked as off-topic.

test/test_nn.py Outdated
return transform_tensor, transform_ary, grid_ary


class TestAffine(TestCase):

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SsnL has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

goodlux pushed a commit to goodlux/pytorch that referenced this pull request Aug 15, 2018
Summary:
I've implemented affine grid generation for volumetric (5d) inputs. The implementation is based off of the spatial implementation, extended by one dimension. I have a few questions about my implementation vs. the existing one that I will add inline.

I have some extensive test cases for the forward pass here: https://gist.github.com/elistevens/6e3bfb20d8d0652b83bd16b3e911285b However, they use `pytest.fixture` extensively, so I'm not sure the best way to incorporate them into the pytorch test suite. Suggestions? I have not tested backwards at all.

Diff probably best viewed with whitespace changes ignored.

Thanks for considering!
Pull Request resolved: pytorch#8322

Differential Revision: D9332335

Pulled By: SsnL

fbshipit-source-id: 1b3a91d078ef41a6d0a800514e49298fd817e4df
@elistevens elistevens deleted the affine_grid_volumetric_support branch August 18, 2018 04:43
ssnl pushed a commit to ssnl/pytorch that referenced this pull request Aug 22, 2018
Summary:
I've implemented affine grid generation for volumetric (5d) inputs. The implementation is based off of the spatial implementation, extended by one dimension. I have a few questions about my implementation vs. the existing one that I will add inline.

I have some extensive test cases for the forward pass here: https://gist.github.com/elistevens/6e3bfb20d8d0652b83bd16b3e911285b However, they use `pytest.fixture` extensively, so I'm not sure the best way to incorporate them into the pytorch test suite. Suggestions? I have not tested backwards at all.

Diff probably best viewed with whitespace changes ignored.

Thanks for considering!
Pull Request resolved: pytorch#8322

Differential Revision: D9332335

Pulled By: SsnL

fbshipit-source-id: 1b3a91d078ef41a6d0a800514e49298fd817e4df
facebook-github-bot pushed a commit that referenced this pull request Aug 22, 2018
Summary: Pull Request resolved: #10775

Differential Revision: D9458207

Pulled By: SsnL

fbshipit-source-id: f2b0dbf2d236134afded9b15d8bf55ff98f50e7b
PenghuiCheng pushed a commit to PenghuiCheng/pytorch that referenced this pull request Sep 11, 2018
Summary: Pull Request resolved: pytorch#10775

Differential Revision: D9458207

Pulled By: SsnL

fbshipit-source-id: f2b0dbf2d236134afded9b15d8bf55ff98f50e7b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting response (this tag is deprecated) This tag is deprecated while we figure out what to do with it open source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants