Repository: Lightning-Universe/lightning-flash

Issue:
Trainer.finetune broken for Keypoint detection module
## 🐛 Bug

Finetuning the `KeypointDetector` with freeze strategy does not freeze the parameters.


### To Reproduce

Follow the [Keypoint detection example]( https://lightning-flash.readthedocs.io/en/latest/reference/keypoint_detection.html)


#### Code sample

```python
import flash
print(flash.__version__)
from flash.core.utilities.imports import example_requires
from flash.image import KeypointDetectionData, KeypointDetector

example_requires("image")

import icedata  # noqa: E402

data_dir = icedata.biwi.load_data()

datamodule = KeypointDetectionData.from_icedata(
    train_folder=data_dir,
    val_split=0.1,
    batch_size=4,
    parser=icedata.biwi.parser,
)

# 2. Build the task
model = KeypointDetector(
    head="keypoint_rcnn",
    backbone="resnet18_fpn",
    num_keypoints=1,
    num_classes=datamodule.num_classes,
)

# 3. Create the trainer and finetune the model
trainer = flash.Trainer(max_epochs=100, gpus=1)
trainer.finetune(model, datamodule=datamodule, strategy="freeze")

trainable = 0
for name, param in model.adapter.model.named_parameters(): # or try from torchsummary import summary?
    if param.requires_grad:
        o = (name, np.product(param.shape), param.requires_grad)
        if o[2]:
            trainable += o[1]
        print(*o)
print(trainable)
    
```




### Expected behavior

The number of trainable parameters should be smaller than 45.8M. Also, `trainer.fit` takes about as much time as `trainer.finetune`:

```
  | Name          | Type                              | Params
--------------------------------------------------------------------
0 | train_metrics | ModuleDict                        | 0     
1 | val_metrics   | ModuleDict                        | 0     
2 | test_metrics  | ModuleDict                        | 0     
3 | adapter       | IceVisionKeypointDetectionAdapter | 46.0 M
--------------------------------------------------------------------
45.8 M    Trainable params
156 K     Non-trainable params
46.0 M    Total params
183.924   Total estimated model params size (MB)
```

### Environment

```
efficientnet-pytorch          0.6.3
icevision                     0.11.0
lightning-bolts               0.4.0
lightning-flash               0.7.0.dev0
pytorch-lightning             1.5.6
segmentation-models-pytorch   0.2.1
torch                         1.10.0+cu111
torchaudio                    0.10.0+cu111
torchmetrics                  0.6.2
torchsummary                  1.5.1
torchtext                     0.11.0
torchvision                   0.11.1+cu111
```

### Additional context

<!-- Add any other context about the problem here. -->



Discussion:

Resolving patch:
diff --git a/flash/core/integrations/icevision/backbones.py b/flash/core/integrations/icevision/backbones.py
--- a/flash/core/integrations/icevision/backbones.py
+++ b/flash/core/integrations/icevision/backbones.py
@@ -36,7 +36,7 @@ def load_icevision(adapter, model_type, backbone, num_classes, **kwargs):
     model = model_type.model(backbone=backbone, num_classes=num_classes, **kwargs)
 
     backbone = nn.Module()
-    params = model.param_groups()[0]
+    params = sum(model.param_groups()[:-1], [])
     for i, param in enumerate(params):
         backbone.register_parameter(f"backbone_{i}", param)
 
diff --git a/flash/image/detection/model.py b/flash/image/detection/model.py
--- a/flash/image/detection/model.py
+++ b/flash/image/detection/model.py
@@ -49,7 +49,7 @@ def __init__(
         pretrained: bool = True,
         optimizer: OPTIMIZER_TYPE = "Adam",
         lr_scheduler: LR_SCHEDULER_TYPE = None,
-        learning_rate: float = 5e-3,
+        learning_rate: float = 1e-2,
         output: OUTPUT_TYPE = None,
         predict_kwargs: Dict = None,
         **kwargs: Any,
diff --git a/flash_examples/integrations/fiftyone/object_detection.py b/flash_examples/integrations/fiftyone/object_detection.py
--- a/flash_examples/integrations/fiftyone/object_detection.py
+++ b/flash_examples/integrations/fiftyone/object_detection.py
@@ -33,14 +33,20 @@
     val_split=0.1,
     transform_kwargs={"image_size": 128},
     parser=icedata.fridge.parser,
-    batch_size=4,
+    batch_size=8,
 )
 
 # 2. Build the task
-model = ObjectDetector(head="efficientdet", backbone="d0", num_classes=datamodule.num_classes, image_size=128)
+model = ObjectDetector(
+    head="efficientdet",
+    backbone="d0",
+    num_classes=datamodule.num_classes,
+    image_size=128,
+    lr_scheduler=("multisteplr", {"milestones": [20]}),
+)
 
 # 3. Create the trainer and finetune the model
-trainer = flash.Trainer(max_epochs=1)
+trainer = flash.Trainer(max_epochs=30)
 trainer.finetune(model, datamodule=datamodule, strategy="freeze")
 
 # 4. Set the output and get some predictions


Test patch: