Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warp 3D #1442

Merged
merged 8 commits into from
Nov 12, 2019
Merged

Warp 3D #1442

merged 8 commits into from
Nov 12, 2019

Conversation

mzient
Copy link
Contributor

@mzient mzient commented Nov 5, 2019

Why we need this PR?

Pick one

  • It adds 3D capabilities to WarpAffine and Rotate

What happened in this PR?

  • Added 3D overloads for Warp kernels
  • Unlock 3D case for WarpAffine and Rotate
  • Add Axis paramete to RotateParams
  • Add 3D jupyter notebook to visually assess if it's working (it is!)

JIRA TASK: [DALI-don't-remember]

@mzient
Copy link
Contributor Author

mzient commented Nov 5, 2019

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [976711]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [976711]: BUILD FAILED

@mzient
Copy link
Contributor Author

mzient commented Nov 6, 2019

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [977970]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [977970]: BUILD FAILED

@mzient
Copy link
Contributor Author

mzient commented Nov 6, 2019

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [978394]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [978394]: BUILD FAILED

@mzient
Copy link
Contributor Author

mzient commented Nov 7, 2019

!build

@mzient mzient changed the title [WIP] Warp 3D Warp 3D Nov 7, 2019
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [980166]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [980166]: BUILD PASSED

@@ -66,6 +66,68 @@ TEST(GeomTransform, Rotation2D) {
EXPECT_NEAR(rotated4.y, 0, 1e-6f);
}

struct vec_near {
template <int N, typename T>
Copy link
Contributor

Choose a reason for hiding this comment

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

this only makes sense for floating point types, right?

Copy link
Contributor Author

@mzient mzient Nov 8, 2019

Choose a reason for hiding this comment

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

In theory, you can have some tolerance even for integer types - but here it's used only for floats.


for (;;) {
auto block_vol = volume(ret);
if (block_vol <= 0x40000 || (sample_vol / block_vol) > 256)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (block_vol <= 0x40000 || (sample_vol / block_vol) > 256)
if (block_vol <= max_block_elements_ || (sample_vol / block_vol) > 256)

dali/kernels/imgproc/warp/block_warp.cuh Show resolved Hide resolved
const InTensorCPU<InputType, 4> &input,
Mapping_ &mapping,
BorderType border = {}) {
int out_w = output.shape[2];
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: would make more sense to have those in order

const InTensorCPU<InputType, 4> &input,
AffineMapping<3> &mapping,
BorderType border = {}) {
int out_w = output.shape[2];
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

setup.SetDefaultBlockSize(def_block_size);
static_assert(setup.tensor_ndim == 4, "Incorrectly inferred tensor_ndim");
setup.SetupBlocks(TLS);
ASSERT_TRUE(setup.IsUniformSize());

while (volume(def_block_size) > 0x40000) {
Copy link
Contributor

Choose a reason for hiding this comment

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

0x40000 should better be a named constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not a good unit test, because it's actually testing the implementation. In such cases, I'd even say I like magic constants in tests - at least everything is clearly visible, not hidden behind layers of meaningless names. I removed the magic value from Setup though.

@@ -20,7 +20,9 @@ DALI_SCHEMA(Rotate)
.DocStr(R"code(Rotate the image by given angle.)code")
.NumInput(1)
.NumOutput(1)
.InputLayout(0, { "HWC" })
.InputLayout(0, { "HWC", "DHWC" })
.AddOptionalArg<float>("axis", "3D only: axis aroun which to rotate; alternatively, Euler angles "
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.AddOptionalArg<float>("axis", "3D only: axis aroun which to rotate; alternatively, Euler angles "
.AddOptionalArg<float>("axis", "3D only: axis around which to rotate; alternatively, Euler angles "

.InputLayout(0, { "HWC" })
.InputLayout(0, { "HWC", "DHWC" })
.AddOptionalArg<float>("axis", "3D only: axis aroun which to rotate; alternatively, Euler angles "
"(yaw, pitch, roll) can be used", std::vector<float>(), true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't seem to be true

@@ -9,6 +9,7 @@ Tutorials
detection_pipeline.ipynb
augmentation_gallery.ipynb
warp.ipynb
3D.ipynb
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe rename this file to warp_3d as we might want to have other 3d notebooks later

@mzient
Copy link
Contributor Author

mzient commented Nov 8, 2019

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [981878]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [981878]: BUILD PASSED

@mzient mzient force-pushed the Warp3D branch 4 times, most recently from 3c89a88 to 7201cf3 Compare November 8, 2019 13:26
@mzient
Copy link
Contributor Author

mzient commented Nov 8, 2019

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [981986]: BUILD STARTED

@mzient
Copy link
Contributor Author

mzient commented Nov 8, 2019

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [981995]: BUILD STARTED

@mzient
Copy link
Contributor Author

mzient commented Nov 8, 2019

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [982002]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [982002]: BUILD PASSED

block.start.y = blockIdx.y * block_size.y;
ivec<ndim> block_idx(0);
block_idx.x = blockIdx.x;
block_idx.y = blockIdx.y;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we assume that ndim > 2 and we have block_idx.y and block_idx[2]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we can't.

if (z_blocks_per_sample_shift) {
block.sample_idx = blockIdx.z >> z_blocks_per_sample_shift;
int block_in_sample = blockIdx.z & ((1 << z_blocks_per_sample_shift) - 1);
block_idx[2] = block_in_sample;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not block_idx.z?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above.

: public WarpParamProvider<Backend, 2, RotateParams<2>, BorderType> {
inline TensorShape<3> RotatedCanvasSize(TensorShape<3> input_shape, vec3 axis, double angle) {
ivec3 in_size = kernels::shape2vec(input_shape);
float eps = 1e-2f;
Copy link
Contributor

Choose a reason for hiding this comment

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

constexpr?

@@ -141,8 +188,42 @@ class RotateParamProvider<Backend, 2, BorderType>
}
}

template <int N, typename T>
void Collect(std::vector<vec<N, T>> &v, const std::string &name, bool required) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move to some utils? It may be reused by other ops as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In another PR maybe...

@@ -1,7 +1,7 @@
#!/bin/bash -e

# used pip packages
pip_packages="jupyter matplotlib mxnet-cu{cuda_v} tensorflow-gpu torchvision torch"
pip_packages="jupyter matplotlib mxnet-cu{cuda_v} tensorflow-gpu torchvision torch opencv-python"
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need it here.

@@ -1,7 +1,7 @@
#!/bin/bash -e

# used pip packages
pip_packages="jupyter matplotlib numpy"
pip_packages="jupyter matplotlib numpy opencv-python"
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need it here.

@@ -1,7 +1,7 @@
#!/bin/bash -e

# used pip packages
pip_packages="jupyter matplotlib numpy"
pip_packages="jupyter matplotlib numpy opencv-python"
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need it here.

"source": [
"## Usage example\n",
"\n",
"First, let's import the necessary modules and define the location of the dataset."
Copy link
Contributor

Choose a reason for hiding this comment

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

and define the location of the dataset. I think is it not done here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True.

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Fix block size issues.

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Add 3D.ipynb to index.rst.
Add opencv-python to jupyter tests.

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Added ability to split uniformly sized samples along Z axis (by a pow2 factor).

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
@mzient
Copy link
Contributor Author

mzient commented Nov 12, 2019

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [986757]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [986757]: BUILD FAILED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [986820]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [986820]: BUILD PASSED

@mzient mzient merged commit 0c8bab1 into NVIDIA:master Nov 12, 2019
@mzient mzient deleted the Warp3D branch November 12, 2019 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants