AI-MXNet-Gluon-ModelZoo
view release on metacpan or search on metacpan
lib/AI/MXNet/Gluon/ModelZoo/Vision/DenseNet.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::DenseNet;
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_dense_block($num_layers, $bn_size, $growth_rate, $dropout, $stage_index)
{
my $out = nn->HybridSequential(prefix=>"stage${stage_index}_");
$out->name_scope(sub {
for(1..$num_layers)
{
$out->add(_make_dense_layer($growth_rate, $bn_size, $dropout));
}
});
return $out;
}
func _make_dense_layer($growth_rate, $bn_size, $dropout)
{
my $new_features = nn->HybridSequential(prefix=>'');
$new_features->add(nn->BatchNorm());
$new_features->add(nn->Activation('relu'));
$new_features->add(nn->Conv2D($bn_size * $growth_rate, kernel_size=>1, use_bias=>0));
$new_features->add(nn->BatchNorm());
$new_features->add(nn->Activation('relu'));
$new_features->add(nn->Conv2D($growth_rate, kernel_size=>3, padding=>1, use_bias=>0));
if($dropout)
{
$new_features->add(nn->Dropout($dropout));
}
my $out = nn->HybridConcurrent(axis=>1, prefix=>'');
$out->add(nn->Identity());
$out->add($new_features);
return $out;
}
func _make_transition($num_output_features)
{
my $out = nn->HybridSequential(prefix=>'');
$out->add(nn->BatchNorm());
$out->add(nn->Activation('relu'));
$out->add(nn->Conv2D($num_output_features, kernel_size=>1, use_bias=>0));
( run in 0.525 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )