onnx / keras-onnx

Convert tf.keras/Keras models to ONNX
Apache License 2.0
379 stars 109 forks source link

RuntimeError: Unexpected error on find the converter for op <class 'mrcnn.model.BatchNorm'> #715

Open RyuAmakaze opened 3 years ago

RyuAmakaze commented 3 years ago

I'm trying to convert a MaskRCNN model (.h5) to .onnx with keras2onnx.

Execution code keras2onnx.convert_keras(model.keras_model, "test1.onnx", target_opset=11)

Error message RuntimeError: Unexpected error on find the converter for op <class 'mrcnn.model.BatchNorm'> MaskRCNN's BatchNorm corresponds to BatchNormalization in onnx's Operator Schemas, but the names are different, so we get an error.

System information OS Platform and Distribution : windows10 ONNX version : 1.9.0 Python version: : 3.7.10 keras2onnx : 1.8.0 tensorflow-gpu =1.14.0 (MaskRCNN is not well compatible with tf2.x.) keras : 2.2.4

Reproduction instructions using maskRCNN


import config
import mrcnn.model as modellib
import os
from mrcnn import utils

model = modellib.MaskRCNN(mode="training", config=config,
model_dir="logs/model")
config = Config()

MODEL_PATH = 'mask_all.h5'
model.load_weights(MODEL_PATH, by_name=True,
exclude=["mrcnn_class_logits", "mrcnn_bbox_fc",
"mrcnn_bbox", "mrcnn_mask"])

import keras2onnx
keras2onnx.convert_keras(model.keras_model, "mask_all.onnx", target_opset=11)

Expected behavior Mask_all.onnx is generated by converting mask_all.h5.

RyuAmakaze commented 3 years ago

Just edit operator definitions? If it's solution, I would like to know how to edit the operator definition.