Beispiel #1
0
def DoReFaNet(
    include_top=True,
    weights="imagenet",
    input_tensor=None,
    input_shape=None,
    classes=1000,
):
    """Instantiates the DoReFa-net architecture.
    Optionally loads weights pre-trained on ImageNet.
    ```netron
    dorefanet-v0.1.0/dorefanet.json
    ```
    ```plot-altair
    /plots/dorefanet.vg.json
    ```
    # Arguments
    include_top: whether to include the fully-connected layer at the top of the network.
    weights: one of `None` (random initialization), "imagenet" (pre-training on
        ImageNet), or the path to the weights file to be loaded.
    input_tensor: optional Keras tensor (i.e. output of `layers.Input()`) to use as
        image input for the model.
    input_shape: optional shape tuple, only to be specified if `include_top` is False,
        otherwise the input shape has to be `(224, 224, 3)`.
        It should have exactly 3 inputs channels.
    classes: optional number of classes to classify images into, only to be specified
        if `include_top` is True, and if no `weights` argument is specified.

    # Returns
    A Keras model instance.

    # Raises
    ValueError: in case of invalid argument for `weights`, or invalid input shape.

    # References
    - [DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low
    Bitwidth Gradients](https://arxiv.org/abs/1606.06160)
    """
    input_shape = utils.validate_input(input_shape, weights, include_top,
                                       classes)

    model = dorefa_net(
        default(),
        input_shape,
        classes,
        input_tensor=input_tensor,
        include_top=include_top,
    )

    # Load weights.
    if weights == "imagenet":
        # download appropriate file
        if include_top:
            weights_path = utils.download_pretrained_model(
                model="dorefanet",
                version="v0.1.0",
                file="dorefanet_weights.h5",
                file_hash=
                "645d7839d574faa3eeeca28f3115773d75da3ab67ff6876b4de12d10245ecf6a",
            )
        else:
            weights_path = utils.download_pretrained_model(
                model="dorefanet",
                version="v0.1.0",
                file="dorefanet_weights_notop.h5",
                file_hash=
                "679368128e19a2a181bfe06ca3a3dec368b1fd8011d5f42647fbbf5a7f36d45f",
            )
        model.load_weights(weights_path)
    elif weights is not None:
        model.load_weights(weights)
    return model
Beispiel #2
0
def BinaryAlexNet(
    include_top=True,
    weights="imagenet",
    input_tensor=None,
    input_shape=None,
    classes=1000,
):
    """Instantiates the BinaryAlexNet architecture.

    Optionally loads weights pre-trained on ImageNet.

    ```netron
    binary_alexnet-v0.2.0/binary_alexnet.json
    ```
    ```plot-altair
    /plots/binary_alexnet.vg.json
    ```

    # Arguments
    include_top: whether to include the fully-connected layer at the top of the network.
    weights: one of `None` (random initialization), "imagenet" (pre-training on
        ImageNet), or the path to the weights file to be loaded.
    input_tensor: optional Keras tensor (i.e. output of `layers.Input()`) to use as
        image input for the model.
    input_shape: optional shape tuple, only to be specified if `include_top` is False,
        otherwise the input shape has to be `(224, 224, 3)`.
        It should have exactly 3 inputs channels.
    classes: optional number of classes to classify images into, only to be specified
        if `include_top` is True, and if no `weights` argument is specified.

    # Returns
    A Keras model instance.

    # Raises
    ValueError: in case of invalid argument for `weights`, or invalid input shape.
    """
    input_shape = utils.validate_input(input_shape, weights, include_top,
                                       classes)

    model = binary_alexnet(
        default(),
        input_shape,
        classes,
        input_tensor=input_tensor,
        include_top=include_top,
    )

    # Load weights.
    if weights == "imagenet":
        # download appropriate file
        if include_top:
            weights_path = utils.download_pretrained_model(
                model="binary_alexnet",
                version="v0.2.0",
                file="binary_alexnet_weights.h5",
                file_hash=
                "0f8d3f6c1073ef993e2e99a38f8e661e5efe385085b2a84b43a7f2af8500a3d3",
            )
        else:
            weights_path = utils.download_pretrained_model(
                model="binary_alexnet",
                version="v0.2.0",
                file="binary_alexnet_weights_notop.h5",
                file_hash=
                "1c7e2ef156edd8e7615e75a3b8929f9025279a948d1911824c2f5a798042475e",
            )
        model.load_weights(weights_path)
    elif weights is not None:
        model.load_weights(weights)

    return model
Beispiel #3
0
def BinaryDenseNet45(
    include_top=True,
    weights="imagenet",
    input_tensor=None,
    input_shape=None,
    classes=1000,
):
    """Instantiates the Binary BinaryDenseNet 45 architecture.

    Optionally loads weights pre-trained on ImageNet.

    ```netron
    binary_densenet-v0.1.0/binary_densenet_45.json
    ```
    ```plot-altair
    /plots/densenet_45.vg.json
    ```

    # Arguments
    include_top: whether to include the fully-connected layer at the top of the network.
    weights: one of `None` (random initialization), "imagenet" (pre-training on
        ImageNet), or the path to the weights file to be loaded.
    input_tensor: optional Keras tensor (i.e. output of `layers.Input()`) to use as
        image input for the model.
    input_shape: optional shape tuple, only to be specified if `include_top` is False,
        otherwise the input shape has to be `(224, 224, 3)`.
        It should have exactly 3 inputs channels.
    classes: optional number of classes to classify images into, only to be specified
        if `include_top` is True, and if no `weights` argument is specified.

    # Returns
    A Keras model instance.

    # Raises
    ValueError: in case of invalid argument for `weights`, or invalid input shape.

    # References
    - [Back to Simplicity:
      How to Train Accurate BNNs from Scratch?](https://arxiv.org/abs/1906.08637)
    """
    input_shape = utils.validate_input(input_shape, weights, include_top,
                                       classes)

    model = binary_densenet(
        binary_densenet45(),
        input_shape=input_shape,
        num_classes=classes,
        input_tensor=input_tensor,
        include_top=include_top,
    )

    # Load weights.
    if weights == "imagenet":
        # download appropriate file
        if include_top:
            weights_path = utils.download_pretrained_model(
                model="binary_densenet",
                version="v0.1.0",
                file="binary_densenet_45_weights.h5",
                file_hash=
                "d00a0d26fbd2dba1bfba8c0306c770f3aeea5c370e99f963bb239bd916f72c37",
            )
        else:
            weights_path = utils.download_pretrained_model(
                model="binary_densenet",
                version="v0.1.0",
                file="binary_densenet_45_weights_notop.h5",
                file_hash=
                "e72d5cc6b0afe4612f8be7b1f9bb48a53ba2c8468b57bf1266d2900c99fd2adf",
            )
        model.load_weights(weights_path)
    elif weights is not None:
        model.load_weights(weights)
    return model
Beispiel #4
0
def BiRealNet(
    include_top=True,
    weights="imagenet",
    input_tensor=None,
    input_shape=None,
    classes=1000,
):
    """Instantiates the Bi-Real Net architecture.

    Optionally loads weights pre-trained on ImageNet.

    ```netron
    birealnet-v0.3.0/birealnet.json
    ```
    ```plot-altair
    /plots/birealnet.vg.json
    ```

    # Arguments
    include_top: whether to include the fully-connected layer at the top of the network.
    weights: one of `None` (random initialization), "imagenet" (pre-training on
        ImageNet), or the path to the weights file to be loaded.
    input_tensor: optional Keras tensor (i.e. output of `layers.Input()`) to use as
        image input for the model.
    input_shape: optional shape tuple, only to be specified if `include_top` is False,
        otherwise the input shape has to be `(224, 224, 3)`.
        It should have exactly 3 inputs channels.
    classes: optional number of classes to classify images into, only to be specified
        if `include_top` is True, and if no `weights` argument is specified.

    # Returns
    A Keras model instance.

    # Raises
    ValueError: in case of invalid argument for `weights`, or invalid input shape.

    # References
    - [Bi-Real Net: Enhancing the Performance of 1-bit CNNs With Improved
      Representational Capability and Advanced Training
      Algorithm](https://arxiv.org/abs/1808.00278)
    """
    input_shape = utils.validate_input(input_shape, weights, include_top, classes)

    model = birealnet(
        default(),
        input_shape,
        classes,
        input_tensor=input_tensor,
        include_top=include_top,
    )

    # Load weights.
    if weights == "imagenet":
        # download appropriate file
        if include_top:
            weights_path = utils.download_pretrained_model(
                model="birealnet",
                version="v0.3.0",
                file="birealnet_weights.h5",
                file_hash="6e6efac1584fcd60dd024198c87f42eb53b5ec719a5ca1f527e1fe7e8b997117",
            )
        else:
            weights_path = utils.download_pretrained_model(
                model="birealnet",
                version="v0.3.0",
                file="birealnet_weights_notop.h5",
                file_hash="5148b61c0c2a1094bdef811f68bf4957d5ba5f83ad26437b7a4a6855441ab46b",
            )
        model.load_weights(weights_path)
    elif weights is not None:
        model.load_weights(weights)
    return model
Beispiel #5
0
def BinaryDenseNet37Dilated(
    include_top=True,
    weights="imagenet",
    input_tensor=None,
    input_shape=None,
    classes=1000,
):
    """Instantiates the Dilated BinaryDenseNet 37 architecture.

    Optionally loads weights pre-trained on ImageNet.

    ```netron
    binary_densenet-v0.1.0/binary_densenet_37_dilated.json
    ```
    ```plot-altair
    /plots/densenet_37_dilated.vg.json
    ```

    # Arguments
    include_top: whether to include the fully-connected layer at the top of the network.
    weights: one of `None` (random initialization), "imagenet" (pre-training on
        ImageNet), or the path to the weights file to be loaded.
    input_tensor: optional Keras tensor (i.e. output of `layers.Input()`) to use as
        image input for the model.
    input_shape: optional shape tuple, only to be specified if `include_top` is False,
        otherwise the input shape has to be `(224, 224, 3)`.
        It should have exactly 3 inputs channels.
    classes: optional number of classes to classify images into, only to be specified
        if `include_top` is True, and if no `weights` argument is specified.

    # Returns
    A Keras model instance.

    # Raises
    ValueError: in case of invalid argument for `weights`, or invalid input shape.

    # References
    - [Back to Simplicity:
      How to Train Accurate BNNs from Scratch?](https://arxiv.org/abs/1906.08637)
    """
    input_shape = utils.validate_input(input_shape, weights, include_top,
                                       classes)

    model = binary_densenet(
        binary_densenet37_dilated(),
        input_shape=input_shape,
        num_classes=classes,
        input_tensor=input_tensor,
        include_top=include_top,
    )

    # Load weights.
    if weights == "imagenet":
        # download appropriate file
        if include_top:
            weights_path = utils.download_pretrained_model(
                model="binary_densenet",
                version="v0.1.0",
                file="binary_densenet_37_dilated_weights.h5",
                file_hash=
                "15c1bcd79b8dc22971382fbf79acf364a3f51049d0e584a11533e6fdbb7363d3",
            )
        else:
            weights_path = utils.download_pretrained_model(
                model="binary_densenet",
                version="v0.1.0",
                file="binary_densenet_37_dilated_weights_notop.h5",
                file_hash=
                "eaf3eac19fc90708f56a27435fb06d0e8aef40e6e0411ff7a8eefbe479226e4f",
            )
        model.load_weights(weights_path)
    elif weights is not None:
        model.load_weights(weights)
    return model
Beispiel #6
0
def BinaryDenseNet37(
    include_top=True,
    weights="imagenet",
    input_tensor=None,
    input_shape=None,
    classes=1000,
):
    """Instantiates the BinaryDenseNet 37 architecture.

    Optionally loads weights pre-trained on ImageNet.

    ```netron
    binary_densenet-v0.1.0/binary_densenet_37.json
    ```
    ```plot-altair
    /plots/densenet_37.vg.json
    ```

    # Arguments
    include_top: whether to include the fully-connected layer at the top of the network.
    weights: one of `None` (random initialization), "imagenet" (pre-training on
        ImageNet), or the path to the weights file to be loaded.
    input_tensor: optional Keras tensor (i.e. output of `layers.Input()`) to use as
        image input for the model.
    input_shape: optional shape tuple, only to be specified if `include_top` is False,
        otherwise the input shape has to be `(224, 224, 3)`.
        It should have exactly 3 inputs channels.
    classes: optional number of classes to classify images into, only to be specified
        if `include_top` is True, and if no `weights` argument is specified.

    # Returns
    A Keras model instance.

    # Raises
    ValueError: in case of invalid argument for `weights`, or invalid input shape.

    # References
    - [Back to Simplicity:
      How to Train Accurate BNNs from Scratch?](https://arxiv.org/abs/1906.08637)
    """
    input_shape = utils.validate_input(input_shape, weights, include_top,
                                       classes)

    model = binary_densenet(
        binary_densenet37(),
        input_shape=input_shape,
        num_classes=classes,
        input_tensor=input_tensor,
        include_top=include_top,
    )

    # Load weights.
    if weights == "imagenet":
        # download appropriate file
        if include_top:
            weights_path = utils.download_pretrained_model(
                model="binary_densenet",
                version="v0.1.0",
                file="binary_densenet_37_weights.h5",
                file_hash=
                "8056a5d52c3ed86a934893987d09a06f59a5166aa9bddcaedb050f111d0a7d76",
            )
        else:
            weights_path = utils.download_pretrained_model(
                model="binary_densenet",
                version="v0.1.0",
                file="binary_densenet_37_weights_notop.h5",
                file_hash=
                "4e12bca9fd27580a5b833241c4eb35d6cc332878c406048e6ca8dbbc78d59175",
            )
        model.load_weights(weights_path)
    elif weights is not None:
        model.load_weights(weights)
    return model
Beispiel #7
0
def BinaryDenseNet28(
    include_top=True,
    weights="imagenet",
    input_tensor=None,
    input_shape=None,
    classes=1000,
):
    """Instantiates the BinaryDenseNet 28 architecture.

    Optionally loads weights pre-trained on ImageNet.

    ```netron
    binary_densenet-v0.1.0/binary_densenet_28.json
    ```
    ```plot-altair
    /plots/densenet_28.vg.json
    ```

    # Arguments
    include_top: whether to include the fully-connected layer at the top of the network.
    weights: one of `None` (random initialization), "imagenet" (pre-training on
        ImageNet), or the path to the weights file to be loaded.
    input_tensor: optional Keras tensor (i.e. output of `layers.Input()`) to use as
        image input for the model.
    input_shape: optional shape tuple, only to be specified if `include_top` is False,
        otherwise the input shape has to be `(224, 224, 3)`.
        It should have exactly 3 inputs channels.
    classes: optional number of classes to classify images into, only to be specified
        if `include_top` is True, and if no `weights` argument is specified.

    # Returns
    A Keras model instance.

    # Raises
    ValueError: in case of invalid argument for `weights`, or invalid input shape.

    # References
    - [Back to Simplicity:
      How to Train Accurate BNNs from Scratch?](https://arxiv.org/abs/1906.08637)
    """
    input_shape = utils.validate_input(input_shape, weights, include_top,
                                       classes)

    model = binary_densenet(
        binary_densenet28(),
        input_shape=input_shape,
        num_classes=classes,
        input_tensor=input_tensor,
        include_top=include_top,
    )

    # Load weights.
    if weights == "imagenet":
        # download appropriate file
        if include_top:
            weights_path = utils.download_pretrained_model(
                model="binary_densenet",
                version="v0.1.0",
                file="binary_densenet_28_weights.h5",
                file_hash=
                "21fe3ca03eed244df9c41a2219876fcf03e73800932ec96a3e2a76af4747ac53",
            )
        else:
            weights_path = utils.download_pretrained_model(
                model="binary_densenet",
                version="v0.1.0",
                file="binary_densenet_28_weights_notop.h5",
                file_hash=
                "a376df1e41772c4427edd1856072b934a89bf293bf911438bf6f751a9b2a28f5",
            )
        model.load_weights(weights_path)
    elif weights is not None:
        model.load_weights(weights)
    return model
Beispiel #8
0
def XNORNet(
    include_top=True,
    weights="imagenet",
    input_tensor=None,
    input_shape=None,
    classes=1000,
):
    """Instantiates the XNOR-Net architecture.

    Optionally loads weights pre-trained on ImageNet.

    ```netron
    xnornet-v0.2.0/xnornet.json
    ```
    ```plot-altair
    /plots/xnornet.vg.json
    ```

    # Arguments
    include_top: whether to include the fully-connected layer at the top of the network.
    weights: one of `None` (random initialization), "imagenet" (pre-training on
        ImageNet), or the path to the weights file to be loaded.
    input_tensor: optional Keras tensor (i.e. output of `layers.Input()`) to use as
        image input for the model.
    input_shape: optional shape tuple, only to be specified if `include_top` is False
        (otherwise the input shape has to be `(224, 224, 3)` (with `channels_last` data
        format) or `(3, 224, 224)` (with `channels_first` data format).
        It should have exactly 3 inputs channels.
    classes: optional number of classes to classify images into, only to be specified
        if `include_top` is True, and if no `weights` argument is specified.

    # Returns
    A Keras model instance.

    # Raises
    ValueError: in case of invalid argument for `weights`, or invalid input shape.

    # References
    - [XNOR-Net: ImageNet Classification Using Binary Convolutional Neural
      Networks](https://arxiv.org/abs/1603.05279)
    """
    input_shape = utils.validate_input(input_shape, weights, include_top,
                                       classes)

    model = xnornet(
        default(),
        input_shape,
        classes,
        input_tensor=input_tensor,
        include_top=include_top,
    )

    # Load weights.
    if weights == "imagenet":
        # download appropriate file
        if include_top:
            weights_path = utils.download_pretrained_model(
                model="xnornet",
                version="v0.2.0",
                file="xnornet_weights.h5",
                file_hash=
                "e6ba24f785655260ae76a2ef1fab520e3528243d9c8fac430299cd81dbeabe10",
            )
        else:
            weights_path = utils.download_pretrained_model(
                model="xnornet",
                version="v0.2.0",
                file="xnornet_weights_notop.h5",
                file_hash=
                "0b8e3d0d60a7a728b5e387b8cd9f0fedc1dd72bcf9f4c693a2245d3a3c596b91",
            )
        model.load_weights(weights_path)
    elif weights is not None:
        model.load_weights(weights)
    return model
Beispiel #9
0
def BinaryResNetE18(
    include_top=True,
    weights="imagenet",
    input_tensor=None,
    input_shape=None,
    classes=1000,
):
    """Instantiates the BinaryResNetE 18 architecture.

    Optionally loads weights pre-trained on ImageNet.

    ```netron
    resnet_e-v0.1.0/resnet_e_18.json
    ```
    ```plot-altair
    /plots/resnet_e_18.vg.json
    ```

    # Arguments
    include_top: whether to include the fully-connected layer at the top of the network.
    weights: one of `None` (random initialization), "imagenet" (pre-training on
        ImageNet), or the path to the weights file to be loaded.
    input_tensor: optional Keras tensor (i.e. output of `layers.Input()`) to use as
        image input for the model.
    input_shape: optional shape tuple, only to be specified if `include_top` is False,
        otherwise the input shape has to be `(224, 224, 3)`.
        It should have exactly 3 inputs channels.
    classes: optional number of classes to classify images into, only to be specified
        if `include_top` is True, and if no `weights` argument is specified.

    # Returns
    A Keras model instance.

    # Raises
    ValueError: in case of invalid argument for `weights`, or invalid input shape.

    # References
    - [Back to Simplicity:
      How to Train Accurate BNNs from Scratch?](https://arxiv.org/abs/1906.08637)
    """
    input_shape = utils.validate_input(input_shape, weights, include_top, classes)

    model = resnet_e(
        default(),
        input_shape=input_shape,
        num_classes=classes,
        input_tensor=input_tensor,
        include_top=include_top,
    )

    # Load weights.
    if weights == "imagenet":
        # download appropriate file
        if include_top:
            weights_path = utils.download_pretrained_model(
                model="resnet_e",
                version="v0.1.0",
                file="resnet_e_18_weights.h5",
                file_hash="bde4a64d42c164a7b10a28debbe1ad5b287c499bc0247ecb00449e6e89f3bf5b",
            )
        else:
            weights_path = utils.download_pretrained_model(
                model="resnet_e",
                version="v0.1.0",
                file="resnet_e_18_weights_notop.h5",
                file_hash="14cb037e47d223827a8d09db88ec73d60e4153a4464dca847e5ae1a155e7f525",
            )
        model.load_weights(weights_path)
    elif weights is not None:
        model.load_weights(weights)
    return model