Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lib restructure #1120

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions docs/autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
"icevision.models.ross.efficientdet.dataloaders.build_infer_batch",
],
"efficientdet_fastai.md": [
"icevision.models.ross.efficientdet.fastai.learner.learner",
"icevision.models.ross.efficientdet.fastai.learner",
],
"efficientdet_lightning.md": [
"icevision.models.ross.efficientdet.lightning.model_adapter.ModelAdapter",
"icevision.models.ross.efficientdet.lightning.ModelAdapter",
],
}

Expand Down
Binary file added docs/templates/images/mmsegmentation-camvid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions icevision/models/fastai/unet/backbones/backbone_config.py

This file was deleted.

11 changes: 8 additions & 3 deletions icevision/models/fastai/unet/backbones/mobilenet_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
from icevision.utils.torch_utils import check_all_model_params_in_groups2
from torch import nn
import torchvision
from icevision.models.fastai.unet.backbones.backbone_config import (
TorchvisionUNetBackboneConfig,
)
from icevision.models.torchvision.backbone_config import TorchvisionBackboneConfig


# utils
class TorchvisionUNetBackboneConfig(TorchvisionBackboneConfig):
def __init__(self, **kwargs):
super().__init__(model_name="unet", **kwargs)


# backbones
def mobilenet_fn(pretrained: bool = True):
model = torchvision.models.mobilenet_v2(pretrained=pretrained)

Expand Down
10 changes: 6 additions & 4 deletions icevision/models/fastai/unet/backbones/resnet_configs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
__all__ = [
"resnet_param_groups",
"resnet18",
"resnet34",
"resnet50",
Expand All @@ -16,9 +15,12 @@
from torch import nn
import torchvision
from icevision.utils.torch_utils import check_all_model_params_in_groups2
from icevision.models.fastai.unet.backbones.backbone_config import (
TorchvisionUNetBackboneConfig,
)
from icevision.models.torchvision.backbone_config import TorchvisionBackboneConfig


class TorchvisionUNetBackboneConfig(TorchvisionBackboneConfig):
def __init__(self, **kwargs):
super().__init__(model_name="unet", **kwargs)


def _resnet_features(model: nn.Module, out_channels: int):
Expand Down
1 change: 1 addition & 0 deletions icevision/models/ross/efficientdet/backbones/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from icevision.models.ross.efficientdet.backbones.backbones import *
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
__all__ = ["learner"]
__all__ = ["learner", "EfficientDetCallback"]

from icevision.imports import *
from icevision.engines.fastai import *
from icevision.models.ross import efficientdet
from icevision.models.ross.efficientdet.loss_fn import loss_fn
from icevision.models.ross.efficientdet.fastai.callbacks import EfficientDetCallback


class EfficientDetCallback(fastai.Callback):
def before_batch(self):
assert len(self.xb) == len(self.yb) == 1, "Only works for single input-output"
self.learn.xb = self.xb[0]
self.learn.records = self.yb[0]
self.learn.yb = ()

def after_pred(self):
self.learn.yb = [self.learn.xb[1]]
self.learn.xb = [self.learn.xb[0]]

if not self.training:
preds = efficientdet.convert_raw_predictions(
batch=(*self.xb, *self.yb),
raw_preds=self.pred["detections"],
records=self.learn.records,
detection_threshold=0.0,
)
self.learn.converted_preds = preds


def learner(
Expand Down
2 changes: 0 additions & 2 deletions icevision/models/ross/efficientdet/fastai/__init__.py

This file was deleted.

25 changes: 0 additions & 25 deletions icevision/models/ross/efficientdet/fastai/callbacks.py

This file was deleted.

1 change: 0 additions & 1 deletion icevision/models/ross/efficientdet/lightning/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions icevision/models/ross/efficientdet/show_batch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__all__ = ["show_batch"]

import torch
from icevision.utils import *
from icevision.visualize import *

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,37 @@
"wide_resnet101_2_fpn",
]

from icevision.models.torchvision.faster_rcnn.backbones.resnet_fpn_utils import (
patch_param_groups,
)
from icevision.imports import *
from icevision.utils import *
from torchvision.models.detection.backbone_utils import resnet_fpn_backbone
from icevision.models.torchvision.faster_rcnn.backbones.backbone_config import (
TorchvisionFasterRCNNBackboneConfig,
)
from icevision.models.torchvision.backbone_config import TorchvisionBackboneConfig


# utils
class TorchvisionFasterRCNNBackboneConfig(TorchvisionBackboneConfig):
def __init__(self, **kwargs):
super().__init__(model_name="faster_rcnn", **kwargs)


def param_groups(model: nn.Module) -> List[nn.Parameter]:
body = model.body

layers = []
layers += [nn.Sequential(body.conv1, body.bn1)]
layers += [getattr(body, l) for l in list(body) if l.startswith("layer")]
layers += [model.fpn]

_param_groups = [list(layer.parameters()) for layer in layers]
check_all_model_params_in_groups2(model, _param_groups)

return _param_groups


def patch_param_groups(model: nn.Module) -> None:
model.param_groups = MethodType(param_groups, model)


# backbones
def _resnet_fpn(name: str, pretrained: bool = True, **kwargs):
model = resnet_fpn_backbone(backbone_name=name, pretrained=pretrained, **kwargs)
patch_param_groups(model)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,38 @@
"wide_resnet101_2_fpn",
]

from icevision.models.torchvision.keypoint_rcnn.backbones.resnet_fpn_utils import (
patch_param_groups,
)

from icevision.imports import *
from icevision.utils import *
from torchvision.models.detection.backbone_utils import resnet_fpn_backbone
from icevision.models.torchvision.keypoint_rcnn.backbones.backbone_config import (
TorchvisionKeypointRCNNBackboneConfig,
)
from icevision.models.torchvision.backbone_config import TorchvisionBackboneConfig


# utils
class TorchvisionKeypointRCNNBackboneConfig(TorchvisionBackboneConfig):
def __init__(self, **kwargs):
super().__init__(model_name="keypoint_rcnn", **kwargs)


def param_groups(model: nn.Module) -> List[nn.Parameter]:
body = model.body

layers = []
layers += [nn.Sequential(body.conv1, body.bn1)]
layers += [getattr(body, l) for l in list(body) if l.startswith("layer")]
layers += [model.fpn]

_param_groups = [list(layer.parameters()) for layer in layers]
check_all_model_params_in_groups2(model, _param_groups)

return _param_groups


def patch_param_groups(model: nn.Module) -> None:
model.param_groups = MethodType(param_groups, model)


# backbones
def _resnet_fpn(name: str, pretrained: bool = True, **kwargs):
model = resnet_fpn_backbone(backbone_name=name, pretrained=pretrained, **kwargs)
patch_param_groups(model)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,37 @@
"wide_resnet101_2_fpn",
]

from icevision.models.torchvision.mask_rcnn.backbones.resnet_fpn_utils import (
patch_param_groups,
)
from icevision.imports import *
from icevision.utils import *
from torchvision.models.detection.backbone_utils import resnet_fpn_backbone
from icevision.models.torchvision.mask_rcnn.backbones.backbone_config import (
TorchvisionMaskRCNNBackboneConfig,
)
from icevision.models.torchvision.backbone_config import TorchvisionBackboneConfig


# utils
class TorchvisionMaskRCNNBackboneConfig(TorchvisionBackboneConfig):
def __init__(self, **kwargs):
super().__init__(model_name="mask_rcnn", **kwargs)


def param_groups(model: nn.Module) -> List[nn.Parameter]:
body = model.body

layers = []
layers += [nn.Sequential(body.conv1, body.bn1)]
layers += [getattr(body, l) for l in list(body) if l.startswith("layer")]
layers += [model.fpn]

_param_groups = [list(layer.parameters()) for layer in layers]
check_all_model_params_in_groups2(model, _param_groups)

return _param_groups


def patch_param_groups(model: nn.Module) -> None:
model.param_groups = MethodType(param_groups, model)


# backbones
def _resnet_fpn(name: str, pretrained: bool = True, **kwargs):
model = resnet_fpn_backbone(backbone_name=name, pretrained=pretrained, **kwargs)
patch_param_groups(model)
Expand Down

This file was deleted.

This file was deleted.

Loading