AI-MXNet-Gluon-ModelZoo

 view release on metacpan or  search on metacpan

examples/image_classification.pl  view on Meta::CPAN


use strict;
use warnings;
use AI::MXNet::Gluon::ModelZoo 'get_model';
use AI::MXNet::Gluon::Utils 'download';
use Getopt::Long qw(HelpMessage);

GetOptions(
    ## my Pembroke Welsh Corgi Kyuubi, enjoing Solar eclipse of August 21, 2017
    'image=s' => \(my $image = 'http://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/'.
                               '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;

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


func _make_basic_conv(%kwargs)
{
    my $out = nn->HybridSequential(prefix=>'');
    $out->add(nn->Conv2D(use_bias=>0, %kwargs));
    $out->add(nn->BatchNorm(epsilon=>0.001));
    $out->add(nn->Activation('relu'));
    return $out;
}

func _make_branch($use_pool, @conv_settings)
{
    my $out = nn->HybridSequential(prefix=>'');
    if($use_pool eq 'avg')
    {
        $out->add(nn->AvgPool2D(pool_size=>3, strides=>1, padding=>1));
    }
    elsif($use_pool eq 'max')
    {
        $out->add(nn->MaxPool2D(pool_size=>3, strides=>2));
    }
    my @setting_names = ('channels', 'kernel_size', 'strides', 'padding');
    for my $setting (@conv_settings)
    {
        my %kwargs;
        for(enumerate($setting))
        {
            my ($i, $value) = @$_;
            if(defined $value)
            {
                $kwargs{ $setting_names[$i] } = $value;
            }
        }
        $out->add(_make_basic_conv(%kwargs));
    }
    return $out;
}

func _make_A($pool_features, $prefix)
{
    my $out = nn->HybridConcurrent(axis=>1, prefix=>$prefix);



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