Search code examples
pythonfunctionkeraskeras-layer

How to use a layer the same way you use function in Keras?


I'm a student and beginner with Keras. I wonder how to use a layer such in the same way of a python function. I want to define a layers, a Dense one, for example, and then be able to compute the image of an x given by the layer.

Thanks and have a good day.


Solution

  • So first, take a look at Keras Functional API. That way you can do something like this:

    from keras.layers import *
    
    # load some data into x
    x = load()
    
    dense_output = Dense(4096, activation='relu')(x)
    dropout_output = Dropout(0.3)(dense_output)   
    ...
    

    You can do basically everything you need with Functional API. I hope this clarifies the situation for you :)