Tensor pass through makes image vertically flipped

Hi, I’m new to Sentis and Unity. My goal is to add a image enhancement neural network to the post process pipeline. My first step is to write a simple pass-through code in OnRenderImage(), like this

private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
    TensorFloat inputTensor = TextureConverter.ToTensor(source);
    TextureConverter.RenderToTexture(inputTensor, destination);
    inputTensor.Dispose();
}

Then when running, I found the view is upside down flipped. Why?

it depends on the convention of the origin of the rendertexture.
It is flipped between pytorch and unity so you need to use the flip that corresponds to your use case

TextureConverter.RenderToTexture(rgbaTensor, rgbaRenderTexture, new TextureTransform().SetCoordOrigin(CoordOrigin.BottomLeft));

You can check com.unity.sentis\Samples\Convert tensors to textures for more details

1 Like