vlfeat / matconvnet-fcn

A MatConvNet-based implementation of the Fully-Convolutional Networks for image segmentation
Other
175 stars 125 forks source link

Index exceeds matrix dimensions error from the vl_nnloss fucntion #26

Open liyin2015 opened 8 years ago

liyin2015 commented 8 years ago

Hi, I used my own data with only 2 classes. But I got the following errors when I started to train. I do not know why it is. Could any body help me with the problem? Xmax 384 384 1 2

X 384 384 2 2

ci 384 384 1 2

Index exceeds matrix dimensions.

Error in vl_nnloss (line 225) t = Xmax + log(sum(ex,3)) - X(ci) ;

Error in SegmentationLoss/forward (line 6) outputs{1} = vl_nnloss(inputs{1}, inputs{2}, [], ...

Error in dagnn.Layer/forwardAdvanced (line 85) outputs = obj.forward(inputs, {net.params(par).value}) ;

Error in dagnn.DagNN/eval (line 88) obj.layers(l).block.forwardAdvanced(obj.layers(l)) ;

Error in cnn_train_dag>process_epoch (line 195) net.eval(inputs, opts.derOutputs) ;

Error in cnn_train_dag (line 90) stats.train(epoch) = process_epoch(net, state, opts, 'train') ;

Error in fcnTrain (line 138) info = cnn_train_dag(net, imdb, getBatchWrapper(bopts), ...

TianCongda commented 7 years ago

I have the same problem as yours. Have you fixed it?

physics-programmer commented 7 years ago

I have the same problem. I suppose that you have created your own getBatch function, et for labels uint8 class or single are not appropriate. I'm still investigating this problem, i found this on the original getBatch : tlabels = zeros(sz(1), sz(2), 'uint8') + 255 ; tlabels(oky,okx) = anno(sy(oky),sx(okx)) ; tlabels = single(tlabels(ly,lx)) ; tlabels = mod(tlabels + 1, 256) ; % 0 = ignore, 1 = bkg labels(:,:,1,si) = tlabels ;

tlabels switches from uint8 class to single with 0-255 integers values... si i tried single(uint8(labels)) but still have error

OluwoleOyetoke commented 7 years ago

Hi @abouSara , I am having similar issues. Have you found the solution to it yet?

physics-programmer commented 7 years ago

Yes i've found a solution thanks to the author or matconvnet-calvin (https://github.com/nightrome/matconvnet-calvin) For binary segmentation, numClasses = 2, and mask should contain values from 1 to 2 (numClasses). It should not contain 0 values neither 3-255 values. It's matlab indexing.

OluwoleOyetoke commented 7 years ago

Mine tells me Index exceeds matrix dimension at line 230 where we have case 'log' t = - log(x(ci)) ;

I'm wonderig what the problem could be. I am using a database with 39, 000 images divided into 43 clategories. What do you thing the issue might be @abouSara

OluwoleOyetoke commented 7 years ago

@abouSara I am not able to solve it yet. Could you please explain better?

physics-programmer commented 7 years ago

It's not very clear for me yet, but here is what works : 43 classes means that labels are 'single' matrix with value = 1 (for class1 objects) up to 43 for class 43 object. Usually images are valued from 0 to 255. By the way, for segmentation problems you should use 'softmaxlog' loss function.

staceywn commented 7 years ago

I am having similar issues. Have you found the solution ? @OluwoleOyetoke

physics-programmer commented 7 years ago

can you be more accurate on you problem ?

iiwindii commented 6 years ago

I have the same problem and still cannot figure out what's wrong

OluwoleOyetoke commented 6 years ago

Although I can't remember exactly how I solved the issues some months ago, you can look through my code here , probably you will find a helpful hint in there.

iiwindii commented 6 years ago

@OluwoleOyetoke Thanks for you reply. I have figured out the problem. The error is due to the parameter 'numGroups' in the fcnInitializeModel function as follows:net.addLayer('deconv32', ... dagnn.ConvTranspose(... 'size', size(filters), ... 'upsample', 32, ... 'crop', [16 16 16 16], ... 'numGroups', 17, ... 'hasBias', false, ... 'opts', net.meta.cudnnOpts), ... 'x38', 'prediction', 'deconvf') ; 'numGroups' should be set to the number of classes (17 for my problem) since the filter depth in this layer should divide numGroups. When I set 'numGroups' to 1 (17/1=17), the error was still there. Very confusing! Anyway, set it to 17 for my problem then everything is OK

OluwoleOyetoke commented 6 years ago

@fengyunxiaozi Thanks, this answer will be helpful to someone else in the future.