Unknown builtin op: aten::Tensor

I got this error while trying to convert nn.module to torchscript.

Traceback (most recent call last):
  File "/home/dai/scripts/mobileocr/detector/mobilenet_east_deploy.py", line 240, in <module>
    script_module = torch.jit.script(net)
  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)
  File "/home/dai/py36env/lib/python3.6/site-packages/torch/jit/_recursive.py", line 222, in try_compile_fn
    return torch.jit.script(fn, _rcb=rcb)
  File "/home/dai/py36env/lib/python3.6/site-packages/torch/jit/__init__.py", line 1226, in script
    fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
  File "/home/dai/py36env/lib/python3.6/site-packages/torch/jit/_recursive.py", line 222, in try_compile_fn
    return torch.jit.script(fn, _rcb=rcb)
  File "/home/dai/py36env/lib/python3.6/site-packages/torch/jit/__init__.py", line 1226, in script
    fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
RuntimeError: 
Unknown builtin op: aten::Tensor.
Here are some suggestions: 
	aten::tensor

The original call is:
at /home/dai/scripts/mobileocr/detector/mobilenet_east_deploy.py:193:17
    for i in range(valid_pos.shape[0]):
        x = valid_pos[i,0]
        y = valid_pos[i,1]
        y_min = y - d[0,i]
        y_max = y + d[1,i]
        x_min = x - d[2,i]
        x_max = x + d[3,i]
        rotate_mat = get_rotate_mat_torch(-angle[i])

        temp_x = torch.Tensor([[x_min,x_max,x_max,x_min]]) - x
                 ~~~~~~~~~~~~ <--- HERE
        temp_y = torch.Tensor([[y_min,y_min,y_max,y_max]]) - y
        coordinates = torch.cat([temp_x,temp_y],dim = 0)
        # res = torch.dot(rotate_mat,coordinates)
        res = torch.matmul(rotate_mat,coordinates)
        res[0,:] += x
        res[1,:] += y

        if is_valid_poly_torch(res,score_shape,scale):
            index.append(i)

My pytorch version is 1.3.1 + cu92

How can I solve this problem or what function can be used to replace torch.Tensor()?

Please remind me if more information is needed.

Try to use the suggested torch.tensor instead (lowercase t).
I would generally not recommend to use torch.Tensor, as this might give you uninitialized code, e.g. by calling torch.Tensor(10).
torch.tensor is the factory method to pass values as a list etc.

2 Likes

Thank you very much, problem solved.