F.adjust_brightness gives different results for the same np.array and paddle.Tensor inputs when brightness_factor > 1.0 and brightness_factor < 1.0

drkbr07n  于 5个月前  发布在  其他
关注(0)|答案(4)|浏览(45)

bug描述 Describe the Bug

paddle.vision.transforms.adjust_brightness gives different results for the same np.array and paddle.Tensor inputs.

  • input: [[[1.]]]
  • np.array : returns [[[2.]]]
  • paddle.Tensor returns [[[1.]]]

when brightness_factor > 1.0

To reproduce:

import numpy as np
import paddle

from paddle.vision.transforms import functional as F

img_arr = np.array([[[1.0]]], dtype=np.float32)
tensor_img = paddle.to_tensor(img_arr, dtype="float32")

print(f"np.array input: {img_arr}")
print(f"paddle tensor input: {tensor_img}")
print("------------------")

adjusted_img_np = F.adjust_brightness(img_arr, brightness_factor=2.0)
adjusted_img_tensor = F.adjust_brightness(tensor_img, brightness_factor=2.0)
print(f"np.array output: {adjusted_img_np}, dtype: {adjusted_img_np.dtype}")
print(f"paddle tensor output: {adjusted_img_tensor}, dtype: {adjusted_img_tensor.dtype}")

Output:

np.array input: [[[1.]]]
paddle tensor input: Tensor(shape=[1, 1, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
       [[[1.]]])
------------------
np.array output: [[[2]]], dtype: uint8
paddle tensor output: Tensor(shape=[1, 1, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
       [[[1.]]]), dtype: paddle.float32

Expected output:

np.array input: [[[1.]]]
paddle tensor input: Tensor(shape=[1, 1, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
       [[[1.]]])
------------------
np.array output: [[[2]]], dtype: uint8
paddle tensor output: Tensor(shape=[1, 1, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
       [[[2.]]]), dtype: paddle.float32

其他补充信息 Additional Supplementary Information

No response

6bc51xsx

6bc51xsx1#

@yghstill 你好,

其实,我今天还发现,即使 brightness_factor < 1 ,输出也是不同的。

如果 brightness_factor < 1.0 ,输入 np.array 输出 [[[0]]] 。(即使 np.array 的类型是 float32 )

... # 代码同上 

img_arr = np.array([[[1.0]]], dtype=np.float32)
tensor_img = paddle.to_tensor(img_arr, dtype="float32")

adjusted_img_np = F.adjust_brightness(img_arr, brightness_factor=0.1)
adjusted_img_tensor = F.adjust_brightness(tensor_img, brightness_factor=0.1)

... # 代码同上

输出:

np.array input: [[[1.]]]
paddle tensor input: Tensor(shape=[1, 1, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
       [[[1.]]])
------------------
np.array output: [[[0]]], dtype: uint8
paddle tensor output: Tensor(shape=[1, 1, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
       [[[0.10000000]]]), dtype: paddle.float32

dtype="float32" 改为 dtype=paddle.float32 或不使用 dtype 并无区别。

如果输入是 np.uint8 类型,这就是正确的。但如果输入是 np.flaot32 类型,则返回 np.float32 更有意义,因此输出应该是 [[[0.1]]]

rsl1atfo

rsl1atfo2#

@ozogxyz 感谢反馈,目前该API输入图像类型只支持了uint8,其他类型输出结果有异常,可以先将输入图像统一设置成uint8,这个问题我们修复下

bt1cpqcv

bt1cpqcv3#

@ozogxyz Could you create a PR to fix it?

b1uwtaje

b1uwtaje4#

@luotao1 Sure, I will try to fix it

相关问题