Skip to content

DarkNetV3

The DarkNetV3 model is based on the "YOLOv3: An Incremental Improvement" paper.

Architecture overview

This paper makes a more powerful version than its predecedors by increasing depth and using ResNet tricks.

The key takeaways from the paper are the following:

  • adds residual connection compared to DarkNetV2

Model builders

The following model builders can be used to instantiate a DarknetV3 model, with or without pre-trained weights. All the model builders internally rely on the DarknetV3 base class.

DarknetV3

DarknetV3(layout: list[tuple[int, int]], num_classes: int = 10, in_channels: int = 3, stem_channels: int = 32, act_layer: Module | None = None, norm_layer: Callable[[int], Module] | None = None, drop_layer: Callable[..., Module] | None = None, conv_layer: Callable[..., Module] | None = None)

Bases: Sequential

Source code in holocron/models/classification/darknetv3.py
def __init__(
    self,
    layout: list[tuple[int, int]],
    num_classes: int = 10,
    in_channels: int = 3,
    stem_channels: int = 32,
    act_layer: nn.Module | None = None,
    norm_layer: Callable[[int], nn.Module] | None = None,
    drop_layer: Callable[..., nn.Module] | None = None,
    conv_layer: Callable[..., nn.Module] | None = None,
) -> None:
    super().__init__(
        OrderedDict([
            (
                "features",
                DarknetBodyV3(layout, in_channels, stem_channels, 1, act_layer, norm_layer, drop_layer, conv_layer),
            ),
            ("pool", GlobalAvgPool2d(flatten=True)),
            ("classifier", nn.Linear(layout[-1][0], num_classes)),
        ])
    )

    init_module(self, "leaky_relu")

darknet53

darknet53(pretrained: bool = False, checkpoint: Checkpoint | None = None, progress: bool = True, **kwargs: Any) -> DarknetV3

Darknet-53 from "YOLOv3: An Incremental Improvement"

PARAMETER DESCRIPTION
pretrained

If True, returns a model pre-trained on ImageNet

TYPE: bool DEFAULT: False

checkpoint

If specified, the model's parameters will be set to the checkpoint's values

TYPE: Checkpoint | None DEFAULT: None

progress

If True, displays a progress bar of the download to stderr

TYPE: bool DEFAULT: True

kwargs

keyword args of DarknetV3

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
DarknetV3

classification model

Darknet53_Checkpoint

Bases: Enum

IMAGENETTE class-attribute instance-attribute
IMAGENETTE = _checkpoint(arch='darknet53', url='https://github.com/frgfm/Holocron/releases/download/v0.2.1/darknet53_224-5015f3fd.pth', acc1=0.9417, acc5=0.9957, sha256='5015f3fdf0963342e0c54790127350375ba269d871feed48f8328b2e43cf7819', size=162584273, num_params=40595178, commit='6e32c5b578711a2ef3731a8f8c61760ed9f03e58', train_args='./imagenette2-320/ --arch darknet53 --batch-size 64 --mixup-alpha 0.2 --amp --device 0 --epochs 100 --lr 1e-3 --label-smoothing 0.1 --random-erase 0.1 --train-crop-size 176 --val-resize-size 232 --opt adamw --weight-decay 5e-2')
DEFAULT class-attribute instance-attribute
DEFAULT = IMAGENETTE
Source code in holocron/models/classification/darknetv3.py
def darknet53(
    pretrained: bool = False,
    checkpoint: Checkpoint | None = None,
    progress: bool = True,
    **kwargs: Any,
) -> DarknetV3:
    """Darknet-53 from
    ["YOLOv3: An Incremental Improvement"](https://pjreddie.com/media/files/papers/YOLOv3.pdf)

    Args:
        pretrained: If True, returns a model pre-trained on ImageNet
        checkpoint: If specified, the model's parameters will be set to the checkpoint's values
        progress: If True, displays a progress bar of the download to stderr
        kwargs: keyword args of [`DarknetV3`][holocron.models.classification.darknetv3.DarknetV3]

    Returns:
        classification model

    ::: holocron.models.Darknet53_Checkpoint
        options:
            heading_level: 4
            show_if_no_docstring: true
    """
    checkpoint = _handle_legacy_pretrained(
        pretrained,
        checkpoint,
        Darknet53_Checkpoint.DEFAULT.value,
    )
    return _darknet(checkpoint, progress, [(64, 1), (128, 2), (256, 8), (512, 8), (1024, 4)], **kwargs)