You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
'Layer 1' is not a valid model name because it is not a valid MATLAB function name
142 views (last 30 days)
Show older comments
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
Fangjun Jiang
on 29 Apr 2019
Edited: Fangjun Jiang
on 29 Apr 2019
remove the white space. call it "Layer1" or "Layer_1"
13 Comments
mar gian
on 29 Apr 2019
Edited: mar gian
on 30 Apr 2019
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!
mar gian
on 1 May 2019
The R2018a . Is there any relation with the errors that appear? A common problem or something?
Fangjun Jiang
on 1 May 2019
I have R2018b. Running the above code brings up a GUI. I don't know what you mean by model or block.
mar gian
on 1 May 2019
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!
Fangjun Jiang
on 1 May 2019
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.
mar gian
on 1 May 2019
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!
Fangjun Jiang
on 2 May 2019
Got it run in R2018a. Model is generated and simulates. No error. Post your model if you still have issues.
mar gian
on 2 May 2019
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.
Walter Roberson
on 3 May 2019
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.
Fangjun Jiang
on 3 May 2019
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.
mar gian
on 4 May 2019
"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 !!!!!
More Answers (0)
See Also
Categories
Find more on Deep Learning with GPU Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)