When I use the optimizer, there is no gradient due to the use of unit8, but I have to use unit8

def apply_relighting_tensor(tensor, alpha, beta):
tensor = tensor * 255.0
new_tensor = tensor.to(torch.uint8)
new_tensor = new_tensor * alpha + beta / 255.0
new_tensor = torch.abs(new_tensor)
new_tensor = new_tensor.to(torch.float32)
new_tensor = new_tensor / 255.0
return new_tensor

I know that this value is normal, but it has no gradient
But when I use floating point numbers, the effect of the generated image is not what I want at all. I don’t know what to do.

def apply_relighting_tensor(tensor, alpha, beta):
tensor_float = tensor * 255.0
new_tensor = tensor_float * alpha + beta

new_tensor = torch.clamp(new_tensor, 0, 255)
new_tensor = new_tensor / 255.0

Since you weren’t able to train the model using the uint8 approach, could it also be possible that the cause of the issue with generated image quality is the result of some other part of your model/training process rather than this particular function.