why am i getting this error with activation function in my code

7 vues (au cours des 30 derniers jours)
Reesha deevina Lobo
Reesha deevina Lobo le 29 Mar 2023
Réponse apportée : Jack le 29 Mar 2023
layers = [fullyConnectedLayer(num_neurons, 'ActivationFunction', activation_function) fullyConnectedLayer(1, 'ActivationFunction', 'purelin')];
i am getting this error
Error using fullyConnectedLayer
layers = [fullyConnectedLayer(num_neurons, 'ActivationFunction', activation_function) fullyConnectedLayer(1, 'ActivationFunction', 'purelin')];
Invalid argument name 'ActivationFunction'. Name must be one of these:
'Name'
'WeightLearnRateFactor'
'BiasLearnRateFactor'
'WeightsInitializer'
'BiasInitializer'
'WeightL2Factor'
'BiasL2Factor'
'Weights'
'Bias'
Error in ann (line 14)
layers = [fullyConnectedLayer(num_neurons, 'ActivationFunction', activation_function) fullyConnectedLayer(1, 'ActivationFunction', 'purelin')];
>> ann

Réponses (1)

Jack
Jack le 29 Mar 2023
Hi,
The error message suggests that the argument 'ActivationFunction' is not a valid argument for the fullyConnectedLayer function.
In recent versions of MATLAB (R2020b and later), the ActivationFunction argument has been replaced with Activation. Therefore, the correct syntax to specify the activation function for a fully connected layer in these versions would be:
layers = [fullyConnectedLayer(num_neurons, 'Activation', activation_function)fullyConnectedLayer(1, 'Activation', 'linear')];
Note that the 'purelin' activation function has been replaced with 'linear'.
If you are using an older version of MATLAB, you can try removing the 'ActivationFunction' argument and use the default activation function ('relu'):
layers = [fullyConnectedLayer(num_neurons)fullyConnectedLayer(1, 'ActivationFunction', 'purelin')];
Alternatively, you can specify the activation function using the 'Name' argument, like this:
layers = [fullyConnectedLayer(num_neurons, 'Name', 'fc1', 'ActivationFunction', activation_function) fullyConnectedLayer(1, 'Name', 'output', 'ActivationFunction', 'purelin')];
Here, 'fc1' and 'output' are the layer names, and activation_function is the name of the desired activation function (e.g., 'relu', 'sigmoid', etc.).

Catégories

En savoir plus sur Install Products dans Help Center et File Exchange

Tags

Produits


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by