Reshape error in trainNetwork with fileDatastore
Show older comments
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 Comments
Jeremy Hughes
on 31 May 2020
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
on 1 Jun 2020
Accepted Answer
More Answers (0)
Categories
Find more on Big Data Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!