weecology / DeepForest

Python Package for Airborne RGB machine learning
https://deepforest.readthedocs.io/
MIT License
524 stars 176 forks source link

Improved zoom augmentations through albumentations. #735

Open bw4sz opened 3 months ago

bw4sz commented 3 months ago

One of the core challenges of machine learning for airborne biodiversity observation is trying to generalize across sensors and acquisition conditions. Given low data sizes, data augmentations are crucial for good generalization across resolutions, focal views and object size.

A quick search of albumentations suggests hits a few existing classes that should be useful:

https://huggingface.co/spaces/qubvel-hf/albumentations-demo?transform=Downscale

https://albumentations.ai/docs/api_reference/augmentations/crops/transforms/#albumentations.augmentations.crops.transforms.RandomSizedBBoxSafeCrop

https://huggingface.co/spaces/qubvel-hf/albumentations-demo?transform=RandomSizedBBoxSafeCrop

https://albumentations.ai/docs/api_reference/augmentations/geometric/transforms/#albumentations.augmentations.geometric.transforms.PadIfNeeded

Checklist

Optional

Om-Doiphode commented 3 months ago

Hi @bw4sz, should I remove the following function from the deepforest/dataset.py?

def get_transform(augment):
    """Albumentations transformation of bounding boxs."""
    if augment:
        transform = A.Compose(
            [A.HorizontalFlip(p=0.5), ToTensorV2()],
            bbox_params=A.BboxParams(format='pascal_voc', label_fields=["category_ids"]))

    else:
        transform = A.Compose([ToTensorV2()],
                              bbox_params=A.BboxParams(format='pascal_voc',
                                                       label_fields=["category_ids"]))

    return transform

And replace it with get_augmentations?

bw4sz commented 3 months ago

Sure, but i'd keep calling it transforms since that it is what it is, and the user wouldn't need to always do augmentation (validation), basically the A.compose statement with optional augmentations. maybe something like

def get_transform(augmentations=None):
    """Albumentations transformation of bounding boxes.
   Args:
        augmentations (str): Name of albumentations augmentation, e.g. "Downscale". For information see albumentations transforms (link). 
   """
  ...

Then loop through the named augmentations and generate them? Having users specify a string that finds a function is always a bit annoying, but its not too many to create if statements.

Om-Doiphode commented 3 months ago

Hi @bw4sz, the get_transform function will take the augmentations from the deepforest_config.yml file right? Not through the function parameter list right?

bw4sz commented 3 months ago

The general philosophy is to have a config argument, and then allow the user to overwrite it specifying an arg directly.