To detect birds and squirrels, we created a dataset to train the YOLOv5 model. After a week’s training with:

python3 -u train.py --data coco.yaml --cfg yolov5s.yaml --weights '' --batch-size 28 --workers 1

The model could recognize birds and squirrels properly except only for this image:

Why does the model recognize the right-side significant squirrel as a bird? Even though I tried a bigger model, the result was the same…

Only after researching the parameters of the function model() of YOLOv5, I found out we can use a different image size: 960 for detecting.

import inspect
import torch
import cv2

model = torch.hub.load('.', 'custom', path='last.pt', source='local')
#model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
model.eval()

image = cv2.imread(img)
results = model(img, size=960)
results.show()

The result is below for model(img, size=960)

Hmm, seems the single-stage YOLOv5 model is nearsighted, just like me…