I met this error when converting my model to torchscript.
RuntimeError:
iterator expression is expected to be a list, iterable, or range, found value of type 'Tensor':
at /home/dai/scripts/card_ocr_cpu/detector/model_torchscript.py:39:28
def standard_nms(S, thres):
order = torch.argsort(S[:, 8]).flip(0)
keep:List[int] = []
while order.size(0) > 0:
i = order[0]
keep.append(i.long().item())
ovr = torch.tensor([intersection(S[i], S[t]) for t in order[1:]])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
inds = torch.where(ovr <= thres)[0]
order = order[inds + 1]
return S[keep]
'standard_nms' is being compiled since it was called from 'nms_locality'
at /home/dai/scripts/card_ocr_cpu/detector/model_torchscript.py:63:11
p = weighted_merge(g, p)
else:
if p.size(0) > 1:
S.append(p)
p = g
if p is not None:
S.append(p)
if len(S) == 0:
return torch.tensor([0])
return standard_nms(torch.stack(S), thres)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
'nms_locality' is being compiled since it was called from 'get_boxes_torch'
at /home/dai/scripts/card_ocr_cpu/detector/model_torchscript.py:247:4
return None
boxes = torch.zeros((polys_restored.shape[0],9)).float()
boxes[:,:8] = polys_restored
xs = xy_text[index,0]
ys = xy_text[index,1]
boxes[:,8] = score[xs,ys]
boxes = nms_locality(boxes,nms_thresh)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
return boxes
'get_boxes_torch' is being compiled since it was called from '__torch__.EAST.forward'
at /home/dai/scripts/card_ocr_cpu/detector/model_torchscript.py:216:12
def forward(self, x, train:bool=False):
x1,x2,x3,x4 = self.extractor(x)
x = self.merge(x1,x2,x3,x4)
# del x1,x2,x3,x4
# collect()
score,geo = self.output(x)
if not train:
boxes = get_boxes_torch(score,geo,score_thresh=0.95,nms_thresh=0.2)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
return boxes
return score,geo
How can I iterate through the tensor like a list. Looking forward for your replay.