Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Hi everybody, I have a problem with running the program .

조회 수: 2 (최근 30일)
mosbahi sourour
mosbahi sourour 2017년 3월 30일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi everybody, I have a problem with running the program .
there is an error like this ???
Index exceeds matrix dimensions.
in this four instructions
imagesTrain = reshape (images(:,:,:,indsTrain),insz(1),insz(2),[]);
imagesVal = reshape(images(:,:,:,indsVal), insz(1),insz(2),[]);
labelsTrain = reshape(labels(:,:,:,indsTrain),insz(1),insz(2),[]);
labelsVal = reshape(labels(:,:,:,indsVal), insz(1),insz(2),[]);
How is the solution of the error?
  댓글 수: 5
Stephen23
Stephen23 2017년 3월 31일
편집: Stephen23 2017년 3월 31일
mosbahi sourour's "Answer" moved here and formatted correctly:
This is the program :
functionimdb=setupImdbIBSRv2(net,indsTrain,indsVal,augment,view)
if nargin < 2, indsTrain = 1:5; end if nargin < 3, indsVal = []; end
if nargin < 4, augment = true;end
if nargin < 5, view = 1; end
% Read original patches
switch view
case {1,'axial'}
permvec = [1 2 3];
case {2, 'sagittal'}
permvec = [2 3 1];
case {3, 'coronal'}
permvec = [3 1 2];
otherwise
error('Invalid view')
end
paths = setPaths();
dirs = dir(paths.IBSR); dirs = dirs(~ismember({dirs.name},{'.','..','.DS_Store','README.txt'}));
nFiles = numel(dirs); assert(nFiles == 18);
insz = [256,128,256];
insz = insz(permvec); nChannelsPerVolume = insz(3);
images = zeros(insz(1),insz(2),nChannelsPerVolume,nFiles, 'uint8');
labels = zeros(insz(1),insz(2),nChannelsPerVolume,nFiles, 'uint8');
tmpSeg = zeros(insz(1),insz(2),nChannelsPerVolume, 'uint8');
ibsrLabels = [0,2,3,4,5,7,8,10,11,12,13,14,15,16,17,18,24,26,28,29,30,41,...
42,43,44,46,47,48,49,50,51,52,53,54,58,60,61,62,72];
labelMap = containers.Map(ibsrLabels,0:numel(ibsrLabels)-1);
ticStart = tic;
for i=1:nFiles
imgPath = fullfile(paths.IBSR, dirs(i).name, [dirs(i).name '_ana_strip.nii']);
segPath = fullfile(paths.IBSR, dirs(i).name, [dirs(i).name '_seg_ana.nii']);
if ~exist(imgPath,'file') && exist([imgPath '.gz'],'file')
gunzip([imgPath '.gz']);
end
if ~exist(segPath,'file') && exist([segPath '.gz'],'file')
gunzip([segPath '.gz']);
end
img = load_nii(imgPath);
seg = load_nii(segPath);
img.img = permute(img.img, permvec);
seg.img = permute(seg.img, permvec);
assert(size(img.img,3) == nChannelsPerVolume)
tmpSeg(:) = 0;
for j=1:numel(ibsrLabels)
tmpSeg(seg.img == ibsrLabels(j)) = labelMap(ibsrLabels(j));
end
images(:,:,:,i) = 255*bsxfun(@rdivide,single(img.img), single(max(max(img.img))));
labels(:,:,:,i) = tmpSeg;
progress('Reading ISBR images',i,nFiles,ticStart);
end
imagesTrain = reshape (images(:,:,:,indsTrain),insz(1),insz(2),[]);
imagesVal = reshape(images(:,:,:,indsVal), insz(1),insz(2),[]); clear images;
labelsTrain = reshape(labels(:,:,:,indsTrain),insz(1),insz(2),[]);
labelsVal = reshape(labels(:,:,:,indsVal), insz(1),insz(2),[]); clear labels;
assert(size(imagesTrain,3) == numel(indsTrain) * nChannelsPerVolume);
assert(size(imagesVal ,3) == numel(indsVal) * nChannelsPerVolume)
complete copy of the error message
Index exceeds matrix dimensions.
Error in cnn>setupImdbIBSRv2 (line 179)
imagesTrain = reshape (images(:,:,:,indsTrain),insz(1),insz(2),[]);
Jan
Jan 2017년 3월 31일
And the complete error message is? We need to know at least the failing line.

답변 (1개)

John D'Errico
John D'Errico 2017년 3월 31일
When you get the error, what is the shape of images, and insz?
size(images)
size(insz)
Also, what are the values of indsTrain and indsval at that time?
One of those variables is not the size you are expecting it to be.
I cannot answer your question, because I cannot run your code as you ran it. I don't have the input arguments, nor do I know what you passed into the function. But you can determine all of this easily.
The trick is to use the debugger. Set this flag at the command line, then run your code. That will have the debugger stop when it sees an error, and then you can do the tests I showed above. That will give you everything you need to answer the question yourself.
dbstop if error
  댓글 수: 2
mosbahi sourour
mosbahi sourour 2017년 3월 31일
편집: Walter Roberson 2017년 3월 31일
the programme in this link https://github.com/tsogkas/brainseg
the name of program CNN. m
John D'Errico
John D'Errico 2017년 4월 1일
I told you what to do, how to debug the problem. Only you can do the rest.

이 질문은 마감되었습니다.

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by