Skip to content

DarkNetV2

The DarkNetV2 model is based on the "YOLO9000: Better, Faster, Stronger" paper.

Architecture overview

This paper improves its version version by adding more recent gradient flow facilitators.

The key takeaways from the paper are the following:

  • adds batch normalization layers compared to DarkNetV1

Model builders

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

DarknetV2

DarknetV2(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/darknetv2.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",
                DarknetBodyV2(
                    layout, in_channels, stem_channels, False, act_layer, norm_layer, drop_layer, conv_layer
                ),
            ),
            ("classifier", nn.Conv2d(layout[-1][0], num_classes, 1)),
            ("pool", GlobalAvgPool2d(flatten=True)),
        ])
    )

    init_module(self, "leaky_relu")

darknet19

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

Darknet-19 from "YOLO9000: Better, Faster, Stronger"

PARAMETER DESCRIPTION
pretrained

If True, returns a model pre-trained on ImageNette

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 DarknetV2

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
DarknetV2

classification model

Darknet19_Checkpoint

Bases: Enum

IMAGENETTE class-attribute instance-attribute
IMAGENETTE = _checkpoint(arch='darknet19', url='https://github.com/frgfm/Holocron/releases/download/v0.2.1/darknet19_224-32fd3f97.pth', acc1=0.9386, acc5=0.9936, sha256='32fd3f979586556554652d650c44a59747c7762d81140cadbcd795179a3877ec', size=79387724, num_params=19827626, commit='6e32c5b578711a2ef3731a8f8c61760ed9f03e58', train_args='./imagenette2-320/ --arch darknet19 --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/darknetv2.py
def darknet19(
    pretrained: bool = False,
    checkpoint: Checkpoint | None = None,
    progress: bool = True,
    **kwargs: Any,
) -> DarknetV2:
    """Darknet-19 from
    ["YOLO9000: Better, Faster, Stronger"](https://pjreddie.com/media/files/papers/YOLO9000.pdf)

    Args:
        pretrained: If True, returns a model pre-trained on ImageNette
        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 [`DarknetV2`][holocron.models.classification.darknetv2.DarknetV2]

    Returns:
        classification model

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