MATLAB: Using GA and NN to find a cat face inside an image, problem in custom population and fitness function

ga nn

Hello, I am currently working on a project to identify a cat face inside an image using GA, I had a trained neural network that can classify whether the input image is cat or not. My problem is in developing the GA to find the best window that can correspond to the cat face, I have developed a custom popoulation func & custom fitness func but I had this error Error in Genetic_Algorithm_NN>PopFunction (line 32) I = imread('C:\Users\Mohamed\Desktop\Neural Networks\Assignment 3\100cats\00000016_018.jpg');
Error using feval
Output argument "pop" (and maybe others) not assigned during call to
"C:\Users\Mohamed\Desktop\Neural Networks\Assignment
3\Genetic_Algorithm_NN.m>PopFunction".
Error in makeState (line 30)
state.Population =
feval(options.CreationFcn,GenomeLength,FitnessFcn,options,options.CreationFcnArgs{:});
Error in gaunc (line 41)
state =
makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 348)
[x,fval,exitFlag,output,population,scores] =
gaunc(FitnessFcn,nvars, ...
Error in Genetic_Algorithm_NN (line 24)
[chromosome,~,~,~,~,~] = ga(@FitFunc,nvars,options);
I am really stuck and I don't know what should be fixed, you kindly help is highly appreciated I will post the code in the next comment thanks

Best Answer

Mohamed - the error message is telling you that there is something wrong with your function to generate the populations and so the output parameter pop, the initial population is not being assigned. Put a breakpoint in the first line of this function and then run the code. What happens? Note that you have two return calls in your code that fire if certain conditions are met. If these fire before pop has been created, then the error makes sense.