The difference between **tvm.relay.nn.upsampling** and **tvm.relay.image.resize2d**

When I ran Unet on VTA, when I imported the Model from Pytorch, I found nn.upsample translated to image.resize2d. However, the following two upsampling methods have been discovered under TVM’s Python API:

tvm.relay.nn.upsampling(data, scale_h=1, scale_w=1, layout='NCHW', method='nearest_neighbor', align_corners=False)¶
tvm.relay.image.resize2d(data, size, roi=None, layout='NCHW', method='linear', coordinate_transformation_mode='half_pixel', rounding_method='', cubic_alpha=- 0.5, cubic_exclude=0, extrapolation_value=0.0, out_dtype=None)¶

So I want to ask them what’s the difference? When will it be translated as nn.upsampling, and when will it be translated as image.resize2d? Because I currently suspect that this has a lot to do with whether the backdoor can implement graph_pack。 So I want to ask them what’s the difference? When will it be translated as Nn. upsampling, and when will it be translated as image.resize2d? Because I currently suspect that this has a lot to do with whether the backdoor can implement graph_pack?Thanks。

Hi @MengboZ, I’m also curious about the reasoning behind this.

To answer your question about when nn.upsampling or image.resize2d is used, it seems to me that it depends on how each front-end chooses to lower an upsampling operation. For example, the PyTorch front-end seems to exclusively use image.resize2d for upsampling, so in your case I would stick to working with this. Other frontends such as Onnx, Keras, CoreML, Caffe2 and MXNet make use of nn.upsampling on occasions, however, the exact reasoning for this I’m not entirely sure.

cc @mbrookhart @siju-samuel @tqchen - it seems to me as though image.resizexd supersedes the functionality of nn.upsampling and nn.upsampling3d. Is there a reason for both to co-exist or is it simply a case of needing to deprecate an old implementation?

nn.upsample calls image.resize under the hood.

Upsample was implemented first, but I think at this point the upsampling op is effectively deprecated, resize is a strict superset of the functionality. I don’t know what the process is for officially deprecating and removing a Relay op.

1 Like

Thanks @mbrookhart, that clears things up :slight_smile:

@mbrookhart @lhutton1 I think we should add a deprecation warning to whoever uses upsampling and redirect them to use image.resize. – though I liked the name “upsampling” as it is not strictly limited to images , while we figure out to a timeframe to remove the relay op.

I believe removal of relay op is good because having less ambiguity of what relay is produced is good for backend maintainers to target a stable set of relay. Moreover, new frontend developments will get less confused between the two.

logger.warning('"tvm.relay.nn.upsampling" is deprecated, use "tvm.relay.image.resize2d" instead.')