Repository: activeloopai/Hub
File: deeplake/integrations/mmdet/mmdet_.py (Python)

Code before:
    - deeplake_dataloader: optional parameter. If specified represents the parameters of the deeplake dataloader. Deeplake dataloader parameters are: "shuffle", "batch_size", "num_workers". This parameter exists for train as well as for val.
        - "shuffle": if True shuffles the dataset.
        - "batch_size": size of batch. If not specified, dataloader will use samples_per_gpu.
        - "num_workers": number of workers to use. If not specified, dataloader will use workers_per_gpu.
- deeplake_dataloader_type: optional parameter. If specified represents the type of deeplake dataloader to use.
- deeplake_metrics_format: optional parameter. If specified represents the format of the deeplake metrics that will be used during evaluation. Default COCO. Avaliable values are: "COCO", "PascalVOC". 
  If COCO format is used, you can specify whether you want to evaluate on bbox only or also want to evaluate on masks. To do that you need to specify the format of the metric in metric. 
  
Ex:

>>>  deeplake_metrics_format = "COCO"
>>>  evaluation = dict(metric=["bbox"], interval=1)

- train_detector: Function to train the MMDetection model. Parameters are: model, cfg: mmcv.ConfigDict, ds_train=None, ds_train_tensors=None, ds_val: Optional[dp.Dataset] = None, ds_val_tensors=None, distributed: bool = False, timestamp=None, meta=None, validate: bool = True.
    - model: MMDetection model that is going to be used.
    - cfg: Configuration of the model as well as of the datasets and transforms that's going to be used.
    - ds_train: Optional parameter. It provided will overwrite deeplake_path in train, and will pass this tensor directly to the dataloader.
    - ds_val: Optional parameter. It provided will overwrite deeplake_path in val, and will pass this tensor directly to the dataloader.
    - ds_train_tensors: Optional parameter. It provided will overwrite deeplake_tensors in train, and will pass this tensor mapping directly to dataloader.
    - ds_val_tensors: Optional parameter. It provided will overwrite deeplake_tensors in val, and will pass this tensor mapping directly to dataloader.
    - distributed: Optional parameter. If provided will run the code on all available gpus. Meta data used to build runner
    - timestamp: variable used in runner to make .log and .log.json filenames the same.'
    - validate: bool, whether validation should be conducted, by default True

NOTE:
    gt_masks is optional parameter and lets say you want to train poure detecter this part is going to exclude. Other mappings are mandatory
    if you don't specify them explicitly they are going to be searched in the dataset according to tensor htype. Better to specify them explicitly

MMDetection Config Examples
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Below is the example of the deeplake mmdet configuration:


>>> _base_ = "../mmdetection/configs/yolo/yolov3_d53_mstrain-416_273e_coco.py"
>>> 
>>> # use caffe img_norm
>>> img_norm_cfg = dict(mean=[0, 0, 0], std=[255., 255., 255.], to_rgb=True)
>>> 
>>> train_pipeline = [
>>>     dict(type='LoadImageFromFile'),
>>>     dict(type='LoadAnnotations', with_bbox=True),
>>>     dict(
>>>         type='Expand',
>>>         mean=img_norm_cfg['mean'],
>>>         to_rgb=img_norm_cfg['to_rgb'],
>>>         ratio_range=(1, 2)),
>>>     dict(type='Resize', img_scale=[(320, 320), (416, 416)], keep_ratio=True),
>>>     dict(type='RandomFlip', flip_ratio=0.0),
>>>     dict(type='PhotoMetricDistortion'),
>>>     dict(type='Normalize', **img_norm_cfg),
>>>     dict(type='Pad', size_divisor=32),

Review comment (suggestion):
```suggestion
    gt_masks is optional parameter and lets say you want to train pure detecter this part is going to exclude. Other mappings are mandatory
```

Code after:
    - deeplake_dataloader: optional parameter. If specified represents the parameters of the deeplake dataloader. Deeplake dataloader parameters are: "shuffle", "batch_size", "num_workers". This parameter exists for train as well as for val.
        - "shuffle": if True shuffles the dataset.
        - "batch_size": size of batch. If not specified, dataloader will use samples_per_gpu.
        - "num_workers": number of workers to use. If not specified, dataloader will use workers_per_gpu.
- deeplake_dataloader_type: optional parameter. If specified represents the type of deeplake dataloader to use.
- deeplake_metrics_format: optional parameter. If specified represents the format of the deeplake metrics that will be used during evaluation. Default COCO. Avaliable values are: "COCO", "PascalVOC". 
  If COCO format is used, you can specify whether you want to evaluate on bbox only or also want to evaluate on masks. To do that you need to specify the format of the metric in metric. 
  
Ex:

>>>  deeplake_metrics_format = "COCO"
>>>  evaluation = dict(metric=["bbox"], interval=1)

- train_detector: Function to train the MMDetection model. Parameters are: model, cfg: mmcv.ConfigDict, ds_train=None, ds_train_tensors=None, ds_val: Optional[dp.Dataset] = None, ds_val_tensors=None, distributed: bool = False, timestamp=None, meta=None, validate: bool = True.
    - model: MMDetection model that is going to be used.
    - cfg: Configuration of the model as well as of the datasets and transforms that's going to be used.
    - ds_train: Optional parameter. If provided will overwrite deeplake_path in train, and will pass this tensor directly to the dataloader.
    - ds_val: Optional parameter. If provided will overwrite deeplake_path in val, and will pass this tensor directly to the dataloader.
    - ds_train_tensors: Optional parameter. If provided will overwrite deeplake_tensors in train, and will pass this tensor mapping directly to dataloader.
    - ds_val_tensors: Optional parameter. If provided will overwrite deeplake_tensors in val, and will pass this tensor mapping directly to dataloader.
    - distributed: Optional parameter. If provided will run the code on all available gpus. Meta data used to build runner
    - timestamp: variable used in runner to make .log and .log.json filenames the same.'
    - validate: bool, whether validation should be conducted, by default True

NOTE:
    gt_masks is optional parameter and lets say you want to train pure detecter this part is going to exclude. Other mappings are mandatory
    if you don't specify them explicitly they are going to be searched in the dataset according to tensor htype. Better to specify them explicitly

MMDetection Config Examples
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Below is the example of the deeplake mmdet configuration:


>>> _base_ = "../mmdetection/configs/yolo/yolov3_d53_mstrain-416_273e_coco.py"
>>> 
>>> # use caffe img_norm
>>> img_norm_cfg = dict(mean=[0, 0, 0], std=[255., 255., 255.], to_rgb=True)
>>> 
>>> train_pipeline = [
>>>     dict(type='LoadImageFromFile'),
>>>     dict(type='LoadAnnotations', with_bbox=True),
>>>     dict(
>>>         type='Expand',
>>>         mean=img_norm_cfg['mean'],
>>>         to_rgb=img_norm_cfg['to_rgb'],
>>>         ratio_range=(1, 2)),
>>>     dict(type='Resize', img_scale=[(320, 320), (416, 416)], keep_ratio=True),
>>>     dict(type='RandomFlip', flip_ratio=0.0),
>>>     dict(type='PhotoMetricDistortion'),
>>>     dict(type='Normalize', **img_norm_cfg),
>>>     dict(type='Pad', size_divisor=32),