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

fix upsample nearest bug #5347

Merged
merged 6 commits into from
Jun 30, 2021
Merged

fix upsample nearest bug #5347

merged 6 commits into from
Jun 30, 2021

Conversation

BBuf
Copy link
Contributor

@BBuf BBuf commented Jun 29, 2021

修复upsample nearest设置scale为非整数时的形状推导和反向推导错误。

@BBuf BBuf requested review from Flowingsun007 and Ldpe2G June 29, 2021 13:47
@@ -23,7 +23,7 @@ namespace {

static int64_t GetNearestInputIndex(const int64_t out_dim_idx, const float scale,
const int64_t in_dim_size) {
int64_t index = static_cast<int64_t>(floorf((static_cast<float>(out_dim_idx) + 0.5f) * scale));
int64_t index = static_cast<int64_t>(std::floor((static_cast<float>(out_dim_idx) * scale)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -65,8 +65,8 @@ REGISTER_USER_OP("upsample_grad")
LOG(FATAL) << "upsample_nearest only supports NCHW";
}
*dx_shape = Shape({dy_shape.At(0), dy_shape.At(1),
static_cast<int32_t>(dy_shape.At(2) / height_scale),
static_cast<int32_t>(dy_shape.At(3) / width_scale)});
static_cast<int32_t>(std::round(dy_shape.At(2) / height_scale)),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

scale如果取1.5,输入图为3x3,那么输出图就是4x4,然后4/1.5=2.666xxx, 安装之前的做法直接取整这种情况会意外丢掉一个像素。

dtype=flow.float32,
requires_grad=True,
)
m = flow.nn.Upsample(scale_factor=1.5)
Copy link
Contributor

Choose a reason for hiding this comment

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

这个地方的测试,一个scale_factor有点太单薄了,我建议scale_factor由out_size / in_size算出来,可以设置多组out_size和in_size来算.

Copy link
Contributor

Choose a reason for hiding this comment

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

我pr interpolate的时候加上吧,其实这里是因为昨天用interpolate包Upsample测试的时候没过,发现不对劲:cry:

Copy link
Contributor Author

@BBuf BBuf Jun 29, 2021

Choose a reason for hiding this comment

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

好的,那麻烦ziqi加吧,我本地验证了几组数据没问题。

@BBuf BBuf requested a review from oneflow-ci-bot June 30, 2021 01:37
@BBuf BBuf added the automerge label Jun 30, 2021
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot June 30, 2021 01:40
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot June 30, 2021 03:43
@oneflow-ci-bot oneflow-ci-bot self-requested a review June 30, 2021 06:11
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot June 30, 2021 07:59
@oneflow-ci-bot oneflow-ci-bot merged commit 5eb22e5 into master Jun 30, 2021
@oneflow-ci-bot oneflow-ci-bot deleted the fix_upsample_bug branch June 30, 2021 09:37
BBuf added a commit that referenced this pull request Jul 1, 2021
Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
oneflow-ci-bot added a commit that referenced this pull request Jul 1, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* fix upsample bilinear bug

* recover code

* align with pytorch

* redesign upsample bilinear

* fix align corner bug

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
oneflow-ci-bot added a commit that referenced this pull request Jul 2, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* fix upsample bilinear bug

* recover code

* align with pytorch

* redesign upsample bilinear

* fix align corner bug

* align bilinear with pytorch

* fix conflict

* fix bug

* code reuse

* fix commets

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
oneflow-ci-bot added a commit that referenced this pull request Jul 7, 2021
* fix upsample nearest bug

* Enhance the difficulty of test samples

* fix

* fix

* fix

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* fix upsample bilinear bug

* fix test

* recover code

* align with pytorch

* redesign upsample bilinear

* fix align corner bug

* align bilinear with pytorch

* enchaned 4-dim samples

* fix conflict

* add backward test

* fix bug

* complete grad test

* fix merge conflict

* delete handwritten interpolate

* bypass pytorch interpolate bug in test

* add tensor grad assignment

* add test

* revert upsample changes

* fix TypeError: set_grad(): incompatible function arguments.  bug

* add zero_grad() docstring

* formmat comment

* fix docstring

* fix suggestions

* Update oneflow/python/test/tensor/test_tensor.py

Co-authored-by: Yinggang Wang <wyg19970408@gmail.com>

* Update oneflow/api/python/framework/tensor.cpp

Co-authored-by: Yinggang Wang <wyg19970408@gmail.com>

* enhance grad setter

* refine zero_grad() docstring and add slice docstring declaration to rst

* adjust optim.rst order

* refine comment

* refine zero_grad() docstring

* fix bug

Co-authored-by: BBuf <1182563586@qq.com>
Co-authored-by: Xiaoyu Zhang <35585791+BBuf@users.noreply.github.com>
Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
Co-authored-by: Yinggang Wang <wyg19970408@gmail.com>
oneflow-ci-bot added a commit that referenced this pull request Jul 16, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* fix upsample bilinear bug

* recover code

* align with pytorch

* redesign upsample bilinear

* fix align corner bug

* align bilinear with pytorch

* fix conflict

* fix bug

* code reuse

* fix commets

* add upsample_linear_1d_user_op

* add upsample_linear_1d_user_op

* add linear1d interp cpu kernel

* add linear1d interp gpu kernel

* rename kernel name

* add upsample nearest_1d kernel

* add upsample nearest_1d cuda kernel

* add upsample nearest_1d op

* fix complie bug

* add bicubic interp cpu kernel forward

* add bicubic2d interp cpu kernel backward impl

* add bicubic2d gpu kernel impl

* fix bicubic kernel compile error

* add bicubic2d kernel register

* fix compile bug

* nearest3d interp cpu kernel

* add nearest3d gpu kernel

* add nearest3d kernel registry

* add nearest3d cpu kernel

* add nearest3d cpu kernel

* add nearest3d cpu kernel

* fix upsample nearest interp bug

* fix upsample nearest interp bug

* add trilinear3d cpu kernel forward

* add trilinear3d cpu kernel backward

* add trilinear gpu kernel impl

* add trilinear op registry

* init interpolate nn function

* add upsample functors

* add interolate module

* add interpolate test_case

* restruct upsample_nearest2d and upsample_bilinear2d

* add upsample nearest2d and bilinear2d op registry

* add upsample nearest2d and bilinear2d op registry

* add upsample kernel grad functor

* add upsample_nearest_2d backward

* add upsample_linear_1d backward

* add upsample_nearest_1d backward

* add upsample_bicubic_2d backward

* fix backward impl bug

* fix nearest1d backward bug

* try to fix backward segmentfault

* add data_format parammeter

* fix upsample kernel backward bug

* fix cuda kernel impl bug

* fix upsample nearest bug

* fix align_corner attr error

* align linear1d impl with pytorch

* fix trilinear register bug

* fix trilinear bug

* add trilinear aligncorners test

* add test for bicubic, still has bug

* reimpl bicubic2d kernel

* align cubic interpolate with pytorch

* add bicubic cuda kernel

* fix bug

* align api with pytorch

* add doctest for interpolate

* update interpolate docs

* fix comments

* fix check_of_return comment

* fix comment

* fix comments

* fix commnet

* fix comment

* fix comments

* fix comments

* fix comments

* fix comments

* fix comment

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
Co-authored-by: Luyang <flowingsun007@163.com>
oneflow-ci-bot added a commit that referenced this pull request Jul 19, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* restruct upsample module

* auto format by CI

* change docs

* fix bug

* fix bug

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org>
oneflow-ci-bot added a commit that referenced this pull request Jul 20, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* init flip op

* add flip op register

* add flip cpu kernel forward

* add flip kernel impl

* add flip op functor and gradient_funcs

* add test, still need fix bug

* fix segmentfault bug

* add docs

* fix comments

* fix comments

* fix comments

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
oneflow-ci-bot added a commit that referenced this pull request Jul 23, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* add new autotest case

* add more tests

* fix bug

* auto format by CI

* add rtol and atol

* add rtol and atol

* add nothing

* auto format by CI

* fix export bug

* fix bug

* fix bug

* fix bug

* fix bug

* auto format by CI

* fix bug

* fix bug

* fix ci error

* fix bug

* auto format by CI

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org>
oneflow-ci-bot added a commit that referenced this pull request Jul 24, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* fix export bug

* add new_autotest_part1

* add new_autotest_part1

* add squeeze test

* add permute test

* add hardswish test

* add prelu

* fix bug

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
oneflow-ci-bot added a commit that referenced this pull request Jul 27, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* fix export bug

* fix conflict

* auto format by CI

* fix license

* fix ci error

* Delete version.py

* auto format by CI

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org>
oneflow-ci-bot added a commit that referenced this pull request Jul 28, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* fix export bug

* support flow.Size

* support flow.Size

* format

* auto format by CI

* fix repeat module bug

* fix repeat module bug

* fix repeat module bug

* fix repeat module bug

* auto format by CI

* fix repeat module bug

* fix conflict

* fix conflict

* auto format by CI

* support tuple parameter

* auto format by CI

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org>
oneflow-ci-bot added a commit that referenced this pull request Jul 28, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* fix export bug

* support expand flow.Size and tuple input

* delete tmp file

* auto format by CI

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org>
oneflow-ci-bot added a commit that referenced this pull request Jul 29, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* fix export bug

* fix flip bug

* fix clip bug

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
oneflow-ci-bot added a commit that referenced this pull request Jul 29, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* fix export bug

* add conv autotest

* add dead loop error raise

* add floor auto_test

* fix random tensor generator bug

* restruct math ops test

* add atan autotest

* restruct math_ops

* fix bug

* fix conv test bug

* fix commnets

* auto format by CI

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org>
oneflow-ci-bot added a commit that referenced this pull request Aug 8, 2021
* fix upsample nearest bug

* fix upsample nearest bug (#5347)

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>

* fix upsample bilinear bug

* fix export bug

* add api

* add api

* add api

* fix comments

* fix complie bug

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
Co-authored-by: Yao Chi <later@usopp.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants