Appreciate the answer. I’m trying to understand how the tensors are being transformed. And how it relates to the outcome of what is being rendered in the end. 
Basically we have a texture of the shape [512, 512, 4], meaning [width, height, channels]. I assume the channels are RGBA.
And we want to go from a tensor with the shape [1, 3, 512, 512] and [batch_size, channels, height, width] to the format of the texture so it can be rendered. There is no alpha channel in this yet.
So please correct me if i’m wrong with this. I’d have to perform the following steps:


tensor.squeeze() the tensor to get rid of the batch_size, now we have [3, 512, 512] with [channels, height, width]


tensor.transpose(0, 2) to get [512, 512, 3] [width, height, channels]. My question here: what would’ve been the purpose of calling tensor.t().data on the output again? especially on a 3-dimensional tensor. I couldn’t find anything in the docs or changelogs of pytorch that any of the api’s used before this would’ve transformed the tensor into 2-D.
Add the alpha channel with torch.cat((tensor, tensor[:, :, 0]), 2) with tensor being in the same shape as the output of 2nd step. I still get the error: Tensors must have same number of dimensions: got 2 and 3. The input is obviously 3 dimensional, but tensor[:, :, 0] returns a tensor of the shape [512, 512]. I feel like this is the issue currently. Is there any ‘easy’ way of adding an extra column to all matrices that can represent the alpha channel? I want to go from shape [512, 512, 3] to [512, 512, 4].
Set all values of the alpha channel to 1. tensor[:, :, 3] = 1 


Cheers
Edit: Found the answer, can pretty much just do:
    a_tensor = torch.cuda.FloatTensor(h, w, 1)
    tensor = torch.cat((tensor, a_tensor), 2)

Is there a way to do this without having to create a tensor beforehand?