Reshape error in trainNetwork with fileDatastore
이전 댓글 표시
Hi,
I try to train NN with fileDatastore, where input is 1x21x1x100 in each mat file and output is 1x1x21x100 in each mat file.
My layers are:
inputsize=21;
Layers = [
imageInputLayer([1 inputsize 1],'Normalization','none')
fullyConnectedLayer(512)
reluLayer
fullyConnectedLayer(64)
reluLayer
fullyConnectedLayer(32)
reluLayer
fullyConnectedLayer(inputsize)
regressionLayer];
and the way I code fileDatastore is:
input = fileDatastore('Dataset_input','ReadFcn',@load);
inputDatat = transform(input,@(data) rearrange_datastore_input(data));
output = fileDatastore('Dataset_output','ReadFcn',@load);
outputDatat = transform(output,@(data) rearrange_datastore_output(data));
trainData=combine(inputDatat,outputDatat);
function image = rearrange_datastore_input(data)
image=data.input;
image= {image};
end
function image = rearrange_datastore_output(data)
image=data.output;
image= {image};
end
However, I keep getting errors as:
Error using trainNetwork (line 170)
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the
appropriate size for that dimension.
Caused by:
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the
appropriate size for that dimension.
I tried to debug a bit and find the problem is in singleInputSingleOutputCollateFcns.m file. Since my output is 1x1x21x100, matlab reshapes output for regression, where error occurs. When reshape, function reshapedCell = cellfun(@(x)reshape(x,outputSizes), cellData(:,col), 'UniformOutput', false); is called, where outputSizes=1,1,21; and element in cellData is of size 1x1x21x100, and thus reshape error occurs.
Is this problem caused by my output form? How should I set the dimension of output?
댓글 수: 2
Jeremy Hughes
2020년 5월 31일
My guess is that "1x21x1x100 in each mat file and output is 1x1x21x100" being different, there's something unexpected going on.
Does the same thing occur if you add a reshape to 21x100 in your rearrange_datastore_output function?
(PS, if you use the code format option in your post, it will be easier to understand your code.)
Haoqing Li
2020년 6월 1일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!