Konverter icon indicating copy to clipboard operation
Konverter copied to clipboard

Support for More Layers

Open frytoli opened this issue 2 years ago • 1 comments

Firstly, nice work on this project -- this looks really cool!

I'm working on a computer vision project, and would love to use Konverter to convert some pre-trained models. As such, these models include ZeroPadding2D layers. Because this layer type isn't supported, when I run Konverter on the model (yes I tried anyway haha) this is the resulting traceback and error:

Traceback (most recent call last): File "test.py", line 14, in konverter.konvert(os.path.join(os.getcwd(), 'models_eynollah', 'model_page_mixed_best.h5'), output_file=os.path.join(os.getcwd(), 'models', 'page_mixed_best.py')) File "/venv/lib/python3.7/site-packages/konverter/init.py", line 20, in init no_watermark=no_watermark) File "/venv/lib/python3.7/site-packages/konverter/init.py", line 41, in _konvert self.start() File "/venv/lib/python3.7/site-packages/konverter/init.py", line 45, in start self.get_layers() File "/venv/lib/python3.7/site-packages/konverter/init.py", line 214, in get_layers layer = support.get_layer_info(layer, next_layer) File "/venv/lib/python3.7/site-packages/konverter/utils/konverter_support.py", line 104, in get_layer_info layer_class.info.activation = self._get_layer_activation(layer) File "/venv/lib/python3.7/site-packages/konverter/utils/konverter_support.py", line 80, in _get_layer_activation if hasattr(layer.activation, '_keras_api_names'): AttributeError: 'ZeroPadding2D' object has no attribute 'activation'

Do you have any advice for how I could add functionality for more layers and/or would you consider adding support for more layers?

Thanks!

frytoli avatar Mar 01 '22 18:03 frytoli

Sorry for the late response, I haven't been working on this project for a while now! I would love to add support for new layers, but because I'm not actively using the project (for now), I have no need to add anything else.

Two things I would love someone to attempt a PR for are:

  • Support for functional models with multiple inputs and outputs
  • Support for new layers, especially convolutional types for images and video

If you attempt this, check out https://github.com/sshane/Konverter/blob/master/konverter/utils/model_attributes.py to see how I've defined the code for each activation/layer and try to add your own. The main code to parse each layer is here: https://github.com/sshane/Konverter/blob/master/konverter/utils/konverter_support.py#L91, however, it's super messy and not really well abstracted away, so you might want to do that at the same time so it doesn't get unwieldy. Good luck if you try anything! I can review and help on PRs as well.

sshane avatar Mar 25 '22 06:03 sshane