facebookarchive / fb.resnet.torch

Torch implementation of ResNet from http://arxiv.org/abs/1512.03385 and training scripts
Other
2.29k stars 664 forks source link

TenCrop, some doubts #167

Open jessika0991 opened 7 years ago

jessika0991 commented 7 years ago

Hi,

I have some trouble understanding exactly what happens when tenCrop is applied to the input. When I don't use the TenCrop option I have an input of 32 images with dimensions 3x224x224. When I enable this option I get an input of 30 images with dimensions 3x224x224. Why is this happening? How is the batch size set?

colesbury commented 7 years ago

The batch size is set by the command line argument -batchSize. With the -tenCrop setting, your 30 images are actually 3 unique pictures with 10 crops each. (3x10x3x224x224). It's folded into a batch of 30 images (30x3x224x224) so that it works with the rest of the code.

jessika0991 commented 7 years ago

Thanks for the fast reply. I still don't understand few things:

  1. How do you set the number 3 in this instruction local indices = perm:narrow(1, idx, math.min(batchSize, size - idx + 1))? When idx is 1 I should get indices:size(1) = 32 but I get 3 instead.

  2. If I remove some instruction from TenCrop function in such a way that I can get 32 crops of 4 images, do I need to change some instruction regarding the batchSize?

colesbury commented 7 years ago
  1. The batch size is divided by 10 and rounded down when doing 10 crops. This is to avoid going out of memory: https://github.com/facebook/fb.resnet.torch/blob/master/dataloader.lua#L50. So [[32/10]] = 3.

  2. You probably want to change this line in dataloader.lua: https://github.com/facebook/fb.resnet.torch/blob/master/dataloader.lua#L47

jessika0991 commented 7 years ago

Thanks a lot. A last question, I am printing the confusion matrix at the end of the training but when the TenCrops option is enabled I get this error: Wrong size for view. Input size: 32. Output size: 4x1. I tried to add target to each crop

However I get an memory access error: THCudaCheck FAIL file=/tmp/luarocks_cutorch-scm-1-6377/cutorch/lib/THC/generic/THCStorage.c line=32 error=77 : an illegal memory access was encountered

There is something else I should change? Or maybe a better way to do this?

jessika0991 commented 7 years ago

Looking better at the generated error, there seems to be an error when the flag are set: https://github.com/torch/cutorch/blob/master/lib/THC/generic/THCStorage.c#L158 But I can't understand why this happens. Any hint?

Thanks