AI-MXNet
view release on metacpan or search on metacpan
lib/AI/MXNet/Executor.pm view on Meta::CPAN
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
use AI::MXNet::Base;
extends 'AI::MXNet::DataIter';
=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
)
]);
$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
my $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
package 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
package AI::MXNet::Monitor;
use Mouse;
use AI::MXNet::Function::Parameters;
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
$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
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
}
}
return $dot;
}
package AI::MXNet::Visualization::PythonGraphviz;
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.451 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )