Suppose a module returns a tuple of classes and offsets at L
feature layers (something like an SSD) for an object detection problem:
pred0_raw = SomeModule(params, 0)(x)
pred1_raw = SomeModule(params, 1)(x)
pred2_raw = SomeModule(params, 2)(x)
Here, len(pred0_raw)
is 2, corresponding to a tuple of (class, offset)
predictions at layer L=0
. class
and offset
are tensors of some shape [B, N, C]
. I would like to concatenate them so I do this:
L=3
classes = [eval(f"pred{i}_raw[0]") for i in range(L)] # class preds at predL_raw[0]
classes = torch.cat(classes, -2) # classes.shape = B, N*L, C
# similarly offsets.shape = B, N*L, 4
When I execute these statements in a Jupyter cell for experimenting, it seems to work but I get a NameError: name 'pred0_raw' is not defined
when I put all of that in a Module
. What am I doing wrong here? Any alternative suggestions?
Thanks!