AlexanderLutsenko / nobuco

Pytorch to Keras/Tensorflow/TFLite conversion made intuitive
MIT License
272 stars 17 forks source link

Unimplemented Nodes: roi_align #63

Closed hanspres1999 closed 2 months ago

hanspres1999 commented 3 months ago

I am trying to convert a pytorch model to TF lite using this module called nobuco, I am facing some serious trouble and would really appreciate some guidance/help. It's a Yolo model and the error stack ends with something that looks like this:

Unimplemented nodes:
FasterRCNN[torchvision.models.detection.faster_rcnn](float32_0<1,3,224,224>) -> [{"boxes": float32_13<5,4>, "labels": int64_11<5>, "scores": float32_12<5>}]
 ├· RoIHeads[torchvision.models.detection.roi_heads]({"0": float32_1<1,256,10,10>, "1": float32_2<1,256,10,10>, "pool": float32_3<1,256,5,5>}, [float32_4<61,4>], [(320, 320)], None) -> ([{"boxes": float32_10<5,4>, "labels": int64_11<5>, "scores": float32_12<5>}], {})
 │   │  MultiScaleRoIAlign[torchvision.ops.poolers]({"0": float32_1<1,256,10,10>, "1": float32_2<1,256,10,10>, "pool": float32_3<1,256,5,5>}, [float32_4<61,4>], [(320, 320)]) -> float32_9<61,256,7,7>
 │   │   │  _filter_input[torchvision.ops.poolers]({"0": float32_1<1,256,10,10>, "1": float32_2<1,256,10,10>, "pool": float32_3<1,256,5,5>}, ["0", "1", "2", "3"]) -> [float32_1<1,256,10,10>, float32_2<1,256,10,10>]
 │   │   ├· _multiscale_roi_align[torchvision.ops.poolers]([float32_1<1,256,10,10>, float32_2<1,256,10,10>], [float32_4<61,4>], (7, 7), 2, [0.03125, 0.03125], LevelMapper(k_min = 5, k_max = 5, s0 = 224, lvl0 = 4, eps = 1e-06)) -> float32_9<61,256,7,7>
 │   │   │   │  roi_align[torchvision.ops.poolers](float32_1<1,256,10,10>, float32_5<61,5>, output_size=(7, 7), spatial_scale=0.03125, sampling_ratio=2) -> float32_6<61,256,7,7>
 │   │   │   │   └· roi_align[torch._ops.torchvision](float32_1<1,256,10,10>, float32_5<61,5>, 0.03125, 7, 7, 2, False) -> float32_6<61,256,7,7>
 │   │   │   │  roi_align[torchvision.ops.poolers](float32_2<1,256,10,10>, float32_7<0,5>, output_size=(7, 7), spatial_scale=0.03125, sampling_ratio=2) -> float32_8<0,256,7,7>
 └   └   └   └   └· roi_align[torch._ops.torchvision](float32_2<1,256,10,10>, float32_7<0,5>, 0.03125, 7, 7, 2, False) -> float32_8<0,256,7,7>

----------------------------------------------------------------------
```-----
Exception                                 Traceback (most recent call last)
<ipython-input-11-8d29e12735cb> in <cell line: 1>()
----> 1 keras_model = nobuco.pytorch_to_keras(
      2     model,
      3     args=[dummy_image], kwargs=None,
      4     inputs_channel_order=ChannelOrder.TENSORFLOW,
      5     outputs_channel_order=ChannelOrder.TENSORFLOW,

/usr/local/lib/python3.10/dist-packages/nobuco/convert.py in pytorch_to_keras(model, args, kwargs, input_shapes, inputs_channel_order, outputs_channel_order, input_names, output_names, trace_shape, enable_torch_tracing, constants_to_variables, full_validation, validation_tolerance, return_outputs_pt, save_trace_html, debug_traces)
    349         print('Unimplemented nodes:')
    350         print(unimplemented_hierarchy.__str__(**vis_params))
--> 351         raise Exception('Unimplemented nodes')
    352 
    353     keras_op = keras_converted_node.keras_op

Exception: Unimplemented nodes

I have looked through the documentation and am unable to use the info in it to solve the error. Appreciate the help.

Thanks in advance.

chadrockey commented 3 months ago

Are you sure it's a yolo model? I think the ultralytics converter handles conversion to tf fine. Your error log makes it look like this is from torchvision.

hanspres1999 commented 2 months ago

It's a YOLO model which I got to know later as I was dealing with it like a black box. I handelled it with the Ultralytics API for conversion. Thanks!

AlexanderLutsenko commented 1 month ago

@hanspres1999 Hi! Sorry for late reply. That YOLO from Ultralytics, does it contain roi_align after conversion? I just don't see any suitable counterparts in Tensorflow, so implementing a node converter for it would likely be quite inefficient.