AI-MXNet-Gluon-ModelZoo

 view release on metacpan or  search on metacpan

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

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

package AI::MXNet::Gluon::ModelZoo::Vision::Inception::V3;
use strict;
use warnings;
use AI::MXNet::Base;
use AI::MXNet::Function::Parameters;
use AI::MXNet::Gluon::Mouse;
extends 'AI::MXNet::Gluon::HybridBlock';

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);
    $out->name_scope(sub {
        $out->add(_make_branch('', [64, 1, undef, undef]));
        $out->add(_make_branch(
            '',
            [48, 1, undef, undef],
            [64, 5, undef, 2]



( run in 0.709 second using v1.01-cache-2.11-cpan-39bf76dae61 )