AI-MXNet-Gluon-ModelZoo

 view release on metacpan or  search on metacpan

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

        }
        $out->add(_make_basic_conv(%kwargs));
    }
    return $out;
}

func _make_A($pool_features, $prefix)
{
    my $out = nn->HybridConcurrent(axis=>1, prefix=>$prefix);
    $out->name_scope(sub {
        $out->add(_make_branch('', [64, 1, undef, undef]));
        $out->add(_make_branch(
            '',
            [48, 1, undef, undef],
            [64, 5, undef, 2]
        ));
        $out->add(_make_branch(
            '',
            [64, 1, undef, undef],
            [96, 3, undef, 1],
            [96, 3, undef, 1]
        ));
        $out->add(_make_branch('avg', [$pool_features, 1, undef, undef]));
    });
    return $out;
}

func _make_B($prefix)
{
    my $out = nn->HybridConcurrent(axis=>1, prefix=>$prefix);
    $out->name_scope(sub {
        $out->add(_make_branch('', [384, 3, 2, undef]));
        $out->add(_make_branch(
            '',
            [64, 1, undef, undef],
            [96, 3, undef, 1],
            [96, 3, 2, undef]
        ));
        $out->add(_make_branch('max'));
    });
    return $out;
}

func _make_C($channels_7x7, $prefix)
{
    my $out = nn->HybridConcurrent(axis=>1, prefix=>$prefix);
    $out->name_scope(sub {
        $out->add(_make_branch('', [192, 1, undef, undef]));
        $out->add(_make_branch(
            '',
            [$channels_7x7, 1, undef, undef],
            [$channels_7x7, [1, 7], undef, [0, 3]],
            [192, [7, 1], undef, [3, 0]]
        ));
        $out->add(_make_branch(
            '',
            [$channels_7x7, 1, undef, undef],
            [$channels_7x7, [7, 1], undef, [3, 0]],
            [$channels_7x7, [1, 7], undef, [0, 3]],
            [$channels_7x7, [7, 1], undef, [3, 0]],
            [192, [1, 7], undef, [0, 3]]
        ));
        $out->add(_make_branch(
            'avg',
            [192, 1, undef, undef]
        ));
    });
    return $out;
}

func _make_D($prefix)
{
    my $out = nn->HybridConcurrent(axis=>1, prefix=>$prefix);
    $out->name_scope(sub {
        $out->add(_make_branch(
            '',
            [192, 1, undef, undef],
            [320, 3, 2, undef]
        ));
        $out->add(_make_branch(
            '',
            [192, 1, undef, undef],
            [192, [1, 7], undef, [0, 3]],
            [192, [7, 1], undef, [3, 0]],
            [192, 3, 2, undef]
        ));
        $out->add(_make_branch('max'));
    });
    return $out;
}

func _make_E($prefix)
{
    my $out = nn->HybridConcurrent(axis=>1, prefix=>$prefix);
    $out->name_scope(sub {
        $out->add(_make_branch('', [320, 1, undef, undef]));

        my $branch_3x3 = nn->HybridSequential(prefix=>'');
        $out->add($branch_3x3);
        $branch_3x3->add(_make_branch(
            '',
            [384, 1, undef, undef]
        ));
        my $branch_3x3_split = nn->HybridConcurrent(axis=>1, prefix=>'');
        $branch_3x3_split->add(_make_branch('', [384, [1, 3], undef, [0, 1]]));
        $branch_3x3_split->add(_make_branch('', [384, [3, 1], undef, [1, 0]]));
        $branch_3x3->add($branch_3x3_split);

        my $branch_3x3dbl = nn->HybridSequential(prefix=>'');
        $out->add($branch_3x3dbl);
        $branch_3x3dbl->add(_make_branch(
            '',
            [448, 1, undef, undef],
            [384, 3, undef, 1]
        ));
        my $branch_3x3dbl_split = nn->HybridConcurrent(axis=>1, prefix=>'');
        $branch_3x3dbl->add($branch_3x3dbl_split);
        $branch_3x3dbl_split->add(_make_branch('', [384, [1, 3], undef, [0, 1]]));
        $branch_3x3dbl_split->add(_make_branch('', [384, [3, 1], undef, [1, 0]]));

        $out->add(_make_branch('avg', [192, 1, undef, undef]));
    });
    return $out;
}

func make_aux($classes)
{
    my $out = nn->HybridSequential(prefix=>'');
    $out->add(nn->AvgPool2D(pool_size=>5, strides=>3));
    $out->add(_make_basic_conv(channels=>128, kernel_size=>1));
    $out->add(_make_basic_conv(channels=>768, kernel_size=>5));

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

    {
        $self->downsample(nn->HybridSequential(prefix=>''));
        $self->downsample->add(
            nn->Conv2D($self->channels, kernel_size=>1, strides=>$self->stride,
                       use_bias=>0, in_channels=>$self->in_channels)
        );
        $self->downsample->add(nn->BatchNorm());
    }
    else
    {
        $self->downsample(undef);
    }
}

method hybrid_forward(GluonClass $F, GluonInput $x)
{
    my $residual = $x;
    $x = $self->body->($x);
    if(defined $self->downsample)
    {
        $residual = $self->downsample->($residual);

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

    {
        $self->downsample(nn->HybridSequential(prefix=>''));
        $self->downsample->add(
            nn->Conv2D($self->channels, kernel_size=>1, strides=>$self->stride,
                       use_bias=>0, in_channels=>$self->in_channels)
        );
        $self->downsample->add(nn->BatchNorm());
    }
    else
    {
        $self->downsample(undef);
    }
}

method hybrid_forward(GluonClass $F, GluonInput $x)
{
    my $residual = $x;
    $x = $self->body->($x);
    if(defined $self->downsample)
    {
        $residual = $self->downsample->($residual);

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

    $self->conv2(_conv3x3($self->channels, 1, $self->channels));
    if($self->downsample)
    {
        $self->downsample(
            nn->Conv2D($self->channels, kernel_size=>1, strides=>$self->stride,
                       use_bias=>0, in_channels=>$self->in_channels)
        );
    }
    else
    {
        $self->downsample(undef);
    }
}

method hybrid_forward(GluonClass $F, GluonInput $x)
{
    my $residual = $x;
    $x = $self->bn1->($x);
    $x = $F->Activation($x, act_type=>'relu');
    if(defined $self->downsample)
    {

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

    $self->conv3(nn->Conv2D($self->channels, kernel_size=>1, strides=>1, use_bias=>0));
    if($self->downsample)
    {
        $self->downsample(
            nn->Conv2D($self->channels, kernel_size=>1, strides=>$self->stride,
                       use_bias=>0, in_channels=>$self->in_channels)
        );
    }
    else
    {
        $self->downsample(undef);
    }
}

method hybrid_forward(GluonClass $F, GluonInput $x)
{
    my $residual = $x;
    $x = $self->bn1->($x);
    $x = $F->Activation($x, act_type=>'relu');
    if(defined $self->downsample)
    {



( run in 2.171 seconds using v1.01-cache-2.11-cpan-d80b1682f3f )