AI-MXNet

 view release on metacpan or  search on metacpan

lib/AI/MXNet/Executor.pm  view on Meta::CPAN

528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
                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

585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
 
extends 'https://metacpan.org/pod/AI::MXNet::DataIter">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

622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
        )
    ]);
    $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

891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
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

1
2
3
4
5
6
7
8
## 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use Mouse;
 
=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

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
        $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

637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
    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

395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
        }
    }
    return $dot;
}
 
use Mouse;
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 )