Skip to content

DarkNet

The DarkNet model is based on the "You Only Look Once: Unified, Real-Time Object Detection" paper.

Architecture overview

This paper introduces a highway network with powerful feature representation abilities.

The key takeaways from the paper are the following:

  • improves the Inception architecture by using conv1x1
  • replaces ReLU by LeakyReLU

Model builders

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

DarknetV1

DarknetV1(layout: list[list[int]], num_classes: int = 10, in_channels: int = 3, stem_channels: int = 64, 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/darknet.py
def __init__(
    self,
    layout: list[list[int]],
    num_classes: int = 10,
    in_channels: int = 3,
    stem_channels: int = 64,
    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",
                DarknetBodyV1(layout, in_channels, stem_channels, act_layer, norm_layer, drop_layer, conv_layer),
            ),
            ("pool", GlobalAvgPool2d(flatten=True)),
            ("classifier", nn.Linear(layout[2][-1], num_classes)),
        ])
    )

    init_module(self, "leaky_relu")

darknet24

darknet24(pretrained: bool = False, progress: bool = True, **kwargs: Any) -> DarknetV1

Darknet-24 from "You Only Look Once: Unified, Real-Time Object Detection"

PARAMETER DESCRIPTION
pretrained

If True, returns a model pre-trained on ImageNet

TYPE: bool DEFAULT: False

progress

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

TYPE: bool DEFAULT: True

kwargs

keyword args of DarknetV1

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
DarknetV1

classification model

Source code in holocron/models/classification/darknet.py
def darknet24(pretrained: bool = False, progress: bool = True, **kwargs: Any) -> DarknetV1:
    """Darknet-24 from
    ["You Only Look Once: Unified, Real-Time Object Detection"](https://pjreddie.com/media/files/papers/yolo_1.pdf)

    Args:
        pretrained: If True, returns a model pre-trained on ImageNet
        progress: If True, displays a progress bar of the download to stderr
        kwargs: keyword args of [`DarknetV1`][holocron.models.classification.darknet.DarknetV1]

    Returns:
        classification model
    """
    return _darknet(
        "darknet24",
        pretrained,
        progress,
        [[192], [128, 256, 256, 512], [*([256, 512] * 4), 512, 1024], [512, 1024] * 2],
        **kwargs,
    )