필터 지우기
필터 지우기

How to match format of data for 3D (4D) CNN ??

조회 수: 3 (최근 30일)
Petr Kolar
Petr Kolar 2022년 8월 4일
댓글: Petr Kolar 2023년 9월 15일
Hi,
I want to process 3D time series by CNN in sequence-to-sequence mode. But I am unable to fit format of Patterns and Responses for 3D CNN.
Example of the problem:
function testInputCNN_4D
% some data - any random numbers for formal check
N=20; % number of datasets
for n = 1:N
% data sizes:
% size_1 x size_2 x number of samples x 3 channels ( eg. [R G B])
signalPattern{n}=rand(4,4,10,3);
signalRespons{n}=rand(4,4,10,3);
end
% simple Net to demonstrate the problem
layers = layerGraph();
layers1 = [
sequenceInputLayer([4 4 10 3],"Name","sequence")
convolution3dLayer([3 3 3],3,"Name","conv3d_1","Padding","same")
softmaxLayer("Name","softmax")
regressionLayer("Name","regressionoutput")];
lgraph = addLayers(layers,layers1);
plot(lgraph);
% training
maxEpochs = 5;
miniBatchSize = 4;
options = trainingOptions('adam', ...
'MaxEpochs',maxEpochs, ...
'MiniBatchSize',miniBatchSize, ...
'InitialLearnRate',0.022, ...
'GradientThreshold',0.7, ...
'Shuffle','never', ...
'Plots','training-progress',...
'ExecutionEnvironment','cpu',...
'Verbose',0);
CNNtest4D = trainNetwork(signalPattern',signalRespons',lgraph,options);
end
%=======eof====
the trainign process starts, but imediattely finshes with errors:
Error using trainNetwork
Array inputs have incompatible channel dimensions.
Error in testInputCNN_4D (line 47)
CNNtest4D = trainNetwork(signalPattern',signalRespons',lgraph,options);
Caused by:
Error using builtin
Array inputs have incompatible channel dimensions.
even if the formal check by Deep Network Designer is OK.
Welcome any idea or working example ....

채택된 답변

Kausthub
Kausthub 2023년 9월 12일
Hi Petr Kolar,
I understand that you are facing errors while trying to fit a 3D CNN model and unsure about the format of data.
From the error message it looks like a case of channel dimension mismatch and the example that you have provided runs successfully. I suggest you to:
  • Check the dimensions of your input arrays and ensure that the channel dimensions are compatible for the operation or function you are using.
  • Verify that you are indexing or slicing arrays correctly along the channel dimension.
Also, if your data consists of 3D images it is recommended to use ‘image3dInputLayer’ instead of ‘sequenceInputLayer’. Refer the following documentation for a better understanding: https://www.mathworks.com/help/deeplearning/ref/nnet.cnn.layer.image3dinputlayer.html
Below mentioned are some references that might be useful for you:
Hope this helps and clarifies your issue regarding format of data for 3D CNN!
  댓글 수: 1
Petr Kolar
Petr Kolar 2023년 9월 15일
Hallo,
thank you for the answer - generally you are of course rigth, but above given data are only an example. My real data are time-series (so I need 'sequensInputLayer'), and aso the spatial dimensions and configuration play their role. However my problem was meanwhile (partly) solved by using a "macro" function 'unet3dLayers' which designs working NN sturcture based on available functions. In addition (my) time-series have to be fold ('sequenceFoldingLayer') and unfold then ('sequenceUnfoldingLayer') to persist original data structure.
Regard Petr

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by