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

[topi python API] 'bilinear_sample_nchw' is not supported in deformable_conv2d.py #4471

Closed
JerryZhouSH opened this issue Dec 5, 2019 · 8 comments

Comments

@JerryZhouSH
Copy link

I build TVM project on Ubuntu 16.04 with CUDA, and install the tvm, nnvm, topi python api with the following cmd:
cd tvm/nnvm/python; sudo pip3 setup.py install
cd tvm/python; sudo pip3 setup.py install
cd tvm/topi/python; sudo pip3 setup.py install

When I import nnvm in python3, the 'ImportError' throwed with "cannot import name 'bilinear_sample_nchw'".

@junrushao
Copy link
Member

Could you try building with the latest master?

@apivovarov
Copy link
Contributor

haha. It was fixed yesterday - #4467

@junrushao
Copy link
Member

Could you verify if it works? If so, we may close this issue for now.

@JerryZhouSH
Copy link
Author

Could you verify if it works? If so, we may close this issue for now.

I replaced 'bilinear_sample_nchw' with 'resize', and work well.
Here is the git diff context:
`diff --git a/topi/python/topi/nn/deformable_conv2d.py b/topi/python/topi/nn/deformable_conv2d.py
index fb05016..adb839d 100644
--- a/topi/python/topi/nn/deformable_conv2d.py
+++ b/topi/python/topi/nn/deformable_conv2d.py
@@ -20,7 +20,7 @@ import tvm

from .util import get_pad_tuple
from ..util import get_const_tuple
-from ..cpp.image import bilinear_sample_nchw
+from ..image.resize import resize

@tvm.target.generic_func
def deformable_conv2d_nchw(data, offset, kernel, strides, padding, dilation, deformable_groups,
@@ -94,7 +94,7 @@ def deformable_conv2d_nchw(data, offset, kernel, strides, padding, dilation, def

 def _bilinear(n, c, h, w):
     outside = tvm.any(h < 0, w < 0, h >= in_height, w >= in_width)
  •    val = bilinear_sample_nchw(data, (n, c, h, w), in_height - 1, in_width - 1)
    
  •    val = resize(data, (n, c, h, w))
       return tvm.if_then_else(outside, zero, val)
    

    data_deform =
    diff --git a/topi/python/topi/vision/rcnn/roi_align.py b/topi/python/topi/vision/rcnn/roi_align.py
    index c861ddd..b009d01 100644
    --- a/topi/python/topi/vision/rcnn/roi_align.py
    +++ b/topi/python/topi/vision/rcnn/roi_align.py
    @@ -18,7 +18,7 @@
    """Roi align operator"""
    import tvm
    from ...util import get_const_tuple
    -from ...cpp.image import bilinear_sample_nchw
    +from ...image.resize import resize

@tvm.target.generic_func
@@ -62,7 +62,7 @@ def roi_align_nchw(data, rois, pooled_size, spatial_scale, sample_ratio=-1):
outside = tvm.any(y < -1.0, x < -1.0, y > height, x > width)
y = tvm.max(y, 0.0)
x = tvm.max(x, 0.0)

  •    val = bilinear_sample_nchw(data, (i, c, y, x), height - 1, width - 1)
    
  •    val = resize(data, (i, c, y, x))
       return tvm.if_then_else(outside, 0.0, val)
    

    def _sample(i, c, ph, pw):`

@JerryZhouSH
Copy link
Author

Could you try building with the latest master?

Yes, the latest commit id is commit 279a8eb.

@vinx13
Copy link
Member

vinx13 commented Dec 9, 2019

Could you verify if it works? If so, we may close this issue for now.

I replaced 'bilinear_sample_nchw' with 'resize', and work well.
Here is the git diff context:
`diff --git a/topi/python/topi/nn/deformable_conv2d.py b/topi/python/topi/nn/deformable_conv2d.py
index fb05016..adb839d 100644
--- a/topi/python/topi/nn/deformable_conv2d.py
+++ b/topi/python/topi/nn/deformable_conv2d.py
@@ -20,7 +20,7 @@ import tvm

from .util import get_pad_tuple
from ..util import get_const_tuple
-from ..cpp.image import bilinear_sample_nchw
+from ..image.resize import resize

@tvm.target.generic_func
def deformable_conv2d_nchw(data, offset, kernel, strides, padding, dilation, deformable_groups,
@@ -94,7 +94,7 @@ def deformable_conv2d_nchw(data, offset, kernel, strides, padding, dilation, def

 def _bilinear(n, c, h, w):
     outside = tvm.any(h < 0, w < 0, h >= in_height, w >= in_width)
  •    val = bilinear_sample_nchw(data, (n, c, h, w), in_height - 1, in_width - 1)
    
  •    val = resize(data, (n, c, h, w))
       return tvm.if_then_else(outside, zero, val)
    

    data_deform =
    diff --git a/topi/python/topi/vision/rcnn/roi_align.py b/topi/python/topi/vision/rcnn/roi_align.py
    index c861ddd..b009d01 100644
    --- a/topi/python/topi/vision/rcnn/roi_align.py
    +++ b/topi/python/topi/vision/rcnn/roi_align.py
    @@ -18,7 +18,7 @@
    """Roi align operator"""
    import tvm
    from ...util import get_const_tuple
    -from ...cpp.image import bilinear_sample_nchw
    +from ...image.resize import resize

@tvm.target.generic_func
@@ -62,7 +62,7 @@ def roi_align_nchw(data, rois, pooled_size, spatial_scale, sample_ratio=-1):
outside = tvm.any(y < -1.0, x < -1.0, y > height, x > width)
y = tvm.max(y, 0.0)
x = tvm.max(x, 0.0)

  •    val = bilinear_sample_nchw(data, (i, c, y, x), height - 1, width - 1)
    
  •    val = resize(data, (i, c, y, x))
       return tvm.if_then_else(outside, 0.0, val)
    

    def _sample(i, c, ph, pw):`

The problem is that cpp lib can not be found in the path, this workaround doesn't solve the problem. On the other way, I believe this issue is in the latest master

@junrushao
Copy link
Member

junrushao commented Dec 9, 2019

Could you try a commit after 6ef2418b? I think it should be fixed by then.

@JerryZhouSH
Copy link
Author

Could you try a commit after 6ef2418b? I think it should be fixed by then.

I rebuilt the project with the latest master, it woks fine.
I will close this issue. Thank you very much.

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

No branches or pull requests

4 participants