sergeykolychev commented on issue #7334: cannot use ImageIter in Perl package
URL: 
https://github.com/apache/incubator-mxnet/issues/7334#issuecomment-320481894
 
 
   @dokechin 
   Thank you. Let's move to next level of our debugging. I've fixed your 
immediate problem and the data is being loaded. Try to plug in this iter into  
mxnet and train something, we'll see if you hit any snugs.
   Here's the patch to the Image.pm that fixes the bugs:
   ```developer@devbox:~/mxnet/perl-package/AI-MXNet$ git diff
   diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/Image.pm 
b/perl-package/AI-MXNet/lib/AI/MXNet/Image.pm
   index 50e4a41..e61d1a4 100644
   --- a/perl-package/AI-MXNet/lib/AI/MXNet/Image.pm
   +++ b/perl-package/AI-MXNet/lib/AI/MXNet/Image.pm
   @@ -747,7 +747,7 @@ sub BUILD
            {
                chomp($line);
                my @line = split(/\t/, $line);
   -            my $label = AI::MXNet::NDArray->array([@line[1..@line-1]]);
   +            my $label = AI::MXNet::NDArray->array([@line[1..@line-2]]);
                my $key   = $line[0];
                $imglist{$key} = [$label, $line[-1]];
                push @imgkeys, $key;
   @@ -821,6 +821,10 @@ sub BUILD
        {
            $self->aug_list(AI::MXNet::Image->CreateAugmenter(data_shape => 
$self->data_shape, %{ $self->kwargs//{} }));
        }
   +    else
   +    {
   +        $self->aug_list([]);
   +    }
        $self->cur(0);
        $self->reset();
    }
   @@ -860,7 +864,7 @@ method next_sample()
            }
            else
            {
   -            my ($label, $fname) = $self->imglist->{$idx};
   +            my ($label, $fname) = @{ $self->imglist->{$idx} };
                if(not defined $self->imgrec)
                {
                    open(F, $self->path_root . "/$fname") or confess("can't 
open $fname $!");
   
   ```
   And here is patched image.pl script with correct usage:
   ```
   #!/usr/bin/perl
   
   ## a bit modified
   ## added path_root
   ## $data is not an array but an object of class AI::MXNet::DataBatch
   use AI::MXNet qw('mx');
   use Data::Dumper;
   my $ite = mx->img()->ImageIter(
   {  batch_size => 1, data_shape=> [3,224,224],label_width =>1, path_imglist 
=> "custom.lst", path_root => '.' });
   for $data (@{$ite}){
     print Dumper($data);
     print $data->data->[0]->aspdl;
     print $data->label->[0]->aspdl;
   }
   ```
   The code assumes that you have image.pl and custom.lst in the top dir and 
the test.jpg file in the subdir 'data'.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to