AI-MXNet-Gluon-ModelZoo
view release on metacpan or search on metacpan
examples/image_classification.pl view on Meta::CPAN
# Resize the short edge into 256 pixes,
# And then perform a center crop to obtain a 224-by-224 image.
# The following code uses the image processing functions provided
# in the AI::MXNet::Image module.
$image = mx->image->imread($image);
$image = mx->image->resize_short($image, $model =~ /inception/ ? 330 : 256);
($image) = mx->image->center_crop($image, [($model =~ /inception/ ? 299 : 224)x2]);
## CV that is used to read image is column major (as PDL)
$image = $image->transpose([2,0,1])->expand_dims(axis=>0);
## normalizing the image
my $rgb_mean = nd->array([0.485, 0.456, 0.406])->reshape([1,3,1,1]);
my $rgb_std = nd->array([0.229, 0.224, 0.225])->reshape([1,3,1,1]);
$image = ($image->astype('float32') / 255 - $rgb_mean) / $rgb_std;
# Now we can recognize the object in the image.
# We perform an additional softmax on the output to obtain probability scores.
# And then print the top-5 recognized objects.
my $prob = $net->($image)->softmax;
lib/AI/MXNet/Gluon/ModelZoo/Vision/SqueezeNet.pm view on Meta::CPAN
# under the License.
package AI::MXNet::Gluon::ModelZoo::Vision::SqueezeNet;
use strict;
use warnings;
use AI::MXNet::Function::Parameters;
use AI::MXNet::Gluon::Mouse;
use AI::MXNet::Types;
extends 'AI::MXNet::Gluon::HybridBlock';
func _make_fire($squeeze_channels, $expand1x1_channels, $expand3x3_channels)
{
my $out = nn->HybridSequential(prefix=>'');
$out->add(_make_fire_conv($squeeze_channels, 1));
my $paths = nn->HybridConcurrent(axis=>1, prefix=>'');
$paths->add(_make_fire_conv($expand1x1_channels, 1));
$paths->add(_make_fire_conv($expand3x3_channels, 3, 1));
$out->add($paths);
return $out;
}
func _make_fire_conv($channels, $kernel_size, $padding=0)
{
my $out = nn->HybridSequential(prefix=>'');
$out->add(nn->Conv2D($channels, $kernel_size, padding=>$padding));
$out->add(nn->Activation('relu'));
( run in 1.090 second using v1.01-cache-2.11-cpan-97f6503c9c8 )