PyTorch Model can only recognize birds when birds are close to camera
update 1

The easiest way to stop cropping images is: to pass in a tuple to size parameter.

So it looks like this:

size=(299,299)


Unfortunately, it does not solve my problem. So the question is still opening.



I just trained my birds model. It works fine when I was testing it with close pictures.

But when I moved the pictures further away my camera, the model was not able to detect birds.

My guess is in this line of code

data = ImageDataBunch.from_folder(path=path_img, bs=48, valid_pct= 0.2, ds_tfms=get_transforms(), size=299, classes=['birds', 'others'])


The 


  get_transforms()


and 


  size=299


the function and size parameters crop my training images to centralize the images, so that birds in the images appear to be closer to the camera.

How to fix it?




Your dataset is biased toward birds at a certain scale, i.e., their size, in pixels, span a very small range (you can verify this).
Center-cropping the images will not change that - the size of the birds (in pixels) will not change.
Therefore, your model cannot handle scale changes.

In order to overcome this limitation of the model you need to make it more scale-robust.
The simplest way to achieve this is to add scale augmentations to your data loader (before the crop). By introducing random scale to each training image you effectively change the size of the bird (in pixels) thus your model "sees" birds with a wider range of sizes (in pixels).
