ModelZoo.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« ModelZoo/Vision/VGG.pm ↑ Summary
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17  
18 package AI::MXNet::Gluon::ModelZoo;
19 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 0 ▶use AI::MXNet qw(mx);
Subroutine BEGIN: called CC=1 SCAR=2.6
22 use AI::MXNet::Gluon qw(gluon);
23 use AI::MXNet::Gluon::NN qw(nn);
24 use AI::MXNet::Gluon::Contrib;
25 use AI::MXNet::Gluon::ModelZoo::Vision;
26 use Exporter;
27 use base qw(Exporter);
28 @AI::MXNet::Gluon::ModelZoo::EXPORT_OK = qw(get_model);
29 our $VERSION = '1.33';
30  
31 =head1 NAME
32  
33 AI::MXNet::Gluon::ModelZoo - A collection of pretrained MXNet Gluon models
34 =cut
35  
36 =head1 SYNOPSIS
37  
38 ## run forward prediction on random data
39 use AI::MXNet::Gluon::ModelZoo qw(get_model);
40 my $alexnet = get_model('alexnet', pretrained => 1);
41 my $out = $alexnet->(mx->nd->random->uniform(shape=>[1, 3, 224, 224]));
42 print $out->aspdl;
43 =cut
44  
45 =head1 DESCRIPTION
46  
47 This module houses a collection of pretrained models (the parameters are hosted on public mxnet servers).
48 https://mxnet.incubator.apache.org/api/python/gluon/model_zoo.html
49 See examples/image_classification.pl for the example of real time image classification
50 using a pretrained model from the ModelZoo
51 =cut
52  
53 our %models = qw/
54 resnet18_v1 resnet18_v1
55 resnet34_v1 resnet34_v1
56 resnet50_v1 resnet50_v1
57 resnet101_v1 resnet101_v1
58 resnet152_v1 resnet152_v1
59 resnet18_v2 resnet18_v2
60 resnet34_v2 resnet34_v2
61 resnet50_v2 resnet50_v2
62 resnet101_v2 resnet101_v2
63 resnet152_v2 resnet152_v2
64 vgg11 vgg11
65 vgg13 vgg13
66 vgg16 vgg16
67 vgg19 vgg19
68 vgg11_bn vgg11_bn
69 vgg13_bn vgg13_bn
70 vgg16_bn vgg16_bn
71 vgg19_bn vgg19_bn
72 alexnet alexnet
73 densenet121 densenet121
74 densenet161 densenet161
75 densenet169 densenet169
76 densenet201 densenet201
77 squeezenet1.0 squeezenet1_0
78 squeezenet1.1 squeezenet1_1
79 inceptionv3 inception_v3
80 mobilenet1.0 mobilenet1_0
81 mobilenet0.75 mobilenet0_75
82 mobilenet0.5 mobilenet0_5
83 mobilenet0.25 mobilenet0_25
84 mobilenetv2_1.0 mobilenet_v2_1_0
85 mobilenetv2_0.75 mobilenet_v2_0_75
86 mobilenetv2_0.5 mobilenet_v2_0_5
87 mobilenetv2_0.25 mobilenet_v2_0_25
88 /;
89  
90  
91 =head2 get_model
92  
93 Returns a pre-defined model by name
94  
95 Parameters
96 ----------
97 $name : Str
98 Name of the model.
99 :$pretrained : Bool
100 Whether to load the pretrained weights for model.
101 :$classes : Int
102 Number of classes for the output layer.
103 :$ctx : AI::MXNet::Context, default CPU
104 The context in which to load the pretrained weights.
105 :$root : Str, default '~/.mxnet/models'
106 Location for keeping the model parameters.
107  
108 Returns
109 -------
110 HybridBlock
111 The model.
112 =cut
113  
114 sub get_model
115 {
116 if(exists $models{lc $_[1]})
117 {
118 shift;
119 }
120 my ($name, %kwargs) = @_;
121 $name = lc $name;
122 Carp::confess(
123 "Model $name is not present in the zoo\nValid models are:\n".
124 join(', ', sort keys %models)."\n"
125 ) unless exists $models{$name};
126 my $sub = $models{$name};
127 AI::MXNet::Gluon::ModelZoo::Vision->$sub(%kwargs);
128 }
129  
130 sub vision { 'AI::MXNet::Gluon::ModelZoo::Vision' }
131  
132 1;
133  
134 =head1 AUTHOR
135  
136 Sergey Kolychev, <sergeykolychev.github@gmail.com>
137  
138 =head1 COPYRIGHT & LICENSE
139  
140 This library is licensed under Apache 2.0 license L<https://www.apache.org/licenses/LICENSE-2.0>
141  
142 =cut
« ModelZoo/Vision/VGG.pm ↑ Summary