How to cast a tensor to a new type?

How can I cast a tensor to the float32 type in pytorch?
intersection = (torch.mul(height_inter, width_inter)
I want the intersection tensor to be float32 type.

torch.mul(height_inter, width_inter).float() converts to torch.FloatTensor, which is float32.

For float64 (double-precision), use torch.DoubleTensor

3 Likes