I am encountering a persistent error with the predict function in the Deep Learning Toolbox within MATLAB 2024b.

조회 수: 11 (최근 30일)
The problem occurs even in a simplified test script designed to isolate the issue:
Matlab
% Basic Script to Test dlarray and predict
function network = initializeSimpleActorNetwork(inputSize, outputSize)
layers = [
featureInputLayer(inputSize, 'Name', 'state_input')
fullyConnectedLayer(outputSize, 'Name', 'output')
];
network = dlnetwork(layerGraph(layers));
end
inputSize = 1827;
outputSize = 10;
testDlarray = dlarray(randn(1, inputSize), 'CB');
testNetwork = initializeSimpleActorNetwork(inputSize, outputSize);
try
testPredict = predict(testNetwork, testDlarray);
disp('Prediction successful!');
disp(['Output size: ', num2str(size(testPredict))]);
catch ME
disp('Prediction failed!');
disp(['Error message: ', ME.message]);
end
Despite the dlarray being created with the correct size (1x1827) and the featureInputLayer being configured to accept an input of size 1827, the predict function consistently throws an error stating that it received an input of size 1.
Troubleshooting Steps Taken:
  • Reinstalled MATLAB 2024b.
  • Verified that the issue persists in the isolated test script.
  • Confirmed that the dlarray is correctly created and that the input layer is correctly configured.
  댓글 수: 1
Chika
Chika 2025년 3월 17일
Error message: Layer "state_input": Invalid input data. Invalid size of channel dimension. Layer expects input with channel dimension size 1827 but received input with size 1.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2025년 3월 17일
편집: Matt J 2025년 3월 17일
You need,
testDlarray = dlarray(randn(inputSize,1), 'CB');
or,
testDlarray = dlarray(randn(1, inputSize), 'BC');
  댓글 수: 1
Chika
Chika 2025년 3월 17일
this worked for the section of code . Although other errors are still there.
Thanks for your quick and brilliant response.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by