Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Error using reshape To RESHAPE the number of elements must not change in Matlab2016b

1 view (last 30 days)
hi I wrote these codes for classify Drone Images into 2 Objects:
imds=imageDatastore('C:\users\hossein\my documents\matlab\droneimagesfinal','fileextensions','.jpg');
target=[2;2;1;1;2;2;2;2;1;1;2;2;2;2;1;1;1;2;2;2;2;1;1;1;1;1;1;2;2;2;1;1;1;1;1;1;1;1;1;1;1;1;2;2;2;1;1;1;1;1;1;1;1;1;1;1;1;2;1;1;1;1;1;1;2;1;1;1;1;1;1;
1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;2;2;1;1;1;1;1;1;1;1;2;2;2;1;1;1;2;2;1;1;2;2;2;1;2;2;2;1;1;1;1;1;1;1;1;1;2;2;2;2;2;2;2;2;1;1;1;1;1;1;1;
1;1;1;1;1;1;1;1;2;2;2;2;2;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;2;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;2;2;2;1;1;1;1;1;1;1;1;1;1;1;
1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;2;2;2];
imds.Labels=target;
[testset,trainingset]= splitEachLabel(imds,0.3,'randomize');
tr_data=zeros(227,227,3,size(trainingset.Labels,1));
te_data=zeros(227,227,3,size(testset.Labels,1));
net=alexnet;
layer='fc7';
Te_F=[];
for i=1:size(testset.Labels,1)
img= readimage(testset,i);
I=zeros(227,227,3);
img=imresize(img,[227 227]);
I(:,:,1:3)=cat(3,img,img,img);
F=activations(net,I,layer);
F=reshape(F(1,1,:),1,4096);
Te_F=[Te_F,F];
end
Tr_F=[];
for i=1:size(trainingset.Labels,1)
img= readimage(trainingset,i);
I=zeros(227,227,3);
img=imresize(img,[227 227]);
I(:,:,1:3)=cat(3,img,img,img);
F=activations(net,I,layer);
F=reshape(F(1,1,:),1,4096);
Tr_F=[Tr_F,F];
end
but after run codes Matlab2016b says this Error: " Error using reshape
To RESHAPE the number of elements must not change."
Error in dronetest1 (line 24)
F=reshape(F(1,:,[]),1,4096);
please help me to fix this error.
  4 Comments
seyed hosein alhoseiny
seyed hosein alhoseiny on 2 Apr 2019
Also In WorkSpace Section Of Matlab, Output Variables calculated incorrectly
I Attach WorkSpace Section Image for My codes in this Comment.
Please See WorkSpace Section Image Dronetest2.jpg
seyed hosein alhoseiny
seyed hosein alhoseiny on 2 Apr 2019
for example In WorkSpace Section in Above Image Variable F must be Vector 1*4096 single
that in Above Image F calculated incorrectly equal to -0.4052
also Tr_F variable Must be 191*4096 single (Training data are 191 Number)
Te_F Variable Must be 82*4096 single (Test data are 82 Number)
I guess All of My codes Must modify
and Please See Errors For Last Lines Of codes for Accuracy Of model.

Answers (0)

This question is closed.

Products

Community Treasure Hunt

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

Start Hunting!