Skip to content

ImportError caused by customed layer

namizzz edited this page Sep 22, 2018 · 2 revisions

PyTorch :

https://github.com/Microsoft/MMdnn/issues/241

https://github.com/Microsoft/MMdnn/issues/281


Keras :

from keras.models import load_model
from your_custom_layer import your_custom_layer1, your_custom_layer2, your_custom_layer3
from mmdnn.conversion.keras.keras2_parser import Keras2Parser

def load_custom_model(modelPath):
    model = load_model(modelPath, custom_objects={
                                                   'custom1': your_custom_layer1, 
                                                   'custom2': your_custom_layer2, 
                                                   'custom3': your_custom_layer3})
    return model



if __name__ == '__main__':
    model = load_custom_model("./model.h5")
    print(model.summary())

    parser = Keras2Parser(model)
    parser.run('custom')