Getting transparency violation error while trying to parallel processing a code in MATLAB

5 views (last 30 days)
I am implementing GA in CNN. While calculating Fitness scores, i am trying to run that code on local parallel server using parfor loops but getting the error "Transparency violation error" inparfor loop.
I am sharing my code for your reference:
function scores = ga_fitness(x,convLayers,trainKidneyData,testKidneyData,imgLength,imgWidth)
% x is population size here.
persistent genNumber; % creates a variable named genNumber;
if(isempty(genNumber)) % initialize the gen number as 1 to calculate the fintess of population of generation 1.
genNumber = 1;
end
scores = zeros(size(x,1),1); %creates a matrix having dimension(popSize*1) to with Zero values. Fitness value of each network is stores in this matrix later.
parfor i=1:size(x,1) %the loop will repeat equal to the number of popSize.
%defining the layers
convConfig = x{i}; % saving the ith population of generation for which the fitness is to be calculated in convConfig.
% create the network architecture.
genConvnetConfig(convLayers,convConfig(1:convLayers),convConfig(convLayers+1:2*convLayers),imgLength,imgWidth);
run('tempScript.m');
%specify the training options
options = trainingOptions('sgdm','MaxEpochs',15,'MiniBatchSize',30,...
'InitialLearnRate',0.001,'verbose',1);
%train the network using training data
kidneyConvnet = trainNetwork(trainKidneyData,layers,options);
%classify the images using trained network
YTest = classify(kidneyConvnet,testKidneyData);
TTest = testKidneyData.Labels;
%calculate accuracy
accuracy = 100*sum(YTest == TTest)/numel(TTest);
scores(i) = accuracy;
% sscores=sscores+scores(i);
% Display the genration number, individual number, accuracy of that individual, number and size of filters in that individual network.
dispString = strcat('======Generation : ',string(genNumber),'========Individual : ',string(i),'============');
disp(dispString);
dispAccuracy = strcat('Accuracy : ', string(accuracy));
disp(dispAccuracy);
filterNumbersString = strcat('Filter Numbers = ', string(convConfig(1:convLayers)));
filterSizesString = strcat('Filter Sizes = ', string(convConfig(convLayers+1:2*convLayers)));
disp(filterNumbersString);
disp(filterSizesString);
end
Getting the error:
Error using run (line 55)
Transparency violation error.
See Parallel Computing Toolbox documentation about Transparency
Error in ga_fitness (line 9)
parfor i=1:size(x,1) %the loop will repeat equal to the number of popSize.
Please help me to fix this error

Accepted Answer

Walter Roberson
Walter Roberson on 21 Jul 2020
genConvnetConfig(convLayers,convConfig(1:convLayers),convConfig(convLayers+1:2*convLayers),imgLength,imgWidth);
run('tempScript.m');
We can deduce from the fact that there is no output variable on the gen* call that it is creating the file testScript that you then run(). It is not permitted to run a script directly inside a parfor loop.
What you need to do is put that work inside a function and call the function, making sure that you either do all the work connected with the variables that the script creates, or else that you return those variables from the function.

More Answers (0)

Categories

Find more on Get Started with Statistics and Machine Learning Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!