AI-MXNet-Gluon-ModelZoo

 view release on metacpan or  search on metacpan

examples/image_classification.pl  view on Meta::CPAN

                               'gluon/dataset/kyuubi.jpg'),
    'model=s' => \(my $model = 'resnet152_v2'),
    'help'    => sub { HelpMessage(0) },
) or HelpMessage(1);

## get a pretrained model (download parameters file if necessary)
my $net = get_model($model, pretrained => 1);

## ImageNet classes
my $fname = download('http://data.mxnet.io/models/imagenet/synset.txt');
my @text_labels = map { chomp; s/^\S+\s+//; $_ } IO::File->new($fname)->getlines;

## get the image from the disk or net
if($image =~ /^https/)
{
    eval { require IO::Socket::SSL; };
    die "Need to have IO::Socket::SSL installed for https images" if $@;
}
$image = $image =~ /^https?/ ? download($image) : $image;

# Following the conventional way of preprocessing ImageNet data:

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


=head1 NAME

    AI::MXNet::Gluon::ModelZoo::ModelStore - Model zoo for pre-trained models.
=cut

use AI::MXNet::Gluon::Utils qw(download check_sha1);
use IO::Uncompress::Unzip qw(unzip);
use File::Path qw(make_path);

my %_model_sha1 = map { $_->[1] => $_->[0] } (
    ['44335d1f0046b328243b32a26a4fbd62d9057b45', 'alexnet'],
    ['f27dbf2dbd5ce9a80b102d89c7483342cd33cb31', 'densenet121'],
    ['b6c8a95717e3e761bd88d145f4d0a214aaa515dc', 'densenet161'],
    ['2603f878403c6aa5a71a124c4a3307143d6820e9', 'densenet169'],
    ['1cdbc116bc3a1b65832b18cf53e1cb8e7da017eb', 'densenet201'],
    ['ed47ec45a937b656fcc94dabde85495bbef5ba1f', 'inceptionv3'],
    ['9f83e440996887baf91a6aff1cccc1c903a64274', 'mobilenet0.25'],
    ['8e9d539cc66aa5efa71c4b6af983b936ab8701c3', 'mobilenet0.5'],
    ['529b2c7f4934e6cb851155b22c96c9ab0a7c4dc2', 'mobilenet0.75'],
    ['6b8c5106c730e8750bcd82ceb75220a3351157cd', 'mobilenet1.0'],

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


    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/MobileNet.pm  view on Meta::CPAN

    _add_conv($out, channels=>$channels, relu6=>$relu6);
}

sub BUILD
{
    my $self = shift;
    $self->name_scope(sub {
        $self->features(nn->HybridSequential(prefix=>''));
        $self->features->name_scope(sub {
            _add_conv($self->features, channels=>int(32 * $self->multiplier), kernel=>3, pad=>1, stride=>2);
            my $dw_channels = [map { int($_ * $self->multiplier) } (32, 64, (128)x2, (256)x2, (512)x6, 1024)];
            my $channels = [map { int($_ * $self->multiplier) } (64, (128)x2, (256)x2, (512)x6, (1024)x2)];
            my $strides = [(1, 2)x3, (1)x5, 2, 1];
            for(zip($dw_channels, $channels, $strides))
            {
                my ($dwc, $c, $s) = @$_;
                _add_conv_dw($self->features, dw_channels=>$dwc, channels=>$c, stride=>$s);
            }
            $self->features->add(nn->GlobalAvgPool2D());
            $self->features->add(nn->Flatten());
        });
        $self->output(nn->Dense($self->classes));

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

{
    my $self = shift;
    $self->name_scope(sub {
        $self->features(nn->HybridSequential(prefix=>'features_'));
        $self->features->name_scope(sub {
            _add_conv(
                $self->features, int(32 * $self->multiplier), kernel=>3,
                stride=>2, pad=>1, relu6=>1
            );

            my $in_channels_group = [map { int($_ * $self->multiplier) } (32, 16, (24)x2, (32)x3, (64)x4, (96)x3, (160)x3)];
            my $channels_group = [map { int($_ * $self->multiplier) } (16, (24)x2, (32)x3, (64)x4, (96)x3, (160)x3, 320)];
            my $ts = [1, (6)x16];
            my $strides = [(1, 2)x2, 1, 1, 2, (1)x6, 2, (1)x3];

            for(zip($in_channels_group, $channels_group, $ts, $strides))
            {
                my ($in_c, $c, $t, $s) = @$_;
                $self->features->add(
                    AI::MXNet::Gluon::ModelZoo::Vision::MobileNet::LinearBottleneck->new(
                        in_channels=>$in_c, channels=>$c,
                        t=>$t, stride=>$s



( run in 0.636 second using v1.01-cache-2.11-cpan-49f99fa48dc )