gmalivenko / pytorch2keras

PyTorch to Keras model convertor
https://pytorch2keras.readthedocs.io/en/latest/
MIT License
858 stars 144 forks source link

KeyError: 'Floor' #93

Open livecle opened 4 years ago

livecle commented 4 years ago

Describe the bug thanks for your code I tried to convert official PyTorch centernet, the backbone is hourglass, got this error.

Logs

DEBUG:onnx2keras:Check input 1 (name 1194).
DEBUG:onnx2keras:... found all, continue
DEBUG:onnx2keras:mul:Convert inputs to Keras/TF layers if needed.
WARNING:onnx2keras:mul:Failed to use keras.layers.Multiply. Fallback to TF lambda.
DEBUG:onnx2keras:######
DEBUG:onnx2keras:...
DEBUG:onnx2keras:Converting ONNX operation
DEBUG:onnx2keras:type: Floor
DEBUG:onnx2keras:node_name: 1196
DEBUG:onnx2keras:node_params: {'change_ordering': False, 'name_policy': 'keep'}
DEBUG:onnx2keras:...
DEBUG:onnx2keras:Check if all inputs are available:
DEBUG:onnx2keras:Check input 0 (name 1195).
DEBUG:onnx2keras:... found all, continue
Traceback (most recent call last):
  File "D:/chenle/github/CenterNet.git/trunk/src/demo_test.py", line 41, in <module>
    demo(opt)
  File "D:/chenle/github/CenterNet.git/trunk/src/demo_test.py", line 37, in demo
    k_model = pytorch_to_keras(detector.model, input_var, (3, 512, 512,), verbose=True,name_policy="keep",change_ordering=False)
  File "C:\Users\chenle\AppData\Local\conda\conda\envs\pytorch-gpu\lib\site-packages\pytorch2keras\converter.py", line 73, in pytorch_to_keras
    verbose=verbose, change_ordering=change_ordering)
  File "C:\Users\chenle\AppData\Local\conda\conda\envs\pytorch-gpu\lib\site-packages\onnx2keras\converter.py", line 165, in onnx_to_keras
    AVAILABLE_CONVERTERS[node_type](
KeyError: 'Floor'

Environment (please complete the following information):

poormag commented 4 years ago

Got the same problem, but KeyError: 'Squeeze' (

gmalivenko commented 4 years ago

Hello @livecle and @poormag.

I added support of Squeeze and Floor layers support for NCHW data format. Please, upgrade onnx2keras library to 0.0.11 using:

pip install --upgrade onnx2keras
poormag commented 4 years ago

@nerox8664 thanx, for Squeeze its okay now

livecle commented 4 years ago

@nerox8664 thank you for your reply. It looks work now, but I got another error.

Logs

DEBUG:onnx2keras:######
DEBUG:onnx2keras:...
DEBUG:onnx2keras:Converting ONNX operation
DEBUG:onnx2keras:type: Floor
DEBUG:onnx2keras:node_name: 1196
DEBUG:onnx2keras:node_params: {'change_ordering': False, 'name_policy': 'keep'}
DEBUG:onnx2keras:...
DEBUG:onnx2keras:Check if all inputs are available:
DEBUG:onnx2keras:Check input 0 (name 1195).
DEBUG:onnx2keras:... found all, continue
Traceback (most recent call last):
  File "D:\Program Files\JetBrains\PyCharm 2019.1.2\helpers\pydev\pydevd.py", line 1758, in <module>
    main()
  File "D:\Program Files\JetBrains\PyCharm 2019.1.2\helpers\pydev\pydevd.py", line 1752, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "D:\Program Files\JetBrains\PyCharm 2019.1.2\helpers\pydev\pydevd.py", line 1147, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:\Program Files\JetBrains\PyCharm 2019.1.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/chenle/github/CenterNet.git/trunk/src/demo_test.py", line 41, in <module>
    demo(opt)
  File "D:/chenle/github/CenterNet.git/trunk/src/demo_test.py", line 37, in demo
    k_model = pytorch_to_keras(detector.model, input_var, [(3, 512, 512,)], verbose=True,name_policy="keep",change_ordering=False)
  File "C:\Users\chenle\AppData\Local\conda\conda\envs\pytorch-gpu\lib\site-packages\pytorch2keras\converter.py", line 73, in pytorch_to_keras
    verbose=verbose, change_ordering=change_ordering)
  File "C:\Users\chenle\AppData\Local\conda\conda\envs\pytorch-gpu\lib\site-packages\onnx2keras\converter.py", line 170, in onnx_to_keras
    keras_names
  File "C:\Users\chenle\AppData\Local\conda\conda\envs\pytorch-gpu\lib\site-packages\onnx2keras\operation_layers.py", line 293, in convert_floor
    layers[node_name] = lambda_layer(input_0)
  File "C:\Users\chenle\AppData\Local\conda\conda\envs\pytorch-gpu\lib\site-packages\keras\engine\base_layer.py", line 489, in __call__
    output = self.call(inputs, **kwargs)
  File "C:\Users\chenle\AppData\Local\conda\conda\envs\pytorch-gpu\lib\site-packages\keras\layers\core.py", line 716, in call
    return self.function(inputs, **arguments)
  File "C:\Users\chenle\AppData\Local\conda\conda\envs\pytorch-gpu\lib\site-packages\onnx2keras\operation_layers.py", line 290, in target_layer
    return tf.floor(x)
  File "C:\Users\chenle\AppData\Local\conda\conda\envs\pytorch-gpu\lib\site-packages\tensorflow\python\ops\gen_math_ops.py", line 3680, in floor
    "Floor", x=x, name=name)
  File "C:\Users\chenle\AppData\Local\conda\conda\envs\pytorch-gpu\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 610, in _apply_op_helper
    param_name=input_name)
  File "C:\Users\chenle\AppData\Local\conda\conda\envs\pytorch-gpu\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 60, in _SatisfiesTypeConstraint
    ", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
TypeError: Value passed to parameter 'x' has DataType int32 not in list of allowed values: bfloat16, float16, float32, float64