"Unrecognized function or variable 'iPadArray'." when using a trained network to predict test data

1 view (last 30 days)
I manually constructed a network and trained with GPU acceleration. But when I use the trained network to predict, I keep getting an error that "Unrecognized function or variable 'iPadArray'".
The codes that can reproduce the error are as follows
clear;clc
rng(17);
%% create the network with Resnet structure
wm = 'glorot';
net = layerGraph;
startLayer = [imageInputLayer([11,256,1],'Normalization','none');
convolution2dLayer([1 40],64,'Padding','same','Stride',[1 1],'WeightsInitializer',wm);
batchNormalizationLayer;
reluLayer;
maxPooling2dLayer([1 2],'Stride',[1 2],'Padding','same')];
net = net.addLayers(startLayer);
resunit = [convolution2dLayer([2 16],128,'Padding','same','Stride',[1 2],'WeightsInitializer',wm);
batchNormalizationLayer;
reluLayer;
convolution2dLayer([2 10],128,'Padding','same','Stride',[1 1],'WeightsInitializer',wm);
batchNormalizationLayer;
additionLayer(2)];
resunit_co = [convolution2dLayer([1 1],128,'Padding','same','Stride',[1 2],'WeightsInitializer',wm);
batchNormalizationLayer];
net = net.addLayers(resunit);
net = net.addLayers(resunit_co);
net = net.connectLayers('maxpool','conv_1');
net = net.connectLayers('maxpool','conv_3');
net = net.connectLayers('batchnorm_3','addition/in2');
lastlayer = [reluLayer;
convolution2dLayer([3 3],128,'Padding','same','Stride',[2 2],'WeightsInitializer',wm);
batchNormalizationLayer;
reluLayer;
fullyConnectedLayer(256,'WeightsInitializer',wm);
batchNormalizationLayer;
reluLayer;
fullyConnectedLayer(5,'WeightsInitializer',wm);
softmaxLayer];
net = net.addLayers(lastlayer);
net = net.connectLayers('addition','relu_2');
net = net.addLayers(classificationLayer);
net = net.connectLayers('softmax','classoutput');
%% train the network with randon data with gpu
xdata = rand(11,256,1,1e3);
ydata = categorical(randi(5,[1,1e3]));
trainOpt = trainingOptions('sgdm', ...
'MaxEpochs',10, ...
'MiniBatchSize',64, ...
'Plots','training-progress', ...
'Shuffle','every-epoch', ...
'ExecutionEnvironment','gpu', ...
'InitialLearnRate',1e-2, ...
'BatchNormalizationStatistics','population');
[netf, info] = trainNetwork(xdata,ydata,net,trainOpt);
%% make prediction and reproduce the error
xtest = rand(11,256,1,200);
ytest = netf.predict(xtest);

Answers (1)

Sai Pavan
Sai Pavan on 9 Oct 2023
Hi Wenyu,
I understand that you are trying to resolve the error "Unrecognized function or variable iPadArray" which arises when you try to get the predictions on the test set with a trained model.
The error message typically occurs when a variable or function is used before it has been defined or due to a typographical error. Please refer to the below page to learn various possible causes of this error:
Please refer to the below documentation to learn how to resolve the “Unrecognized function or variable” error:
Another suggestion to address the error would be to convert the input test data into a GPU-compatible format using thegpuArray” function before making predictions with the trained model.
Please refer to the below documentation to learn more about “gpuArray” function:
Hope it helps.
Regards,
Sai Pavan

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!