0%

Recent intersting bugs in my implementation

Assign values to pytorch tensor

Everytime when I try to initialize a pytorch tensor, I would like to use torch.zeros:

1
sum_each_bbox = torch.zeros(len(bbox),len(bbox[0]))

But when I try to assign interger value to the tensor, like:

1
2
3
sum_each_bbox[i,j] = sum(bbox[i][j])
print(sum_each_bbox[i,j] )
print(bbox[i][j])

The value will be different:

1
2
tensor(16906704.)
16906703

Instead, we should specify the data type to make it assigned correctly.

1
sum_each_bbox = torch.zeros(len(bbox),len(bbox[0]),dtype=torch.int64)