Search code examples
plotkeras

How to plot machine learning model horizontally?


I want to draw a machine learning model. In some paper, they draw models horizontally like Figure 11, 12, 13, 14, 15 in https://tches.iacr.org/index.php/TCHES/article/view/7388/6560. These seems to have drawn models from keras. How can I do like that?


Solution

  • You might use this example:

    from keras.models import Sequential
    from keras.layers import Dense, Activation
    
    model = Sequential([
        Dense(32, input_shape=(784,)),
        Activation('relu'),
        Dense(10),
        Activation('softmax'),
    ])
    
    from keras.utils import plot_model
    plot_model(model,
               show_shapes=True,
               to_file='model.png'
    )
    

    The result is:

    enter image description here