ptrblck:

Is FiveCrop slowing down the code and if so how long is an epoch taking without this transformation, i.e. for a single input only?


Yes, if I am using RandomCrop for size 224 then its takes 5 minutes for 1 epochs while 35 minutes is the output for other.



 ptrblck:

I’m not familiar with your use case and thus asked, if you could describe the general use case a bit.
E.g. if the image should get a single prediction, you could use the majority prediction of all 5 patches.
If all predictions are different, you could try to use the prediction with the highest logit.


Okay, Let me explain,  So I am solving a multi-class image classification problem. I have 3 classes and I am using Pytorch’s ImageFolder  data loader so the labels are 0,1,2.
My image size are (2k,2k), I can’t downsample the dataset because each distinct class image differs because of the texture of the image and downsampling making all the images look same.
So first, I resorted to RandomCrop, validation loss is skyrocketing high using the RandomCrop.
Then I moved to FiveCrop which is moving the validation loss in the range of training loss.
I am using the implementation of FiveCrop from the Pytorch documentation -
Below -
transform = Compose([
>>>    FiveCrop(size), # this is a list of PIL Images
>>>    Lambda(lambda crops: torch.stack([ToTensor()(crop) for crop in crops])) # returns a 4D tensor
>>> ])
>>> #In your test loop you can do the following:
>>> input, target = batch # input is a 5d tensor, target is 2d
>>> bs, ncrops, c, h, w = input.size()
>>> result = model(input.view(-1, c, h, w)) # fuse batch size and ncrops
>>> result_avg = result.view(bs, ncrops, -1).mean(1) # avg over crops

Personally, I want the inference to watch every part of image and then give the prediction but I don’t know how it will pan out in this case as image size is very large.
Please, let me know if I explained my use-case alright or not.(I’ll describe again)