'Layer 1' is not a valid model name because it is not a valid MATLAB function name

What does it mean is not a valid MATLAB function name? When I first generated a neural network with matlab 'Layer 1' name was autogenerated. How can i resolve this ? If I rename somehow the block name is enough or this may mean something else too?
Thanks in advance,
M

 Accepted Answer

remove the white space. call it "Layer1" or "Layer_1"

13 Comments

As I wrote its a automated generated neural network ...this is how I generate the model
[x,t] = engine_dataset;
trainRatio = 0.8; valRatio = 0; testRatio = 0.2;
[trainInd, valInd, testInd] = dividerand(size(x, 2), trainRatio, valRatio, testRatio);
% Train the a 2-layerd neural network with 10 neurons in the hidden layer
% using training data
net = fitnet(10);
net = train(net,x(:, trainInd),t(:, trainInd));
so how can I remove the white spaces? or better how can I rename it ??
p.s I did search before I post here.
UPDATE: I did found how to just change th block names..and I feel stupid because all it took was just a double-click on the name. Now when I tried to run it it shows an error of" Layer_1" is not loaded. I guess I should change it elsewhere too except just on the diagram. But I have really no clue where!
The R2018a . Is there any relation with the errors that appear? A common problem or something?
I have R2018b. Running the above code brings up a GUI. I don't know what you mean by model or block.
yes. as I wrote in the UPDATE section this code generates my neural network. After that with the command
[model_name, net_name] = gensim(net, 'Name', 'myNeural');
I am generating a simulink model . I am referring to the blocks there. My bad I put simulink on tags and nowhere else. So the thing is I found a way to rename the autogenerated blocks on my model (only by double clicking on the name) in simulink, but I should propably change it somewhere else too because it gives me an error for example : the block 'Layer_1' is not loaded.
I dont know where though!
There is no error in R2018b. I saw the block "Layer 1" and "Layer 2" but it simulates and no error.
Check the value of net.layers{1}.name and net.layers{2}.name. In R2018b, it is "Hidden" and "Output". It seems unrelated.
Might be a bug on the Mathworks side. Contact the technical support.
Hidden and Output is to my version as well.....I think it make some sense since Layer 1 is the hidden layer and layer 2 results the output. So i dont think there is my problem .
If I rename my blocks from "Layer 1" to "Layer1" should i just double click the name and change it or should I do something else too?
P.SThanks for taking the time to help me!
Got it run in R2018a. Model is generated and simulates. No error. Post your model if you still have issues.
This is what I am getting after renaming from "Layer 1" to "Layer_1" . If I dont change anything I get : 'Layer 1' is not a valid model name because it is not a valid MATLAB function name.
Screenshot (27).png
The space is inserted at roughly line 338 of gensim, in the block of code that starts with the comment 'Network Block Names'. sprintf('Layer %g', i) . There is nothing you could do at the user level to designate a different name. You could probably create some code to change the block names.
If you examine
you will see that spaces are permitted in block names except as the first character of the name.
Now, model names have to be valid MATLAB function names, but layer names are block names, not model names.
Perhaps you are attempting to somehow invoke a layer directly as-if it were a model? For example you cannot open_system() a block directly: you have to open_system() the block qualified by the model name.
The error message come from fxpoptdemo_neuralnetworks_script.m. It is looking for root level model "Layer_1" and block "Layer_1/tansig", which don't exist.
Using gensim() as it is, there is a block 'myNeural/Function Fitting Neural Network/Layer 1/tansig'. Using this in your script should get rid of this error.
"Perhaps you are attempting to somehow invoke a layer directly as-if it were a model? For example you cannot open_system() a block directly: you have to open_system() the block qualified by the model name"
Yes, I went through the code again and I found out that I had done this exact thing...
And even I renamed the block when autogenerated it kept showing errors. Anyway I changed that and now works fine.
MANY THANKS to both of you who responded and spend some amount of time !!!!!
Thank you, so we need to without spacing between the words

Sign in to comment.

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products

Release

R2018a

Asked:

on 29 Apr 2019

Commented:

on 3 Nov 2023

Community Treasure Hunt

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

Start Hunting!