Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error converting keras model to pytorch #915

Open
nischa564 opened this issue Feb 20, 2021 · 1 comment
Open

Error converting keras model to pytorch #915

nischa564 opened this issue Feb 20, 2021 · 1 comment

Comments

@nischa564
Copy link

nischa564 commented Feb 20, 2021

Platform (like ubuntu 16.04/win10): win10

Python version: 3.8.5

Source framework with version (like Tensorflow 1.4.1 with GPU): Tensorflow 2.3.0 with GPU

Destination framework with version (like CNTK 2.3 with GPU): Pytorch 1.7.1

Pre-trained model path (webpath or webdisk path): https://keras.io/examples/vision/mnist_convnet/

Running scripts: mmconvert -sf keras -iw my_h5_model.h5 -df pytorch -om pytorch_model.pth

Hello, I try to convert a keras model to a pytorch model. The error I get is:

Traceback (most recent call last):
File "c:\users\nisch\anaconda3\envs\jntorchenv\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\nisch\anaconda3\envs\jntorchenv\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "C:\Users\Nisch\anaconda3\envs\jntorchenv\Scripts\mmconvert.exe_main
.py", line 7, in
File "c:\users\nisch\anaconda3\envs\jntorchenv\lib\site-packages\mmdnn\conversion_script\convert.py", line 102, in _main
ret = convertToIR._convert(ir_args)
File "c:\users\nisch\anaconda3\envs\jntorchenv\lib\site-packages\mmdnn\conversion_script\convertToIR.py", line 46, in _convert
parser = Keras2Parser(model)
File "c:\users\nisch\anaconda3\envs\jntorchenv\lib\site-packages\mmdnn\conversion\keras\keras2_parser.py", line 136, in init
self.keras_graph.build()
File "c:\users\nisch\anaconda3\envs\jntorchenv\lib\site-packages\mmdnn\conversion\keras\keras2_graph.py", line 48, in build
for pred in node.inbound_layers:
TypeError: 'InputLayer' object is not iterable

@nischa564
Copy link
Author

Hello, I solved this problem by using different versions:

Python version: 3.6.12

Source framework with version (like Tensorflow 1.4.1 with GPU): Tensorflow 1.15.2

Destination framework with version (like CNTK 2.3 with GPU): Pytorch 0.4.0

But now I am getting this error:
Traceback (most recent call last):
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\mmdnn\conversion\keras\keras2_parser.py", line 104, in init
from keras.applications.mobilenet import relu6
ImportError: cannot import name 'relu6'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Users\Nisch\anaconda3\envs\mmdnne\Scripts\mmconvert.exe_main
.py", line 7, in
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\mmdnn\conversion_script\convert.py", line 102, in _main
ret = convertToIR._convert(ir_args)
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\mmdnn\conversion_script\convertToIR.py", line 46, in _convert
parser = Keras2Parser(model)
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\mmdnn\conversion\keras\keras2_parser.py", line 120, in init
'DepthwiseConv2D': layers.DepthwiseConv2D
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\engine\saving.py", line 419, in load_model
model = deserialize_model(f, custom_objects, compile)
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\engine\saving.py", line 225, in deserialize_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\engine\saving.py", line 458, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\layers_init
.py", line 55, in deserialize
printable_module_name='layer')
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\utils\generic_utils.py", line 145, in deserialize_keras_object
list(custom_objects.items())))
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\engine\sequential.py", line 300, in from_config
custom_objects=custom_objects)
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\layers_init
.py", line 55, in deserialize
printable_module_name='layer')
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\utils\generic_utils.py", line 147, in deserialize_keras_object
return cls.from_config(config['config'])
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\engine\base_layer.py", line 1109, in from_config
return cls(**config)
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\layers\convolutional.py", line 490, in init
**kwargs)
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\layers\convolutional.py", line 117, in init
self.kernel_initializer = initializers.get(kernel_initializer)
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\initializers.py", line 508, in get
return deserialize(identifier)
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\initializers.py", line 503, in deserialize
printable_module_name='initializer')
File "c:\users\nisch\anaconda3\envs\mmdnne\lib\site-packages\keras\utils\generic_utils.py", line 138, in deserialize_keras_object
': ' + class_name)
ValueError: Unknown initializer: GlorotUniform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant