[TOPI][IMAGE][RESIZE] Bilinear interpolation for resize and upsampling. - #1181
Conversation
aecac12 to
8543d28
Compare
|
I just go through in mobile. Maybe omit something. |
|
align_corners doesn't affect the final shape, it just few pixels retained from input source to output with out re computation.. I will add that soon while review in progress. |
|
How about merging upsampling and bilinear into scale from frontend ? |
|
align_corners, you can refer the TF's implementation: For nearest neighbours: const int64 in_y = std::min(
(align_corners) ? static_cast<int64>(roundf(y * height_scale))
: static_cast<int64>(floorf(y * height_scale)),
in_height - 1);
for (int x = 0; x < out_width; ++x) {
const int64 in_x = std::min(
(align_corners) ? static_cast<int64>(roundf(x * width_scale))
: static_cast<int64>(floorf(x * width_scale)),
in_width - 1);For ResizeBilinear: // CalculateResizeScale determines the float scaling factor.
inline float CalculateResizeScale(int64 in_size, int64 out_size,
bool align_corners) {
return (align_corners && out_size > 1)
? (in_size - 1) / static_cast<float>(out_size - 1)
: in_size / static_cast<float>(out_size);
}
height_scale = CalculateResizeScale(in_height, out_height, align_corners_);
width_scale = CalculateResizeScale(in_width, out_width, align_corners_);I personally prefer keep separate interface. Which will make the customer know what op do. How to implement these op is the low-level framework's work. You can unify into scale you can also choose not to do. |
|
Thanks, I will check the above logic for align_coeners. Separation at customer end happens by "mode" attribute. The template and purpose is same hence I feel good to unify upto frontend. @tqchen what do you think ? |
ed38ba4 to
4a32049
Compare
|
I got through align_corners for bilinear, the same for nn is a challenge due to round, floor compatible IR instructions. Any ideas ? Or will hold align_corners for nn until there is a demand for it ! |
|
|
You can implement floor like this: https://discuss.tvm.ai/t/floordiv-operation-in-tensors-how-to-achieve/146/5 Then we should not have not-compatibility instruction |
|
Ok, let me try the floor operator addition first. I hope mod division work fine with all platforms by default. |
|
thanks, having bilinear upsampling is nice. But what is the use case of asymmetric upsampling (different scales for width and height) ? |
|
Yes, different scale for width and height. I don't have information on real time models for asymmetric scale. I felt its easy to maintain with new algorithms in future if required. Thanks for the review :) |
|
Please do the test on the OpenCL platform carefully. Someone told me that mod opeartor on floating point type has some issue. |
|
Sure, I will check that too. |
|
any updates on this PR? @masahi @FrozenGene do you have followup comments? |
|
Shouldn't |
|
Can I merge them both as "scale" and made it generic at all levels? |
|
@masahi |
|
I think "upsampling" is a better name than "scale". I don't know why you want down sampling, when we already have pooling. |
* Doc changes from review (3D tensor and others)
* set_num_inputs, input_names : Dynamic assignment for resize and upsampling.
* align_corners removed across for upsampling.
* in_shape->size checks updated.
* Bilinear test case added at compiler level.
* UseBilinear as common function.
* Doc correction.
* mode -> method
* Documentation changes.
f78a5c4 to
d24c986
Compare
* weights arg removed across nnvm/tvm.
|
CI is upgraded to use python3 in most cases but there is still python2 checks, so the code is better to be compatible until 2019 |
|
|
||
| )" NNVM_ADD_FILELINE) | ||
| .add_argument("data", "4D Tensor", "Input data.") | ||
| .add_argument("weight", "3D Tensor", "Weight matrix.") |
There was a problem hiding this comment.
Thanks. removed now.
|
LGTM. |
|
Thanks to the reviewers and the contributor, this is merged. |
|
From the discussion it seems like this implementation follows resize in tensorflow. However, |
Discuss:
Above implementation merges both nn (upsampling) and bilinear at topi.cpp level as scale.
How about merging upsampling & bilinear as scale at python tvm.topi and nnvm front end too ?
We can have just "scale" at all places in this case.