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
4条答案
按热度按时间6bc51xsx1#
@yghstill 你好,
其实,我今天还发现,即使
brightness_factor < 1
,输出也是不同的。如果
brightness_factor < 1.0
,输入np.array
输出[[[0]]]
。(即使np.array
的类型是float32
)输出:
将
dtype="float32"
改为dtype=paddle.float32
或不使用dtype
并无区别。如果输入是
np.uint8
类型,这就是正确的。但如果输入是np.flaot32
类型,则返回np.float32
更有意义,因此输出应该是[[[0.1]]]
。rsl1atfo2#
@ozogxyz 感谢反馈,目前该API输入图像类型只支持了uint8,其他类型输出结果有异常,可以先将输入图像统一设置成uint8,这个问题我们修复下
bt1cpqcv3#
@ozogxyz Could you create a PR to fix it?
b1uwtaje4#
@luotao1 Sure, I will try to fix it