Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Machine Learning by (47.6k points)

This is my code that works if I use other activation layers like tanh:

model = Sequential()

act = keras.layers.advanced_activations.PReLU(init='zero', weights=None)

model.add(Dense(64, input_dim=14, init='uniform'))

model.add(Activation(act))

model.add(Dropout(0.15))

model.add(Dense(64, init='uniform'))

model.add(Activation('softplus'))

model.add(Dropout(0.15))

model.add(Dense(2, init='uniform'))

model.add(Activation('softmax'))

sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)

model.compile(loss='binary_crossentropy', optimizer=sgd)

model.fit(X_train, y_train, nb_epoch=20, batch_size=16, 

show_accuracy=True, validation_split=0.2, verbose = 2)

In this case, it doesn't work and says "TypeError: 'PReLU' object is not callable" and the error is called at the model.compile line. Why is this the case? All the non-advanced activation functions work. However, neither of the advanced activation functions, including this one, works.

1 Answer

0 votes
by (33.1k points)

You can use the advance activations like PReLU with add() method and not wrapping it using Activation class. 

For example:

model = Sequential()

act = keras.layers.advanced_activations.PReLU(init='zero', weights=None)

model.add(Dense(64, input_dim=14, init='uniform'))

model.add(act)

Hope this answer helps.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...