Can not use x=torch.tensor(b), to create a Tensor out of a List[List[Tensor]] (A List of Lists of Tensors)

Minimal Sample:

import torch
from typing import List

def get_boxes(batch_bboxes=None):
    s = torch.jit.annotate(List[List[torch.Tensor]], [])
    bb = torch.tensor(s)


RuntimeError: The following operation failed in the TorchScript interpreter.
Traceback of TorchScript (most recent call last):
bb = torch.tensor(b)

RuntimeError: Input must be of ints, floats, or bools, got Tensor

Hi @a.h.23,

Have you tried using torch.stack to convert the List of Tensors to Tensor, then repeat again for the 2nd list?

Thx AlphaBetaGamma96 !

My solution was now this:

ccc= torch.empty((0,1))

for bbox in pb:
   ch = torch.stack([category], dim=0)
   ch = torch.unsqueeze(ch, 0)
   ccc =, ch))

I also opend a Issue at the pytorch repo: