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

`ResizeCropMirror(..., output_dtype=FLOAT)` returns UINT8 tensor #1097

Open
hyabe opened this issue Jul 22, 2019 · 1 comment
Open

`ResizeCropMirror(..., output_dtype=FLOAT)` returns UINT8 tensor #1097

hyabe opened this issue Jul 22, 2019 · 1 comment
Labels
bug

Comments

@hyabe
Copy link

@hyabe hyabe commented Jul 22, 2019

ResizeCropMirror seems ignoring output_dtype option.

It reproduces on DALI 0.11.0/CUDA 10.1/CentOS 7.5 with the following code:

import nvidia.dali as dali
import numpy as np


class ResizeTo1x1Pipeline(dali.pipeline.Pipeline):
    def __init__(self):
        super(ResizeTo1x1Pipeline, self).__init__(batch_size=1, num_threads=1, device_id=0)
        self._fetcher = dali.ops.ExternalSource()
        # FastResizeCropMirror has the same problem
        self._resizer = dali.ops.ResizeCropMirror(
            resize_x=1, resize_y=1, crop=[1, 1],
            interp_type=dali.types.DALIInterpType.INTERP_LINEAR,
            output_dtype=dali.types.DALIDataType.FLOAT)

    def define_graph(self):
        self._images = self._fetcher()
        return self._resizer(self._images)

    def set_input_image(self, image):
        self.feed_input(self._images, image[np.newaxis])


print('DALI: {}'.format(dali.__version__))
pipeline = ResizeTo1x1Pipeline()
pipeline.build()

# a grayscale 3x2 image ([[1,2,3],[4,5,6]])
source_image = np.arange(6, dtype=np.uint8).reshape(2, 3, 1)
pipeline.set_input_image(source_image)
    
resized_images, = pipeline.run()

actual_image = resized_images.at(0)
expected_image = source_image.mean(axis=(0, 1), keepdims=True, dtype=np.float32)
np.testing.assert_allclose(actual_image, expected_image)

On my machine, DALI returns UINT8 instead of FLOAT as follows:

DALI: 0.11.0
Traceback (most recent call last):
  File "foo.py", line 35, in <module>
    np.testing.assert_allclose(actual_image, expected_image)
  File "/home/XXXXXXXX/miniconda3/envs/tensorrt/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 1501, in assert_allclose
    verbose=verbose, header=header, equal_nan=equal_nan)
  File "/home/XXXXXXXX/miniconda3/envs/tensorrt/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 827, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Not equal to tolerance rtol=1e-07, atol=0

Mismatch: 100%
Max absolute difference: 0.5
Max relative difference: 0.2
 x: array([[[3]]], dtype=uint8)
 y: array([[[2.5]]], dtype=float32)
@JanuszL JanuszL added the bug label Jul 22, 2019
@JanuszL
Copy link
Contributor

@JanuszL JanuszL commented Jul 22, 2019

@hyabe - yes, indeed it is a bug, output_dtype argument is disregarded. We are in the middle of reworking operators and API and we will fix this problem doing soon moving it to new resize kernel with ROI. Tracked as DALI-986.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.