I got the following error while converting model to torchscript.
Traceback (most recent call last):
File "ocr.py", line 206, in <module>
ts = torch.jit.script(ocr)
File "/home/dai/py36env/lib/python3.6/site-packages/torch/jit/__init__.py", line 1203, in script
return torch.jit.torch.jit._recursive.recursive_script(obj)
File "/home/dai/py36env/lib/python3.6/site-packages/torch/jit/_recursive.py", line 173, in recursive_script
return copy_to_script_module(mod, overload_stubs + stubs)
File "/home/dai/py36env/lib/python3.6/site-packages/torch/jit/_recursive.py", line 95, in copy_to_script_module
torch.jit._create_methods_from_stubs(script_module, stubs)
File "/home/dai/py36env/lib/python3.6/site-packages/torch/jit/__init__.py", line 1423, in _create_methods_from_stubs
self._c._create_methods(self, defs, rcbs, defaults)
RuntimeError:
builtin cannot be used as a value:
at ocr.py:80:23
img_tensor = resize_img(img_tensor)
# self.show(img_tensor)
img_tensor_ = (img_tensor - 0.5) / 0.5
img_tensor_ = img_tensor_.permute(2,0,1).unsqueeze(0) # --> n x c x h x w
boxes = self.east(img_tensor_)
new_boxes = []
pass_list:List[int] = []
for i in range(boxes.shape[0]):
~~~~~~~~~~~ <--- HERE
for j in range(i+1,boxes.shape[0]):
if i in pass_list or j in pass_list:
continue
cx1,cy1,angle1 = box_analyse(boxes[i])
cx2,cy2,angle2 = box_analyse(boxes[j])
if torch.atan(torch.abs(torch.abs(cy2 - cy1) / torch.abs(cx2 - cx1))) - (90 - (angle1 + angle2) / 2) * 3.141592653 / 180 < 0.1:
b = torch.cat([boxes[i][:8].reshape(4, 2), boxes[j][:8].reshape(4, 2)], dim=0)
new_box = torch.ops.my_ops.min_rect(b)
new_boxes.append(new_box.reshape(-1))
The variable boxes
is a tensor returned from model east
, is tensor.shape a builtin function in torchscript?
By the way, how can I debug in torchscript?
I met many problems in torchscript, it will be great if there’s a way to debug torchscript.