libffcv / ffcv

FFCV: Fast Forward Computer Vision (and other ML workloads!)
https://ffcv.io
Apache License 2.0
2.84k stars 178 forks source link

Normalize of transforms module error #185

Closed geekchen007 closed 2 years ago

geekchen007 commented 2 years ago

error location:

.../ffcv_3.0/ffcv/ffcv/transforms/normalize.py

detail:

/ffcv/lib/python3.8/site-packages/ffcv/transforms/normalize.py", line 88, in normalize_convert return final_result.view(final_type) TypeError: view(): argument 'size' (position 1) must be tuple of ints, not torch.dtype

debug info print("type:",final_type, self.original_dtype) print('value:',final_result)

type: torch.float16 <class 'numpy.float16'> value: tensor([[[[ 0, 0, 0, ..., 0, 0, 0], [ 0, 0, 0, ..., 0, 0, 0], [ 0, 0, 0, ..., 0, 0, 0], ..., [ 0, 0, 0, ..., 0, 0, 0], [ 0, 0, 0, ..., 0, 0, 0], [ 0, 0, 0, ..., 0, 0, 0]],

     [[-20890, -20890, -20890,  ..., -20890, -20890, -20890],
      [-20890, -20890, -20890,  ..., -20890, -20890, -20890],

_It seems that the calculation of “finalresultis” wrong

unit-test:

...L/ffcv_3.0/ffcv/tests/test_image_normalization.py

conda environment:

Name Version Build Channel _libgcc_mutex 0.1 conda_forge conda-forge _openmp_mutex 4.5 1_gnu conda-forge assertpy 1.1 pypi_0 pypi attrs 21.4.0 pypi_0 pypi binutils 2.36.1 hdd6e379_2 conda-forge binutils_impl_linux-64 2.36.1 h193b22a_2 conda-forge binutils_linux-64 2.36 hf3e587d_33 conda-forge blas 2.16 mkl conda-forge braceexpand 0.1.7 pypi_0 pypi bzip2 1.0.8 h516909a_2 conda-forge/label/cf202003 c-compiler 1.1.1 h516909a_0 conda-forge ca-certificates 2021.10.8 ha878542_0 conda-forge cairo 1.16.0 h6cf1ce9_1008 conda-forge compilers 1.1.1 0 conda-forge cudatoolkit 10.1.243 h036e899_10 conda-forge cupy 9.6.0 py38hc3adec7_0 conda-forge cxx-compiler 1.1.1 hc9558a2_0 conda-forge cycler 0.11.0 pypi_0 pypi dataclasses 0.6 pypi_0 pypi dbus 1.13.6 he372182_0 conda-forge/label/cf202003 expat 2.2.9 he1b5a44_2 conda-forge/label/cf202003 fastargs 1.2.0 pypi_0 pypi fastrlock 0.8 py38h709712a_1 conda-forge ffcv 0.0.3 pypi_0 pypi ffmpeg 4.1.3 h167e202_0 conda-forge fontconfig 2.13.96 ha180cfb_0 conda-forge fonttools 4.29.1 pypi_0 pypi fortran-compiler 1.1.1 he991be0_0 conda-forge freetype 2.10.4 h0708190_1 conda-forge future 0.18.2 pypi_0 pypi gcc_impl_linux-64 7.5.0 hda68d29_13 conda-forge gcc_linux-64 7.5.0 h47867f9_33 conda-forge gettext 0.19.8.1 h5e8e0c9_1 conda-forge/label/cf202003 gfortran_impl_linux-64 7.5.0 h56cb351_20 conda-forge gfortran_linux-64 7.5.0 h78c8a43_33 conda-forge giflib 5.2.1 h516909a_2 conda-forge/label/cf202003 glib 2.70.2 h780b84a_4 conda-forge glib-tools 2.70.2 h780b84a_4 conda-forge gmp 6.2.0 he1b5a44_2 conda-forge/label/cf202003 gnutls 3.6.5 hd3a4fd2_1002 conda-forge/label/cf202003 graphite2 1.3.13 he1b5a44_1001 conda-forge/label/cf202003 gst-plugins-base 1.14.5 h0935bb2_2 conda-forge/label/cf202003 gstreamer 1.18.5 h9f60fe5_3 conda-forge gxx_impl_linux-64 7.5.0 h64c220c_13 conda-forge gxx_linux-64 7.5.0 h555fc39_33 conda-forge harfbuzz 2.9.1 h83ec7ef_1 conda-forge hdf5 1.10.5 nompi_h3c11f04_1104 conda-forge/label/cf202003 icu 68.2 h9c3ff4c_0 conda-forge imgcat 0.5.0 pypi_0 pypi iniconfig 1.1.1 pypi_0 pypi intel-openmp 2022.0.1 h06a4308_3633 https://mirrors.ustc.edu.cn/anaconda/pkgs/main jasper 1.900.1 h07fcdf6_1006 conda-forge/label/cf202003 jbig 2.1 h14c3975_2001 conda-forge/label/cf202003 joblib 1.1.0 pypi_0 pypi jpeg 9e h7f98852_0 conda-forge kernel-headers_linux-64 2.6.32 he073ed8_15 conda-forge kiwisolver 1.3.2 pypi_0 pypi krb5 1.17.1 h2fd8d38_0 conda-forge/label/cf202003 lame 3.100 h14c3975_1001 conda-forge/label/cf202003 lcms2 2.12 hddcbb42_0 conda-forge ld_impl_linux-64 2.36.1 hea4e1c9_2 conda-forge lerc 3.0 h9c3ff4c_0 conda-forge libblas 3.8.0 16_mkl conda-forge libcblas 3.8.0 16_mkl conda-forge libclang 11.1.0 default_ha53f305_1 conda-forge libdeflate 1.10 h7f98852_0 conda-forge libedit 3.1.20191231 he28a2e2_2 conda-forge libevent 2.1.10 h72c5cf5_0 conda-forge/label/cf202003 libffi 3.4.2 h7f98852_5 conda-forge libgcc-ng 11.2.0 h1d223b6_12 conda-forge libgfortran-ng 7.5.0 h14aa051_20 conda-forge libgfortran4 7.5.0 h14aa051_20 conda-forge libglib 2.70.2 h174f98d_4 conda-forge libgomp 11.2.0 h1d223b6_12 conda-forge libiconv 1.16 h516909a_0 conda-forge libjpeg-turbo 2.1.1 h7f98852_0 conda-forge liblapack 3.8.0 16_mkl conda-forge liblapacke 3.8.0 16_mkl conda-forge libllvm11 11.1.0 hf817b99_3 conda-forge libnsl 2.0.0 h7f98852_0 conda-forge libopenblas 0.3.7 h5ec1e0e_6 conda-forge/label/cf202003 libopencv 4.2.0 py38_2 conda-forge/label/cf202003 libpng 1.6.37 hed695b0_1 conda-forge/label/cf202003 libpq 12.3 h255efa7_3 conda-forge libstdcxx-ng 11.2.0 he4da1e4_12 conda-forge libtiff 4.3.0 h542a066_3 conda-forge libuuid 2.32.1 h14c3975_1000 conda-forge/label/cf202003 libuv 1.43.0 h7f98852_0 conda-forge libwebp 1.0.2 h56121f0_5 conda-forge/label/cf202003 libwebp-base 1.1.0 2 conda-forge/label/cf202003 libxcb 1.13 h14c3975_1002 conda-forge/label/cf202003 libxkbcommon 1.0.3 he3ba5ed_0 conda-forge libxml2 2.9.12 h72842e0_0 conda-forge libzlib 1.2.11 h36c2ea0_1013 conda-forge llvmlite 0.38.0 py38h4630a5e_0 conda-forge lz4-c 1.9.3 h9c3ff4c_1 conda-forge matplotlib 3.5.1 pypi_0 pypi mkl 2020.2 256 https://mirrors.ustc.edu.cn/anaconda/pkgs/main mysql-common 8.0.28 ha770c72_0 conda-forge mysql-libs 8.0.28 hfa10184_0 conda-forge ncurses 6.3 h9c3ff4c_0 conda-forge nettle 3.4.1 h1bed415_1002 conda-forge/label/cf202003 ninja 1.10.2 h4bd325d_1 conda-forge nspr 4.32 h9c3ff4c_1 conda-forge nss 3.74 hb5efdd6_0 conda-forge numba 0.55.1 py38h4bf6c61_0 conda-forge numpy 1.21.5 pypi_0 pypi olefile 0.46 pyh9f0ad1d_1 conda-forge opencv 4.2.0 py38_2 conda-forge/label/cf202003 openh264 1.8.0 hdbcaa40_1000 conda-forge/label/cf202003 openjpeg 2.4.0 hb52868f_1 conda-forge openssl 1.1.1l h7f98852_0 conda-forge packaging 21.3 pypi_0 pypi pandas 1.4.1 pypi_0 pypi pcre 8.45 h9c3ff4c_0 conda-forge pillow 8.4.0 py38h8e6f84c_0 conda-forge pip 22.0.3 pyhd8ed1ab_0 conda-forge pixman 0.40.0 h36c2ea0_0 conda-forge pkg-config 0.29.2 h36c2ea0_1008 conda-forge pluggy 1.0.0 pypi_0 pypi psutil 5.9.0 pypi_0 pypi pthread-stubs 0.4 h14c3975_1001 conda-forge/label/cf202003 py 1.11.0 pypi_0 pypi py-opencv 4.2.0 py38h5ca1d4c_2 conda-forge/label/cf202003 pydeprecate 0.3.2 pypi_0 pypi pyparsing 3.0.7 pypi_0 pypi python 3.8.12 ha38a3c6_3_cpython conda-forge python-dateutil 2.8.2 pypi_0 pypi python_abi 3.8 2_cp38 conda-forge pytorch 1.7.0 py3.8_cuda10.1.243_cudnn7.6.3_0 pytorch pytorch-pfn-extras 0.5.7 pypi_0 pypi pytz 2021.3 pypi_0 pypi pyyaml 6.0 pypi_0 pypi qt 5.12.9 h9d6b050_2 conda-forge readline 8.1 h46c0cb4_0 conda-forge scikit-learn 1.0.2 pypi_0 pypi scipy 1.8.0 pypi_0 pypi setuptools 60.9.3 py38h578d9bd_0 conda-forge six 1.16.0 pypi_0 pypi sklearn 0.0 pypi_0 pypi sqlite 3.37.0 h9cd32fc_0 conda-forge sysroot_linux-64 2.12 he073ed8_15 conda-forge terminaltables 3.1.10 pypi_0 pypi threadpoolctl 3.1.0 pypi_0 pypi tk 8.6.12 h27826a3_0 conda-forge tomli 2.0.1 pypi_0 pypi torch-metrics 1.1.7 pypi_0 pypi torchmetrics 0.7.2 pypi_0 pypi torchvision 0.8.1 py38_cu101 pytorch tqdm 4.62.3 pypi_0 pypi typing_extensions 4.1.1 pyha770c72_0 conda-forge webdataset 0.1.103 pypi_0 pypi wheel 0.37.1 pyhd8ed1ab_0 conda-forge x264 1!152.20180806 h14c3975_0 conda-forge/label/cf202003 xorg-kbproto 1.0.7 h14c3975_1002 conda-forge/label/cf202003 xorg-libice 1.0.10 h516909a_0 conda-forge/label/cf202003 xorg-libsm 1.2.3 h84519dc_1000 conda-forge/label/cf202003 xorg-libx11 1.6.9 h516909a_0 conda-forge/label/cf202003 xorg-libxau 1.0.9 h14c3975_0 conda-forge/label/cf202003 xorg-libxdmcp 1.1.3 h516909a_0 conda-forge/label/cf202003 xorg-libxext 1.3.4 h516909a_0 conda-forge/label/cf202003 xorg-libxrender 0.9.10 h516909a_1002 conda-forge/label/cf202003 xorg-renderproto 0.11.1 h14c3975_1002 conda-forge/label/cf202003 xorg-xextproto 7.3.0 h14c3975_1002 conda-forge/label/cf202003 xorg-xproto 7.0.31 h14c3975_1007 conda-forge/label/cf202003 xz 5.2.5 h516909a_1 conda-forge zlib 1.2.11 h36c2ea0_1013 conda-forge zstd 1.5.2 ha95c52a_0 conda-forge

GuillaumeLeclerc commented 2 years ago

Hello,

https://pytorch.org/docs/stable/generated/torch.Tensor.view.html confirms that one can pass a dtype as view, we are using this function properly.

What you see is because numba doesn't support FP16. To go around that problem we interpret the data to INT16 so that it can go through the pipeline (but the bits are correct). If in your loop you "interpret" (using view) back into FP16 you should see the proper values.