Repository: Lightning-Universe/lightning-flash

Issue:
Document `ObjectDetectionData` transforms
## 📚 Documentation

It is possible (although not trivial) to get bounding box augmentations / transforms working with `ObjectDetectionData` (see #414). We should document this somewhere, ideally providing some examples.

cc @hzitoun



Discussion:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Hi @ethanwharris , I've experience working with object-detection and data-augmentation through albumentatations. If it's still needed I start working on the issue :)
Hi @gianscarpe, some documentation here would definitely be welcome :smiley: Our object detection now relies on IceVision underneath so our support for albumentations is much better than it used to be. You should now be able to wrap albumentations augmentations in the `IceVisionTransformAdapter` (maybe the name `AlbumentationsAdapter` or something would be better?) here: https://github.com/PyTorchLightning/lightning-flash/blob/cf86275d629092e4c43f2d996061bff7abe17784/flash/core/integrations/icevision/transforms.py#L198

There's a couple of examples further down that page where we use the default transforms from IceVision. It would be very welcome for you to add a documentation section about this similar to what we have for image classification here: https://lightning-flash.readthedocs.io/en/latest/reference/image_classification.html#custom-transformations

Thanks for your help :smiley:
Hi @ethanwharris, I'd like to discuss a feature that maybe it's missing. Let me know if a new issue is more appropriate. 
Detectron2 library allows to evaluate a model using the standard COCO evaluator by wrapping it inside an evaluator function. I find this feature extremely compelling, especially since evaluator object-detector is not trivial. Do you plan to add similar features to flash?
Hi @gianscarpe in theory we should now support this, but it would be great for you to try i out and maybe update the documentation there if you're interested. The way it should work is that you can pass a metric from Icevision to the ObjectDetector task. Here's some code that _should_ be working:
```
from icevision.metrics import COCOMetric, COCOMetricType

model = ObjectDetector(..., metrics=[COCOMetric(COCOMetricType.bbox)])
```

Let me know if that works and how the experience there could be improved! :smiley:

Resolving patch:
diff --git a/flash/core/integrations/icevision/transforms.py b/flash/core/integrations/icevision/transforms.py
--- a/flash/core/integrations/icevision/transforms.py
+++ b/flash/core/integrations/icevision/transforms.py
@@ -196,7 +196,13 @@ def from_icevision_predictions(predictions: List["Prediction"]):
 
 
 class IceVisionTransformAdapter(nn.Module):
-    def __init__(self, transform):
+    """
+    Args:
+        transform: list of transformation functions to apply
+
+    """
+
+    def __init__(self, transform: List[Callable]):
         super().__init__()
         self.transform = A.Adapter(transform)
 
diff --git a/flash/core/utilities/imports.py b/flash/core/utilities/imports.py
--- a/flash/core/utilities/imports.py
+++ b/flash/core/utilities/imports.py
@@ -17,7 +17,6 @@
 import types
 from importlib.util import find_spec
 from typing import List, Union
-from warnings import warn
 
 from pkg_resources import DistributionNotFound
 
@@ -107,19 +106,8 @@ def _compare_version(package: str, op, version) -> bool:
     from PIL import Image  # noqa: F401
 else:
 
-    class MetaImage(type):
-        def __init__(cls, name, bases, dct):
-            super().__init__(name, bases, dct)
-
-            cls._Image = None
-
-        @property
-        def Image(cls):
-            warn("Mock object called due to missing PIL library. Please use \"pip install 'lightning-flash[image]'\".")
-            return cls._Image
-
-    class Image(metaclass=MetaImage):
-        pass
+    class Image:
+        Image = object
 
 
 if Version:


Test patch: