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

RandomAffine applies transforms without centering #12301

Open
cmhm7 opened this issue Feb 6, 2025 · 0 comments
Open

RandomAffine applies transforms without centering #12301

cmhm7 opened this issue Feb 6, 2025 · 0 comments
Assignees

Comments

@cmhm7
Copy link

cmhm7 commented Feb 6, 2025

Thanks for your error report and we appreciate it a lot.

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. I have read the FAQ documentation but cannot get the expected help.
  3. The bug has not been fixed in the latest version.

Describe the bug
A clear and concise description of what the bug is.

In RandomAffine, the transforms do not center the image first. Consequently, they are applied relative to the top left of the image. That prevents using large parameters: for instance, with a max rotation angle of 180°, most of the time the resulting image will be black because the rotation takes the image out of the valid positions

Reproduction

  1. What command or script did you run?
    In your pipeline put
dict(type='RandomAffine', max_rotate_degree=180.,max_translate_ratio=0.01,scaling_ratio_range=(0.99,1.01),max_shear_degree=1,border_val = (0,0,0))

And visualize dataloader outputs

  1. Did you make any modifications on the code or config? Did you understand what you have modified?
    No

  2. What dataset did you use?
    Custom one

Environment

  1. Please run python mmdet/utils/collect_env.py to collect necessary environment information and paste it here.

sys.platform: linux
Python: 3.7.10 (default, Feb 26 2021, 18:47:35) [GCC 7.3.0]
CUDA available: False
MUSA available: False
numpy_random_seed: 2147483648
GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
PyTorch: 1.9.0
PyTorch compiling details: PyTorch built with:

GCC 7.3
C++ Version: 201402
Intel(R) oneAPI Math Kernel Library Version 2021.2-Product Build 20210312 for Intel(R) 64 architecture applications
Intel(R) MKL-DNN v2.1.2 (Git Hash 98be7e8afa711dc9b66c8ff3504129cb82013cdb)
OpenMP 201511 (a.k.a. OpenMP 4.5)
NNPACK is enabled
CPU capability usage: AVX2
Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.1, CUDNN_VERSION=8.0.5, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.9.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON,

TorchVision: 0.10.0
OpenCV: 4.10.0
MMEngine: 0.10.6
MMDetection: 3.3.0+78cf2bc

  1. You may add addition that may be helpful for locating the problem, such as
    • How you installed PyTorch [e.g., pip, conda, source]
    • Other environment variables that may be related (such as $PATH, $LD_LIBRARY_PATH, $PYTHONPATH, etc.)

Error traceback
If applicable, paste the error trackback here.

ARG PYTORCH="1.9.0"
ARG CUDA="11.1"
ARG CUDNN="8"

A placeholder for trackback.

Bug fix
In mmdet/datasets/transforms/transforms.py/RandomAffine/_get_random_homography_matrix

change the beginning of the function to

    def _get_random_homography_matrix(self, height, width):

        # Recenter
        centering_matrix = self._get_translation_matrix(-width/2., -height/2.)
        inverse_centering_matrix = self._get_translation_matrix(width/2., height/2.)

end the end to

        warp_matrix = (
            inverse_centering_matrix @ translate_matrix @ shear_matrix @ rotation_matrix @ scaling_matrix @ centering_matrix)
        return warp_matrix
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

2 participants