Hi,
I have a preprocess class that has two methods other than forward
. when I try to sctrip the model this RunTime error apears:
Traceback (most recent call last):
File "/projects/src/preprocess_script.py", line 99, in <module>
scripted_prep = torch.jit.script(prep)
File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/__init__.py", line 1261, in script
return torch.jit._recursive.create_script_module(obj, torch.jit._recursive.infer_methods_to_compile)
File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/_recursive.py", line 305, in create_script_module
return create_script_module_impl(nn_module, concrete_type, stubs_fn)
File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/_recursive.py", line 361, in create_script_module_impl
create_methods_from_stubs(concrete_type, stubs)
File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/_recursive.py", line 279, in create_methods_from_stubs
concrete_type._create_methods(defs, rcbs, defaults)
File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/_recursive.py", line 583, in compile_unbound_method
stub = make_stub(fn)
File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/_recursive.py", line 34, in make_stub
ast = torch.jit.get_jit_def(func, self_name="RecursiveScriptModule")
File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/frontend.py", line 171, in get_jit_def
type_line = torch.jit.annotations.get_type_line(source)
File "/home/.conda/envs/GC/lib/python3.6/site-packages/torch/jit/annotations.py", line 202, in get_type_line
raise RuntimeError("Return type line '# type: (...) -> ...' not found on multiline "
RuntimeError: Return type line '# type: (...) -> ...' not found on multiline type annotation
(See PEP 484 https://www.python.org/dev/peps/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-code)
Process finished with exit code 1
I found out that one of the methods makes this error but even I commented the whole method code and just remain:
def from_tensors(self):
pass
still get the same error.
this is my forward code:
def forward(self, im_in):
images = im_in.permute(2, 0, 1).to('cpu')
images = self.normalizer(images)
images = self.from_tensors([images], 3) #this line raises error
return images