Open inakivelasco opened 2 years ago
You've chosen to report an unexpected problem or bug. Unless you already know the root cause of it, please include details about it by filling the issue template. The following information is missing: "Instructions To Reproduce the Issue and Full Logs"; "Your Environment";
Don't have a way to reproduce this. To guess from the error message I think this line: https://github.com/facebookresearch/detectron2/blob/45b3fcea6e76bf7a351e54e01c7d6e1a3a0100a5/detectron2/modeling/backbone/resnet.py#L428 should be changed to
self._out_features = list(out_features)
Don't have a way to reproduce this. To guess from the error message I think this line:
should be changed to
self._out_features = list(out_features)
After changing that and executing again the same command I get the following error:
Traceback (most recent call last): File "D:\detectron2-master\detectron2-master\tools\deploy\export_lazy_config.py", line 257, in
exported_model = export_scripting(torch_model) File "D:\detectron2-master\detectron2-master\tools\deploy\export_lazy_config.py", line 103, in export_scripting ts_model = scripting_with_instances(ScriptableAdapter(), fields) File "c:\users\inaki\detectron2\detectron2\export\torchscript.py", line 55, in scripting_with_instances scripted_model = torch.jit.script(model) File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_script.py", line 1265, in script return torch.jit._recursive.create_script_module( File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_recursive.py", line 454, in create_script_module return create_script_module_impl(nn_module, concrete_type, stubs_fn) File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_recursive.py", line 516, in create_script_module_impl script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn) File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_script.py", line 594, in _construct init_fn(script_module) File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_recursive.py", line 494, in init_fn scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn) File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_recursive.py", line 520, in create_script_module_impl create_methods_and_properties_from_stubs(concrete_type, method_stubs, property_stubs) File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_recursive.py", line 371, in create_methods_and_properties_from_stubs concrete_type._create_methods_and_properties(property_defs, property_rcbs, method_defs, method_rcbs, method_defaults) RuntimeError: Module 'FCOS' has no attribute 'head_in_features' (This attribute exists on the Python module, but we failed to convert Python type: 'omegaconf.listconfig.ListConfig' to a TorchScript type. Only tensors and (possibly nested) tuples of tensors, lists, or dictsare supported as inputs or outputs of traced functions, but instead got value of type ListConfig.. Its type was inferred; try adding a type annotation for the attribute.):
File "c:\users\inaki\detectron2\detectron2\modeling\meta_arch\dense_detector.py", line 94
images = self.preprocess_image(batched_inputs)
features = self.backbone(images.tensor)
features = [features[f] for f in self.head_in_features]
~~~~~~~~~~~~~~~~~~~~~ <--- HERE
predictions = self.head(features)
self.head_in_features
should be changed to a list as well.
Also, FCOS
is not in the export support list in https://detectron2.readthedocs.io/en/latest/tutorials/deployment.html , so there are probably other changes needed
self.head_in_features
should be changed to a list as well. Also,FCOS
is not in the export support list in https://detectron2.readthedocs.io/en/latest/tutorials/deployment.html , so there are probably other changes needed
I changed this in the dense_detector.py (i added the final line):
self.backbone = backbone
self.head = head
if head_in_features is None:
shapes = self.backbone.output_shape()
self.head_in_features = sorted(shapes.keys(), key=lambda x: shapes[x].stride)
else:
self.head_in_features = head_in_features
self.head_in_features = list(head_in_features)
Now I get the following error:
Traceback (most recent call last): File "D:\detectron2-master\detectron2-master\tools\deploy\export_lazy_config.py", line 257, in
exported_model = export_scripting(torch_model) File "D:\detectron2-master\detectron2-master\tools\deploy\export_lazy_config.py", line 103, in export_scripting ts_model = scripting_with_instances(ScriptableAdapter(), fields) File "c:\users\inaki\detectron2\detectron2\export\torchscript.py", line 55, in scripting_with_instances scripted_model = torch.jit.script(model) File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_script.py", line 1265, in script return torch.jit._recursive.create_script_module( File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_recursive.py", line 454, in create_script_module return create_script_module_impl(nn_module, concrete_type, stubs_fn) File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_recursive.py", line 516, in create_script_module_impl script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn) File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_script.py", line 594, in _construct init_fn(script_module) File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_recursive.py", line 494, in init_fn scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn) File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_recursive.py", line 520, in create_script_module_impl create_methods_and_properties_from_stubs(concrete_type, method_stubs, property_stubs) File "C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch\jit_recursive.py", line 371, in create_methods_and_properties_from_stubs concrete_type._create_methods_and_properties(property_defs, property_rcbs, method_defs, method_rcbs, method_defaults) RuntimeError: forward(torch.detectron2.modeling.meta_arch.fcos.FCOSHead self, Tensor features) -> ((Tensor[], Tensor[], Tensor[])): Expected a value of type 'Tensor (inferred)' for argument 'features' but instead found type 'List[Tensor]'. Inferred 'features' to be of type 'Tensor' because it was not annotated with an explicit type. Empty lists default to List[Tensor]. Add a variable annotation to the assignment to create an empty list of another type (torch.jit.annotate(List[T, []]) where T is the type of elements in the list for Python 2) :
`File "c:\users\inaki\detectron2\detectron2\modeling\meta_arch\dense_detector.py", line 96
features = self.backbone(images.tensor)
features = [features[f] for f in self.head_in_features]
predictions = self.head(features)
~~~~~~~~~ <--- HERE
if self.training:`
Thanks for your response
FCOSHead.forward
needs to have type annotation just like RetinaNetHead.forward
.
Hi, any new updates on this? I got exactly the same error when trying to deploy the new mask-rcnn baseline with lazy config.
I am trying to export a model trained with a custom dataset to torchscript.
Any help would be appreciated
Instructions To Reproduce the Issue and Full Logs
I trained a model and now I am trying to export it to torchscript but I am having some problems with it
I run the following command:
export_lazy_config.py --config-file "path to .yaml with the config" --format torchscript --export-method scripting --output /export_output
I got the following error: Module 'ResNet' has no attribute '_out_features' (This attribute exists on the Python module, but we failed to convert Python type: 'omegaconf.listconfig.ListConfig' to a TorchScript type. Only tensors and (possibly nested) tuples of tensors, lists, or dictsare supported as inputs or outputs of traced functions, but instead got value of type ListConfig.. Its type was inferred; try adding a type annotation for the attribute.)
Here is the log:
Your Environment
sys.platform win32 Python 3.10.3 | packaged by conda-forge | (main, Mar 28 2022, 05:19:17) [MSC v.1916 64 bit (AMD64)] numpy 1.22.3 detectron2 0.6 @c:\users\inaki\detectron2\detectron2 Compiler MSVC 192930141 CUDA compiler not available DETECTRON2_ENV_MODULE PyTorch 1.11.0 @C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torch PyTorch debug build False GPU available Yes GPU 0 NVIDIA GeForce RTX 3050 Laptop GPU (arch=8.6) Driver version 512.59 CUDA_HOME C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6 Pillow 9.0.1 torchvision 0.12.0 @C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torchvision torchvision arch flags C:\Users\Inaki.conda\envs\ScientificProject\lib\site-packages\torchvision_C.pyd; cannot find cuobjdump fvcore 0.1.5.post20220305 iopath 0.1.9 cv2 4.5.5