AI-MXNet-Gluon-ModelZoo

 view release on metacpan or  search on metacpan

lib/AI/MXNet/Gluon/ModelZoo.pm  view on Meta::CPAN

    Returns a pre-defined model by name

    Parameters
    ----------
    $name : Str
        Name of the model.
    :$pretrained : Bool
        Whether to load the pretrained weights for model.
    :$classes : Int
        Number of classes for the output layer.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.

    Returns
    -------
    HybridBlock
        The model.
=cut

sub get_model
{

lib/AI/MXNet/Gluon/ModelZoo/ModelStore.pm  view on Meta::CPAN


    Return location for the pretrained on local file system.

    This function will download from online model zoo when model cannot be found or has mismatch.
    The root directory will be created if it doesn't exist.

    Parameters
    ----------
    $name : Str
        Name of the model.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.

    Returns
    -------
    $file_path
        Path to the requested pretrained model file.
=cut

method get_model_file(Str $name, Str :$root='~/.mxnet/models')
{

lib/AI/MXNet/Gluon/ModelZoo/ModelStore.pm  view on Meta::CPAN

        Carp::confess("Downloaded file $file_path has different hash. Please try again.");
    }
}

=head2 purge

    Purge all pretrained model files in local file store.

    Parameters
    ----------
    root : str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method purge(Str $root='~/.mxnet/models')
{
    $root =~ s/~/$ENV{HOME}/;
    map { unlink } glob("$root/*.params");
}

1;

lib/AI/MXNet/Gluon/ModelZoo/Vision/AlexNet.pm  view on Meta::CPAN


    AI::MXNet::Gluon::ModelZoo::Vision::AlexNet - AlexNet model from the `"One weird trick..."
=cut

=head1 DESCRIPTION

    AlexNet model from the "One weird trick..." <https://arxiv.org/abs/1404.5997> paper.

    Parameters
    ----------
    classes : Int, default 1000
        Number of classes for the output layer.
=cut
has 'classes' => (is => 'ro', isa => 'Int', default => 1000);
method python_constructor_arguments() { ['classes'] }

sub BUILD
{
    my $self = shift;
    $self->name_scope(sub {
        $self->features(nn->HybridSequential(prefix=>''));
        $self->features->name_scope(sub {
            $self->features->add(nn->Conv2D(64, kernel_size=>11, strides=>4,
                                            padding=>2, activation=>'relu'));

lib/AI/MXNet/Gluon/ModelZoo/Vision/AlexNet.pm  view on Meta::CPAN

}

package AI::MXNet::Gluon::ModelZoo::Vision;

=head2 alexnet

    AlexNet model from the `"One weird trick..." <https://arxiv.org/abs/1404.5997> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default AI::MXNet::Context->cpu
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method alexnet(
    Bool :$pretrained=0,
    AI::MXNet::Context :$ctx=AI::MXNet::Context->cpu(),
    Str :$root='~/.mxnet/models',
    Int :$classes=1000
)
{

lib/AI/MXNet/Gluon/ModelZoo/Vision/DenseNet.pm  view on Meta::CPAN

    Densenet-BC model from the "Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf> paper.

    Parameters
    ----------
    num_init_features : Int
        Number of filters to learn in the first convolution layer.
    growth_rate : Int
        Number of filters to add each layer (`k` in the paper).
    block_config : array ref of Int
        List of integers for numbers of layers in each pooling block.
    bn_size : Int, default 4
        Multiplicative factor for number of bottle neck layers.
        (i.e. bn_size * k features in the bottleneck layer)
    dropout : float, default 0
        Rate of dropout after each dense layer.
    classes : int, default 1000
        Number of classification classes.
=cut
has [qw/num_init_features
        growth_rate/] => (is => 'ro', isa => 'Int', required => 1);
has 'block_config'    => (is => 'ro', isa => 'ArrayRef[Int]', required => 1);
has 'bn_size'         => (is => 'ro', isa => 'Int', default => 4);
has 'dropout'         => (is => 'ro', isa => 'Num', default => 0);
has 'classes'         => (is => 'ro', isa => 'Int', default => 1000);
method python_constructor_arguments(){ [qw/num_init_features growth_rate block_config bn_size dropout classes/] }

sub BUILD
{
    my $self = shift;
    $self->name_scope(sub {
        $self->features(nn->HybridSequential(prefix=>''));
        $self->features->add(
            nn->Conv2D(
                $self->num_init_features, kernel_size=>7,

lib/AI/MXNet/Gluon/ModelZoo/Vision/DenseNet.pm  view on Meta::CPAN


=head2 get_densenet

    Densenet-BC model from the
    "Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf> paper.

    Parameters
    ----------
    $num_layers : Int
        Number of layers for the variant of densenet. Options are 121, 161, 169, 201.
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method get_densenet(
    Int $num_layers, Bool :$pretrained=0, :$ctx=AI::MXNet::Context->cpu(),
    :$root='~/.mxnet/models',
    Int :$bn_size=4,
    Num :$dropout=0,
    Int :$classes=1000
)

lib/AI/MXNet/Gluon/ModelZoo/Vision/DenseNet.pm  view on Meta::CPAN

    return $net;
}

=head2 densenet121

    Densenet-BC 121-layer model from the
    "Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method densenet121(%kwargs)
{
    return __PACKAGE__->get_densenet(121, %kwargs)
}

=head2 densenet161

    Densenet-BC 161-layer model from the
    "Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method densenet161(%kwargs)
{
    return __PACKAGE__->get_densenet(161, %kwargs)
}

=head2 densenet169

    Densenet-BC 169-layer model from the
    "Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method densenet169(%kwargs)
{
    return __PACKAGE__->get_densenet(169, %kwargs)
}

=head2 densenet201

    Densenet-BC 201-layer model from the
    "Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method densenet201(%kwargs)
{
    return __PACKAGE__->get_densenet(201, %kwargs)
}

1;

lib/AI/MXNet/Gluon/ModelZoo/Vision/Inception.pm  view on Meta::CPAN

=cut

=head1 DESCRIPTION

    Inception v3 model from
    "Rethinking the Inception Architecture for Computer Vision"
    <http://arxiv.org/abs/1512.00567> paper.

    Parameters
    ----------
    classes : Int, default 1000
        Number of classification classes.
=cut

has 'classes' => (is => 'ro', isa => 'Int', default => 1000);
method python_constructor_arguments(){ ['classes'] }

sub BUILD
{
    my $self = shift;
    $self->name_scope(sub {
        $self->features(nn->HybridSequential(prefix=>''));
        $self->features->add(_make_basic_conv(channels=>32, kernel_size=>3, strides=>2));
        $self->features->add(_make_basic_conv(channels=>32, kernel_size=>3));
        $self->features->add(_make_basic_conv(channels=>64, kernel_size=>3, padding=>1));

lib/AI/MXNet/Gluon/ModelZoo/Vision/Inception.pm  view on Meta::CPAN

package AI::MXNet::Gluon::ModelZoo::Vision;

=head2 inception_v3

    Inception v3 model from
    "Rethinking the Inception Architecture for Computer Vision"
    <http://arxiv.org/abs/1512.00567> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method inception_v3(
    Bool :$pretrained=0, AI::MXNet::Context :$ctx=AI::MXNet::Context->cpu(),
    Str :$root='~/.mxnet/models', Int :$classes=1000
)
{
    my $net = AI::MXNet::Gluon::ModelZoo::Vision::Inception::V3->new($classes);
    if($pretrained)

lib/AI/MXNet/Gluon/ModelZoo/Vision/MobileNet.pm  view on Meta::CPAN

    {
        $out = $F->elemwise_add($out, $x);
    }
    return $out;
}

package AI::MXNet::Gluon::ModelZoo::Vision::MobileNet;
use AI::MXNet::Gluon::Mouse;
use AI::MXNet::Base;
extends 'AI::MXNet::Gluon::HybridBlock';
has 'multiplier' => (is => 'ro', isa => 'Num', default => 1);
has 'classes'    => (is => 'ro', isa => 'Int', default => 1000);
method python_constructor_arguments(){ [qw/multiplier classes/] }

=head1 NAME

    AI::MXNet::Gluon::ModelZoo::Vision::MobileNet - MobileNet model from the
        "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications"
=cut

=head1 DESCRIPTION

    MobileNet model from the
    "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications"
    <https://arxiv.org/abs/1704.04861> paper.

    Parameters
    ----------
    multiplier : Num, default 1.0
        The width multiplier for controling the model size. Only multipliers that are no
        less than 0.25 are supported. The actual number of channels is equal to the original
        channel size multiplied by this multiplier.
    classes : Int, default 1000
        Number of classes for the output layer.
=cut

func _add_conv(
    $out, :$channels=1, :$kernel=1, :$stride=1, :$pad=0,
    :$num_group=1, :$active=1, :$relu6=0
)
{
    $out->add(nn->Conv2D($channels, $kernel, $stride, $pad, groups=>$num_group, use_bias=>0));
    $out->add(nn->BatchNorm(scale=>1));

lib/AI/MXNet/Gluon/ModelZoo/Vision/MobileNet.pm  view on Meta::CPAN

{
    $x = $self->features->($x);
    $x = $self->output->($x);
    return $x;
}

package AI::MXNet::Gluon::ModelZoo::Vision::MobileNetV2;
use AI::MXNet::Gluon::Mouse;
use AI::MXNet::Base;
extends 'AI::MXNet::Gluon::HybridBlock';
has 'multiplier' => (is => 'ro', isa => 'Num', default => 1);
has 'classes'    => (is => 'ro', isa => 'Int', default => 1000);
method python_constructor_arguments(){ [qw/multiplier classes/] }

=head1 NAME

    AI::MXNet::Gluon::ModelZoo::Vision::MobileNetV2 - MobileNet model from the
        "Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation"
=cut

=head1 DESCRIPTION

    MobileNetV2 model from the
    "Inverted Residuals and Linear Bottlenecks:
      Mobile Networks for Classification, Detection and Segmentation"
    <https://arxiv.org/abs/1801.04381> paper.

    Parameters
    ----------
    multiplier : Num, default 1.0
        The width multiplier for controling the model size. Only multipliers that are no
        less than 0.25 are supported. The actual number of channels is equal to the original
        channel size multiplied by this multiplier.
    classes : Int, default 1000
        Number of classes for the output layer.
=cut

func _add_conv(
    $out, $channels, :$kernel=1, :$stride=1, :$pad=0,
    :$num_group=1, :$active=1, :$relu6=0
)
{
    $out->add(nn->Conv2D($channels, $kernel, $stride, $pad, groups=>$num_group, use_bias=>0));
    $out->add(nn->BatchNorm(scale=>1));

lib/AI/MXNet/Gluon/ModelZoo/Vision/MobileNet.pm  view on Meta::CPAN

    MobileNet model from the
    "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications"
    <https://arxiv.org/abs/1704.04861> paper.

    Parameters
    ----------
    $multiplier : Num
        The width multiplier for controling the model size. Only multipliers that are no
        less than 0.25 are supported. The actual number of channels is equal to the original
        channel size multiplied by this multiplier.
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method get_mobilenet(
    Num $multiplier, Bool :$pretrained=0, AI::MXNet::Context :$ctx=AI::MXNet::Context->cpu(),
    Str :$root='~/.mxnet/models'
)
{
    my $net = AI::MXNet::Gluon::ModelZoo::Vision::MobileNet->new($multiplier);
    if($pretrained)

lib/AI/MXNet/Gluon/ModelZoo/Vision/MobileNet.pm  view on Meta::CPAN

    "Inverted Residuals and Linear Bottlenecks:
      Mobile Networks for Classification, Detection and Segmentation"
    <https://arxiv.org/abs/1801.04381> paper.

    Parameters
    ----------
    $multiplier : Num
        The width multiplier for controling the model size. Only multipliers that are no
        less than 0.25 are supported. The actual number of channels is equal to the original
        channel size multiplied by this multiplier.
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method get_mobilenet_v2(
    Num $multiplier, Bool :$pretrained=0, AI::MXNet::Context :$ctx=AI::MXNet::Context->cpu(),
    Str :$root='~/.mxnet/models'
)
{
    my $net = AI::MXNet::Gluon::ModelZoo::Vision::MobileNetV2->new($multiplier);
    if($pretrained)

lib/AI/MXNet/Gluon/ModelZoo/Vision/MobileNet.pm  view on Meta::CPAN

}

=head2 mobilenet1_0

    MobileNet model from the
    "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications"
    <https://arxiv.org/abs/1704.04861> paper, with width multiplier 1.0.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
=cut

method mobilenet1_0(%kwargs)
{
    return __PACKAGE__->get_mobilenet(1.0, %kwargs);
}

=head2 mobilenet_v2_1_0

    MobileNetV2 model from the
    "Inverted Residuals and Linear Bottlenecks:
      Mobile Networks for Classification, Detection and Segmentation"
    <https://arxiv.org/abs/1801.04381> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
=cut

method mobilenet_v2_1_0(%kwargs)
{
    return __PACKAGE__->get_mobilenet_v2(1.0, %kwargs);
}

=head2 mobilenet0_75

    MobileNet model from the
    "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications"
    <https://arxiv.org/abs/1704.04861> paper, with width multiplier 0.75.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
=cut

method mobilenet0_75(%kwargs)
{
    return __PACKAGE__->get_mobilenet(0.75, %kwargs);
}

=head2 mobilenet_v2_0_75

    MobileNetV2 model from the
    "Inverted Residuals and Linear Bottlenecks:
      Mobile Networks for Classification, Detection and Segmentation"
    <https://arxiv.org/abs/1801.04381> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
=cut

method mobilenet_v2_0_75(%kwargs)
{
    return __PACKAGE__->get_mobilenet_v2(0.75, %kwargs);
}

=head2 mobilenet0_5

    MobileNet model from the
    "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications"
    <https://arxiv.org/abs/1704.04861> paper, with width multiplier 0.5.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
=cut

method mobilenet0_5(%kwargs)
{
    return __PACKAGE__->get_mobilenet(0.5, %kwargs);
}

=head2 mobilenet_v2_0_5

    MobileNetV2 model from the
    "Inverted Residuals and Linear Bottlenecks:
      Mobile Networks for Classification, Detection and Segmentation"
    <https://arxiv.org/abs/1801.04381> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
=cut

method mobilenet_v2_0_5(%kwargs)
{
    return __PACKAGE__->get_mobilenet_v2(0.5, %kwargs);
}

=head2 mobilenet0_25

    MobileNet model from the
    "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications"
    <https://arxiv.org/abs/1704.04861> paper, with width multiplier 0.25.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
=cut

method mobilenet0_25(%kwargs)
{
    return __PACKAGE__->get_mobilenet(0.25, %kwargs);
}

=head2 mobilenet_v2_0_25

    MobileNetV2 model from the
    "Inverted Residuals and Linear Bottlenecks:
      Mobile Networks for Classification, Detection and Segmentation"
    <https://arxiv.org/abs/1801.04381> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
=cut

method mobilenet_v2_0_25(%kwargs)
{
    return __PACKAGE__->get_mobilenet_v2(0.25, %kwargs);
}

1;

lib/AI/MXNet/Gluon/ModelZoo/Vision/ResNet.pm  view on Meta::CPAN

    BasicBlock V1 from `"Deep Residual Learning for Image Recognition"
    <http://arxiv.org/abs/1512.03385>`_ paper.
    This is used for ResNet V1 for 18, 34 layers.

    Parameters
    ----------
    channels : Int
        Number of output channels.
    stride : Int
        Stride size.
    downsample : Bool, default 0
        Whether to downsample the input.
    in_channels : Int, default 0
        Number of input channels. Default is 0, to infer from the graph.
=cut

has ['channels',
      'stride']   => (is => 'ro', isa => 'Int', required => 1);
has 'downsample' => (is => 'rw', default => 0);
has 'in_channels' => (is => 'ro', isa => 'Int', default => 0);
method python_constructor_arguments() { [qw/channels stride downsample/] }
func _conv3x3($channels, $stride, $in_channels)
{
    return nn->Conv2D(
        $channels, kernel_size=>3, strides=>$stride, padding=>1,
        use_bias=>0, in_channels=>$in_channels
    );
}

sub BUILD

lib/AI/MXNet/Gluon/ModelZoo/Vision/ResNet.pm  view on Meta::CPAN

    Bottleneck V1 from "Deep Residual Learning for Image Recognition"
    <http://arxiv.org/abs/1512.03385> paper.
    This is used for ResNet V1 for 50, 101, 152 layers.

    Parameters
    ----------
    channels : int
        Number of output channels.
    stride : int
        Stride size.
    downsample : bool, default False
        Whether to downsample the input.
    in_channels : int, default 0
        Number of input channels. Default is 0, to infer from the graph.
=cut

has ['channels',
      'stride']   => (is => 'ro', isa => 'Int', required => 1);
has 'downsample'  => (is => 'rw', default => 0);
has 'in_channels' => (is => 'ro', isa => 'Int', default => 0);
method python_constructor_arguments() { [qw/channels stride downsample/] }
func _conv3x3($channels, $stride, $in_channels)
{
    return nn->Conv2D(
        $channels, kernel_size=>3, strides=>$stride, padding=>1,
        use_bias=>0, in_channels=>$in_channels
    );
}

sub BUILD

lib/AI/MXNet/Gluon/ModelZoo/Vision/ResNet.pm  view on Meta::CPAN

    Bottleneck V2 from "Identity Mappings in Deep Residual Networks"
    <https://arxiv.org/abs/1603.05027> paper.
    This is used for ResNet V2 for 18, 34 layers.

    Parameters
    ----------
    channels : Int
        Number of output channels.
    stride : Int
        Stride size.
    downsample : Bool, default 0
        Whether to downsample the input.
    in_channels : Int, default 0
        Number of input channels. Default is 0, to infer from the graph.
=cut

has ['channels',
      'stride']   => (is => 'ro', isa => 'Int', required => 1);
has 'downsample' => (is => 'rw', default => 0);
has 'in_channels' => (is => 'ro', isa => 'Int', default => 0);
method python_constructor_arguments() { [qw/channels stride downsample/] }
func _conv3x3($channels, $stride, $in_channels)
{
    return nn->Conv2D(
        $channels, kernel_size=>3, strides=>$stride, padding=>1,
        use_bias=>0, in_channels=>$in_channels
    );
}

sub BUILD

lib/AI/MXNet/Gluon/ModelZoo/Vision/ResNet.pm  view on Meta::CPAN

    Bottleneck V2 from "Identity Mappings in Deep Residual Networks"
    <https://arxiv.org/abs/1603.05027> paper.
    This is used for ResNet V2 for 50, 101, 152 layers.

    Parameters
    ----------
    channels : int
        Number of output channels.
    stride : int
        Stride size.
    downsample : bool, default False
        Whether to downsample the input.
    in_channels : int, default 0
        Number of input channels. Default is 0, to infer from the graph.
=cut

has ['channels',
      'stride']   => (is => 'ro', isa => 'Int', required => 1);
has 'downsample' => (is => 'rw', default => 0);
has 'in_channels' => (is => 'ro', isa => 'Int', default => 0);
method python_constructor_arguments() { [qw/channels stride downsample/] }
func _conv3x3($channels, $stride, $in_channels)
{
    return nn->Conv2D(
        $channels, kernel_size=>3, strides=>$stride, padding=>1,
        use_bias=>0, in_channels=>$in_channels
    );
}

sub BUILD

lib/AI/MXNet/Gluon/ModelZoo/Vision/ResNet.pm  view on Meta::CPAN


    Parameters
    ----------
    block : AI::MXNet::Gluon::HybridBlock
        Class for the residual block. Options are AI::MXNet::Gluon::ModelZoo::Vision::ResNet::BasicBlockV1,
        AI::MXNet::Gluon::ModelZoo::Vision::ResNet::BottleneckV1.
    layers : array ref of Int
        Numbers of layers in each block
    channels : array ref of Int
        Numbers of channels in each block. Length should be one larger than layers list.
    classes : int, default 1000
        Number of classification classes.
    thumbnail : bool, default 0
        Enable thumbnail.
=cut

has 'block'     => (is => 'ro', isa => 'Str', required => 1);
has ['layers',
    'channels'] => (is => 'ro', isa => 'ArrayRef[Int]', required => 1);
has 'classes'   => (is => 'ro', isa => 'Int', default => 1000);
has 'thumbnail' => (is => 'ro', isa => 'Bool', default => 0);
method python_constructor_arguments() { [qw/block layers channels classes thumbnail/] }
func _conv3x3($channels, $stride, $in_channels)
{
    return nn->Conv2D(
        $channels, kernel_size=>3, strides=>$stride, padding=>1,
        use_bias=>0, in_channels=>$in_channels
    );
}

sub BUILD

lib/AI/MXNet/Gluon/ModelZoo/Vision/ResNet.pm  view on Meta::CPAN


    Parameters
    ----------
    block : AI::MXNet::Gluon::HybridBlock
        Class for the residual block. Options are AI::MXNet::Gluon::ModelZoo::Vision::ResNet::BasicBlockV2,
        AI::MXNet::Gluon::ModelZoo::Vision::ResNet::BottleneckV2.
    layers : array ref of Int
        Numbers of layers in each block
    channels : array ref of Int
        Numbers of channels in each block. Length should be one larger than layers list.
    classes : int, default 1000
        Number of classification classes.
    thumbnail : bool, default 0
        Enable thumbnail.
=cut

has 'block'     => (is => 'ro', isa => 'Str', required => 1);
has ['layers',
    'channels'] => (is => 'ro', isa => 'ArrayRef[Int]', required => 1);
has 'classes'   => (is => 'ro', isa => 'Int', default => 1000);
has 'thumbnail' => (is => 'ro', isa => 'Bool', default => 0);
method python_constructor_arguments() { [qw/block layers channels classes thumbnail/] }
func _conv3x3($channels, $stride, $in_channels)
{
    return nn->Conv2D(
        $channels, kernel_size=>3, strides=>$stride, padding=>1,
        use_bias=>0, in_channels=>$in_channels
    );
}

sub BUILD

lib/AI/MXNet/Gluon/ModelZoo/Vision/ResNet.pm  view on Meta::CPAN

    <http://arxiv.org/abs/1512.03385> paper.
    ResNet V2 model from "Identity Mappings in Deep Residual Networks"
    <https://arxiv.org/abs/1603.05027> paper.

    Parameters
    ----------
    $version : Int
        Version of ResNet. Options are 1, 2.
    $num_layers : Int
        Numbers of layers. Options are 18, 34, 50, 101, 152.
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

# Constructor
method get_resnet(
    Int $version, Int $num_layers, Bool :$pretrained=0,
    AI::MXNet::Context :$ctx=AI::MXNet::Context->cpu(),
    Str :$root='~/.mxnet/models',
    Maybe[Int]  :$classes=,
    Maybe[Bool] :$thumbnail=

lib/AI/MXNet/Gluon/ModelZoo/Vision/ResNet.pm  view on Meta::CPAN

    return $net;
}

=head2 resnet18_v1

    ResNet-18 V1 model from "Deep Residual Learning for Image Recognition"
    <http://arxiv.org/abs/1512.03385> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method resnet18_v1(%kwargs)
{
    return __PACKAGE__->get_resnet(1, 18, %kwargs);
}

=head2 resnet34_v1

    ResNet-34 V1 model from "Deep Residual Learning for Image Recognition"
    <http://arxiv.org/abs/1512.03385> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method resnet34_v1(%kwargs)
{
    return __PACKAGE__->get_resnet(1, 34, %kwargs);
}

=head2 resnet50_v1

    ResNet-50 V1 model from "Deep Residual Learning for Image Recognition"
    <http://arxiv.org/abs/1512.03385> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method resnet50_v1(%kwargs)
{
    return __PACKAGE__->get_resnet(1, 50, %kwargs);
}

=head2 resnet101_v1

    ResNet-101 V1 model from "Deep Residual Learning for Image Recognition"
    <http://arxiv.org/abs/1512.03385> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method resnet101_v1(%kwargs)
{
    return __PACKAGE__->get_resnet(1, 101, %kwargs);
}

=head2 resnet152_v1

    ResNet-152 V1 model from "Deep Residual Learning for Image Recognition"
    <http://arxiv.org/abs/1512.03385> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method resnet152_v1(%kwargs)
{
    return __PACKAGE__->get_resnet(1, 152, %kwargs);
}

=head2 resnet18_v2

    ResNet-18 V2 model from "Identity Mappings in Deep Residual Networks"
    <https://arxiv.org/abs/1603.05027> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method resnet18_v2(%kwargs)
{
    return __PACKAGE__->get_resnet(2, 18, %kwargs);
}

=head2 resnet34_v2

    ResNet-34 V2 model from "Identity Mappings in Deep Residual Networks"
    <https://arxiv.org/abs/1603.05027> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method resnet34_v2(%kwargs)
{
    return __PACKAGE__->get_resnet(2, 34, %kwargs);
}

=head2 resnet50_v2

    ResNet-50 V2 model from "Identity Mappings in Deep Residual Networks"
    <https://arxiv.org/abs/1603.05027> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method resnet50_v2(%kwargs)
{
    return __PACKAGE__->get_resnet(2, 50, %kwargs);
}

=head2 resnet101_v2

    ResNet-101 V2 model from "Identity Mappings in Deep Residual Networks"
    <https://arxiv.org/abs/1603.05027> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method resnet101_v2(%kwargs)
{
    return __PACKAGE__->get_resnet(2, 101, %kwargs);
}

=head2 resnet152_v2

    ResNet-152 V2 model from "Identity Mappings in Deep Residual Networks"
    <https://arxiv.org/abs/1603.05027> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method resnet152_v2(%kwargs)
{
    return __PACKAGE__->get_resnet(2, 152, %kwargs);
}

1;

lib/AI/MXNet/Gluon/ModelZoo/Vision/SqueezeNet.pm  view on Meta::CPAN

    and <0.5MB model size" <https://arxiv.org/abs/1602.07360> paper.
    SqueezeNet 1.1 model from the official SqueezeNet repo
    <https://github.com/DeepScale/SqueezeNet/tree/master/SqueezeNet_v1.1>.
    SqueezeNet 1.1 has 2.4x less computation and slightly fewer parameters
    than SqueezeNet 1.0, without sacrificing accuracy.

    Parameters
    ----------
    version : Str
        Version of squeezenet. Options are '1.0', '1.1'.
    classes : Int, default 1000
        Number of classification classes.
=cut

has 'version' => (is => 'ro', isa => enum([qw[1.0 1.1]]), required => 1);
has 'classes' => (is => 'ro', isa => 'Int', default => 1000);
method python_constructor_arguments() { [qw/version classes/] }

sub BUILD
{
    my $self = shift;
    $self->name_scope(sub {
        $self->features(nn->HybridSequential(prefix=>''));
        if($self->version eq '1.0')
        {
            $self->features->add(nn->Conv2D(96, kernel_size=>7, strides=>2));

lib/AI/MXNet/Gluon/ModelZoo/Vision/SqueezeNet.pm  view on Meta::CPAN

    and <0.5MB model size" <https://arxiv.org/abs/1602.07360> paper.
    SqueezeNet 1.1 model from the official SqueezeNet repo
    <https://github.com/DeepScale/SqueezeNet/tree/master/SqueezeNet_v1.1>.
    SqueezeNet 1.1 has 2.4x less computation and slightly fewer parameters
    than SqueezeNet 1.0, without sacrificing accuracy.

    Parameters
    ----------
    $version : Str
        Version of squeezenet. Options are '1.0', '1.1'.
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method get_squeezenet(
    Str $version, Bool :$pretrained=0, AI::MXNet::Context :$ctx=AI::MXNet::Context->cpu(),
    Str :$root='~/.mxnet/models', Int :$classes=1000
)
{
    my $net = AI::MXNet::Gluon::ModelZoo::Vision::SqueezeNet->new($version, $classes);
    if($pretrained)

lib/AI/MXNet/Gluon/ModelZoo/Vision/SqueezeNet.pm  view on Meta::CPAN

    return $net;
}

=head2 squeezenet1_0

    SqueezeNet 1.0 model from the "SqueezeNet: AlexNet-level accuracy with 50x fewer parameters
    and <0.5MB model size" <https://arxiv.org/abs/1602.07360> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method squeezenet1_0(%kwargs)
{
    return __PACKAGE__->get_squeezenet('1.0', %kwargs);
}

=head2 squeezenet1_1

    SqueezeNet 1.1 model from the official SqueezeNet repo
    <https://github.com/DeepScale/SqueezeNet/tree/master/SqueezeNet_v1.1>.
    SqueezeNet 1.1 has 2.4x less computation and slightly fewer parameters
    than SqueezeNet 1.0, without sacrificing accuracy.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default CPU
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method squeezenet1_1(%kwargs)
{
    return __PACKAGE__->get_squeezenet('1.1', %kwargs);
}

1;

lib/AI/MXNet/Gluon/ModelZoo/Vision/VGG.pm  view on Meta::CPAN


    VGG model from the "Very Deep Convolutional Networks for Large-Scale Image Recognition"
    <https://arxiv.org/abs/1409.1556> paper.

    Parameters
    ----------
    layers : array ref of Int
        Numbers of layers in each feature block.
    filters : array ref of Int
        Numbers of filters in each feature block. List length should match the layers.
    classes : Int, default 1000
        Number of classification classes.
    batch_norm : Bool, default 0
        Use batch normalization.
=cut
method python_constructor_arguments() { [qw/layers filters classes batch_norm/] }
has ['layers',
     'filters']   => (is => 'ro', isa => 'ArrayRef[Int]', required => 1);
has  'classes'    => (is => 'ro', isa => 'Int', default => 1000);
has  'batch_norm' => (is => 'ro', isa => 'Bool', default => 0);

sub BUILD
{
    my $self = shift;
    assert(@{ $self->layers } == @{ $self->filters });
    $self->name_scope(sub {
        $self->features($self->_make_features());
        $self->features->add(nn->Dense(4096, activation=>'relu',
                                       weight_initializer=>'normal',
                                       bias_initializer=>'zeros'));

lib/AI/MXNet/Gluon/ModelZoo/Vision/VGG.pm  view on Meta::CPAN


=head2 get_vgg

    VGG model from the "Very Deep Convolutional Networks for Large-Scale Image Recognition"
    <https://arxiv.org/abs/1409.1556> paper.

    Parameters
    ----------
    $num_layers : Int
        Number of layers for the variant of densenet. Options are 11, 13, 16, 19.
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default AI::MXNet::Context->cpu
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method get_vgg(
    Int $num_layers, Bool :$pretrained=0, AI::MXNet::Context :$ctx=AI::MXNet::Context->cpu(),
    Str :$root='~/.mxnet/models', Int :$classes=1000, Bool :$batch_norm=0
)
{
    my ($layers, $filters) = @{ $vgg_spec{$num_layers} };
    my $net = AI::MXNet::Gluon::ModelZoo::Vision::VGG->new($layers, $filters, $classes, $batch_norm);

lib/AI/MXNet/Gluon/ModelZoo/Vision/VGG.pm  view on Meta::CPAN

    return $net;
}

=head2 vgg11

    VGG-11 model from the "Very Deep Convolutional Networks for Large-Scale Image Recognition"
    <https://arxiv.org/abs/1409.1556> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default AI::MXNet::Context->cpu
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method vgg11(%kwargs)
{
    return __PACKAGE__->get_vgg(11, %kwargs);
}

=head2 vgg13

    VGG-13 model from the "Very Deep Convolutional Networks for Large-Scale Image Recognition"
    <https://arxiv.org/abs/1409.1556> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default AI::MXNet::Context->cpu
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method vgg13(%kwargs)
{
    return __PACKAGE__->get_vgg(13, %kwargs);
}

=head2 vgg16

    VGG-16 model from the "Very Deep Convolutional Networks for Large-Scale Image Recognition"
    <https://arxiv.org/abs/1409.1556> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default AI::MXNet::Context->cpu
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method vgg16(%kwargs)
{
    return __PACKAGE__->get_vgg(16, %kwargs);
}

=head2 vgg19

    VGG-19 model from the "Very Deep Convolutional Networks for Large-Scale Image Recognition"
    <https://arxiv.org/abs/1409.1556> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default AI::MXNet::Context->cpu
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method vgg19(%kwargs)
{
    return __PACKAGE__->get_vgg(19, %kwargs);
}

=head2 vgg11_bn

    VGG-11 model with batch normalization from the "Very Deep Convolutional Networks for Large-Scale Image Recognition"
    <https://arxiv.org/abs/1409.1556> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default AI::MXNet::Context->cpu
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method vgg11_bn(%kwargs)
{
    $kwargs{batch_norm} = 1;
    return __PACKAGE__->get_vgg(11, %kwargs);
}

=head2 vgg13_bn

    VGG-13 model with batch normalization from the "Very Deep Convolutional Networks for Large-Scale Image Recognition"
    <https://arxiv.org/abs/1409.1556> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default AI::MXNet::Context->cpu
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method vgg13_bn(%kwargs)
{
    $kwargs{batch_norm} = 1;
    return __PACKAGE__->get_vgg(13, %kwargs);
}

=head2 vgg16_bn

    VGG-16 model with batch normalization from the "Very Deep Convolutional Networks for Large-Scale Image Recognition"
    <https://arxiv.org/abs/1409.1556> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default AI::MXNet::Context->cpu
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method vgg16_bn(%kwargs)
{
    $kwargs{batch_norm} = 1;
    return __PACKAGE__->get_vgg(16, %kwargs);
}

=head2 vgg19_bn

    VGG-19 model with batch normalization from the "Very Deep Convolutional Networks for Large-Scale Image Recognition"
    <https://arxiv.org/abs/1409.1556> paper.

    Parameters
    ----------
    :$pretrained : Bool, default 0
        Whether to load the pretrained weights for model.
    :$ctx : AI::MXNet::Context, default AI::MXNet::Context->cpu
        The context in which to load the pretrained weights.
    :$root : Str, default '~/.mxnet/models'
        Location for keeping the model parameters.
=cut

method vgg19_bn(%kwargs)
{
    $kwargs{batch_norm} = 1;
    return __PACKAGE__->get_vgg(19, %kwargs);
}

1;



( run in 0.756 second using v1.01-cache-2.11-cpan-0a6323c29d9 )