AI-MXNet
view release on metacpan or search on metacpan
lib/AI/MXNet/Executor.pm view on Meta::CPAN
528529530531532533534535536537538539540541542543544545546547548549550551552553
ctx
=>
$self
->_ctx,
args
=> \
%new_arg_dict
,
args_grad
=> \
%new_grad_dict
,
grad_req
=>
$self
->_grad_req,
aux_states
=> \
%new_aux_dict
,
group2ctx
=>
$self
->_group2ctx,
shared_exec
=>
$self
);
}
=head2 debug_str
A debug string about the internal execution plan.
Returns
-------
debug_str : string
Debug string of the executor.
=cut
method debug_str()
{
return
scalar
(check_call(AI::MXNetCAPI::ExecutorPrint(
$self
->handle)));
}
1;
lib/AI/MXNet/IO.pm view on Meta::CPAN
585586587588589590591592593594595596597598599600601602603604605606use
AI::MXNet::Base;
=head1 NAME
AI::MXNet::MXDataIter - A data iterator pre-built in C++ layer of MXNet.
=cut
has
'handle'
=> (
is
=>
'ro'
,
isa
=>
'DataIterHandle'
,
required
=> 1);
has
'_debug_skip_load'
=> (
is
=>
'rw'
,
isa
=>
'Int'
,
default
=> 0);
has
'_debug_at_begin'
=> (
is
=>
'rw'
,
isa
=>
'Int'
,
default
=> 0);
has
'data_name'
=> (
is
=>
'ro'
,
isa
=>
'Str'
,
default
=>
'data'
);
has
'label_name'
=> (
is
=>
'ro'
,
isa
=>
'Str'
,
default
=>
'softmax_label'
);
has
[
qw/first_batch
provide_data
provide_label
batch_size/
] => (
is
=>
'rw'
,
init_arg
=>
undef
);
sub
BUILD
{
my
$self
=
shift
;
lib/AI/MXNet/IO.pm view on Meta::CPAN
622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
)
]);
$self
->batch_size(
$data
->shape->[0]);
}
sub
DEMOLISH
{
check_call(AI::MXNetCAPI::DataIterFree(
shift
->handle));
}
=head2 debug_skip_load
Set the iterator to simply return always first batch.
Notes
-----
This can be used to test the speed of network without taking
the loading delay into account.
=cut
method debug_skip_load()
{
$self
->_debug_skip_load(1);
AI::MXNet::Logging->info(
'Set debug_skip_load to be true, will simply return first batch'
);
}
method
reset
()
{
$self
->_debug_at_begin(1);
$self
->first_batch(
undef
);
check_call(AI::MXNetCAPI::DataIterBeforeFirst(
$self
->handle));
}
method
next
()
{
if
(
$self
->_debug_skip_load and not
$self
->_debug_at_begin)
{
return
AI::MXNet::DataBatch->new(
data
=> [
$self
->getdata],
label
=> [
$self
->getlabel],
pad
=>
$self
->getpad,
index
=>
$self
->getindex
);
}
if
(
defined
$self
->first_batch)
{
my
$batch
=
$self
->first_batch;
$self
->first_batch(
undef
);
return
$batch
}
$self
->_debug_at_begin(0);
my
$next_res
= check_call(AI::MXNetCAPI::DataIterNext(
$self
->handle));
if
(
$next_res
)
{
return
AI::MXNet::DataBatch->new(
data
=> [
$self
->getdata],
label
=> [
$self
->getlabel],
pad
=>
$self
->getpad,
index
=>
$self
->getindex
);
}
lib/AI/MXNet/Image.pm view on Meta::CPAN
891892893894895896897898899900901902903904905906907908909910911my
$batch_data
= AI::MXNet::NDArray->empty([
$batch_size
,
$c
,
$h
,
$w
]);
my
$batch_label
= AI::MXNet::NDArray->empty(@{
$self
->provide_label->[0]}[1]);
my
$i
= 0;
while
(
$i
<
$batch_size
)
{
my
(
$label
,
$s
) =
$self
->next_sample;
last
if
not
defined
$label
;
my
$data
= [AI::MXNet::Image->imdecode(
$s
)];
if
(@{
$data
->[0]->shape } == 0)
{
AI::MXNet::Logging->debug(
'Invalid image, skipping.'
);
next
;
}
for
my
$aug
(@{
$self
->aug_list })
{
$data
= [
map
{ @{
$aug
->(
$_
) } }
@$data
];
}
for
my
$d
(
@$data
)
{
assert((
$i
<
$batch_size
),
'Batch size must be multiples of augmenter output length'
);
$batch_data
->at(
$i
) .= AI::MXNet::NDArray->transpose(
$d
, {
axes
=>[2, 0, 1] });
lib/AI/MXNet/Logging.pm view on Meta::CPAN
12345678package
AI::MXNet::Logging;
## TODO
use
Mouse;
sub
warning {
shift
;
warn
sprintf
(
shift
,
@_
) .
"\n"
};
*debug
=
*info
=
*warning
;
sub
get_logger { __PACKAGE__->new }
1;
lib/AI/MXNet/Monitor.pm view on Meta::CPAN
12345678910111213141516171819202122package
AI::MXNet::Monitor;
use
Mouse;
use
AI::MXNet::Base;
=head1 NAME
AI::MXNet::Monitor - Monitor outputs, weights, and gradients for debugging.
=head1 DESCRIPTION
Monitor outputs, weights, and gradients for debugging.
Parameters
----------
interval : int
Number of batches between printing.
stat_func : function
a function that computes statistics of tensors.
Takes a NDArray and returns a NDArray. defaults to mean
absolute value |x|/size(x).
pattern : str
lib/AI/MXNet/Monitor.pm view on Meta::CPAN
108109110111112113114115116117118119120121122123124125126127128
$self
->step(
$self
->step + 1);
}
=head2 toc
End collecting for current batch and return results.
Call after computation of current batch.
Returns
-------
res : array ref of array refs with debug info
=cut
method toc()
{
return
[]
unless
$self
->activated;
for
my
$exe
(@{
$self
->exes })
{
$_
->wait_to_read
for
@{
$exe
->arg_arrays };
$_
->wait_to_read
for
@{
$exe
->aux_arrays };
}
lib/AI/MXNet/Symbol.pm view on Meta::CPAN
637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
if
(
$complete
)
{
return
$arg_shapes
,
$out_shapes
,
$aux_shapes
;
}
else
{
return
(
undef
,
undef
,
undef
);
}
}
=head2 debug_str
The debug string.
Returns
-------
debug_str : string
Debug string of the symbol.
=cut
method debug_str()
{
return
scalar
(check_call(AI::MXNetCAPI::SymbolPrint(
$self
->handle)));
}
=head2 save
Save the symbol into a file.
You can also use Storable to do the job if you only work with Perl.
The advantage of load/save is the file is language agnostic.
lib/AI/MXNet/Visualization.pm view on Meta::CPAN
395396397398399400401402403404405406407408409410411412413414415
}
}
return
$dot
;
}
use
Mouse;
use
AI::MXNet::Types;
has
'format'
=> (
is
=>
'ro'
,
isa
=> enum([
qw/debug canon text ps hpgl pcl mif
pic gd gd2 gif jpeg png wbmp cmapx
imap vdx vrml vtx mp fig svg svgz
plain/
]
)
);
has
'graph'
=> (
is
=>
'ro'
,
isa
=>
'GraphViz'
);
method render(
$output
=)
{
my
$method
=
'as_'
.
$self
->
format
;
( run in 0.678 second using v1.01-cache-2.11-cpan-26ccb49234f )