From 663f1d64767c8c3e0f044277890c05f84c2471f3 Mon Sep 17 00:00:00 2001 From: lgvaz Date: Thu, 6 May 2021 09:43:33 -0300 Subject: [PATCH 1/3] bumps fastai and fastcore versions --- setup.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 014e907bd..c5cd8fa5c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,7 +27,7 @@ packages = find: install_requires = torch >=1.7.0,<1.9 torchvision >=0.8.0,<0.10 - fastcore >=1.3.0,<1.3.3 + fastcore >=1.3.0,<1.4 tqdm >=4.49.0,<5 opencv-python >=4.1.1,<5 albumentations >=0.4.6,<0.6 @@ -40,7 +40,7 @@ install_requires = [options.extras_require] all = - fastai >=2.1,<2.1.5 + fastai >=2.1,<2.4 ipykernel >=4.10.1,<6 pytorch-lightning >=1.2.10 effdet >=0.2.1,<0.3 From 7c5f4ddbe8e10475aa583a91792894ff384bceed Mon Sep 17 00:00:00 2001 From: lgvaz Date: Tue, 11 May 2021 10:57:28 -0300 Subject: [PATCH 2/3] updates changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82df49c8d..a3ea34654 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Supports pytorch 1.8 - rotate_limit changed from 45 to 15 - rgb_shift_limit changed from 20 to 10 - VOC parser uses image sizes from annotation file instead of image + - bumps fastai to latest version (<2.4) ### Deleted ## [0.7.0] From 5671cb7fdb022aded5b88d3c83d05466b3f6c687 Mon Sep 17 00:00:00 2001 From: lgvaz Date: Tue, 11 May 2021 14:45:41 -0300 Subject: [PATCH 3/3] sketches --- icevision/backbones/timm/mobilenet.py | 7 +++ .../models/mmdet/backbones/timm/mobilenet.py | 19 ++++++ icevision/models/mmdet/utils.py | 14 +++++ sketch.md | 63 +++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 icevision/backbones/timm/mobilenet.py create mode 100644 icevision/models/mmdet/backbones/timm/mobilenet.py create mode 100644 sketch.md diff --git a/icevision/backbones/timm/mobilenet.py b/icevision/backbones/timm/mobilenet.py new file mode 100644 index 000000000..7af73c752 --- /dev/null +++ b/icevision/backbones/timm/mobilenet.py @@ -0,0 +1,7 @@ +__all__ = ["mobilenet"] + +import timm + + +def our_mobilenet(*args, **kwargs): + return timm.models.mobilenetv3(*args, **kwargs) diff --git a/icevision/models/mmdet/backbones/timm/mobilenet.py b/icevision/models/mmdet/backbones/timm/mobilenet.py new file mode 100644 index 000000000..b95d0a14f --- /dev/null +++ b/icevision/models/mmdet/backbones/timm/mobilenet.py @@ -0,0 +1,19 @@ +from icevision.backbones.timm.mobilenet import * + + +@BACKBONES.register_module(force=True) +class MobileNetv3Large100(nn.Module): + def __init__(self, pretrained=True, out_indices=(0, 1, 2, 3, 4), **kwargs): + super().__init__() + self.model = our_mobilenet( + pretrained=True, + features_only=True, + out_indices=out_indices, + **kwargs, + ) + + def init_weights(self, pretrained=None): + pass + + def forward(self, x): # should return a tuple + return self.model(x) diff --git a/icevision/models/mmdet/utils.py b/icevision/models/mmdet/utils.py index 1f7d4e1ee..de86d7b86 100644 --- a/icevision/models/mmdet/utils.py +++ b/icevision/models/mmdet/utils.py @@ -17,6 +17,13 @@ mmdet_configs_path = download_mmdet_configs() +class MMDetTimmBackboneConfig(BackboneConfig): + def __init__(self, backbone): + self.backbone = backbone + self.feature_channels = [o["num_chs"] for o in list(backbone.feature_info)] + self.type = backbone.__class__.__name__ + + class MMDetBackboneConfig(BackboneConfig): def __init__(self, model_name, config_path, weights_url): self.model_name = model_name @@ -75,4 +82,11 @@ def create_model_config( cfg = Config.fromfile(config_path) + if isinstance(backbone, MMDetTimmBackboneConfig): + cfg.model.backbone = { + "type": backbone.type, + } + + cfg.model.neck.in_channels = backbone.feature_channels + return cfg, weights_path diff --git a/sketch.md b/sketch.md new file mode 100644 index 000000000..f82ad4252 --- /dev/null +++ b/sketch.md @@ -0,0 +1,63 @@ +### 0.8 + +- Yolov5 support +- fastai new version (multi-gpu and half-precision) +- mmdet new version +- support for negative samples +- pytorch 1.8 + +### namespace + +- old - +model_type = models.mmdet.retinanet +backbone = model_type.backbones.resnet50_fpn_1x + +models.torchvision.backbones + +model_type = models.torchvision.faster_rcnn +backbone = model_type.backbones.resnet50 + + + +- current - +import icevision as ice + +model_type = ice.detection.models.mmdet.retinanet +backbone = model_type.backbones.timm.resnet18 + +model_type = ice.classification.models.mmdet.? +backbone = model_type.backbones.timm.resnet18? (no backbone for classification?) + + +model_type = ice.multitask + + +### Mmdet backbone + +- two steps +1. register the backbones + - Files to register the backbones + +2. specify backbones per model + + +base_config_path = mmdet_configs_path / "retinanet" +config_path=base_config_path / "retinanet_r50_fpn_1x_coco.py" +config_path +cfg = Config.fromfile(config_path) +cfg.model.backbone = { + 'type': 'MobileNetv3Large100', +} + +cfg.model.neck.in_channels = neck_in_channels # [16, 24, 40 , 112, 960] + +cfg.model.bbox_head.num_classes = len(parser.class_map) - 1 + +model = build_detector(cfg.model, cfg.get("train_cfg"), cfg.get("test_cfg")) +model + +def get_in_channels(): + x = torch.randn(1,3,224,224) + features = backbone(x) + neck_in_channels = [f.shape[1] for f in features] + return neck_in_channels \ No newline at end of file