How to Add 0-Value Columns/Rows to Tensor

Hi all,

This is related to Is there a way to insert a tensor into an existing tensor? but vectorized.

I want to add additional dummy categories to an object detector. Suppose the original vision model predicts 151 categories. How would I add 22 new 0 categories with a known order (they can be in the middle of the 151 so it wouldn’t be left/right-padding).

obj_dists = torch.rand(650, 151) # suppose there are 650 RoIs in this image.
mapping_151_177 = torch.randint(151) # index of the 177 corresponding to the 
mapping_177_151 = torch.randint(177) # index of the 177 corresponding to the 

Now my additional question is whether this is a dumb idea to start with, even if it’s feasible. Does this affect the gradient flow of the original data, for example? Or does this totally calls into question the losses?

If I understand your use case correctly, you would like to add new class ids into the targets as pre-defined locations (which is not necessarily at the beginning or end of the current target classes).
If so, you would of course change the entire datset and would most likely need to retrain the model.
The class correspondence between the model outputs and the target will be broken unless you also “shift” the model output logits by the same amount. In any case, adding new classes to the “right” of the already used classes sounds like an easier approach, so could you explain why you want to perform this remapping?