-
Notifications
You must be signed in to change notification settings - Fork 825
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
fix upsample nearest bug #5347
Conversation
@@ -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))); |
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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来算.
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,那麻烦ziqi加吧,我本地验证了几组数据没问题。
Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
修复upsample nearest设置scale为非整数时的形状推导和反向推导错误。