sergeykolychev commented on issue #7511: Perl MNIST using record file format. 
Test not passed.
URL: 
https://github.com/apache/incubator-mxnet/issues/7511#issuecomment-323171563
 
 
   @dokechin 
   Found your problem
   1) you used batch size 1 which is not recommended (for mnist 100 works well)
   2) you must shuffle your data otherwise the network will see 5000 '9' number 
as last ones in the training and will forget all other digits
   3) it's best to use 'adam' optimizer than the default 'sgd' because with it 
the network converges much faster
   4) if you want to use your own original optimizer parameters and the default 
'sgd' then increase number of epochs to say 4, 2 is not enough to get to 80% 
accuracy on the training set
   5) The ImageRecordIter needs a chunk of memory to shuffle your data, 
unfortunately if this memory size is insufficient some of the data will be 
returned unshuffled and this will prevent the network from converging
   I put this number as 1000 (Mb) and it seems to be enough.
   here is the patch to your perl script that passes the test:
   ```
   developer@devbox:~/mnist_png$ git diff
   diff --git a/image.pl b/image.pl
   index f2549d2..c95eee6 100644
   --- a/image.pl
   +++ b/image.pl
   @@ -5,11 +5,11 @@ use Data::Dumper;
    use Test::More tests => 1;
    
     my $testing_ite = mx->io->ImageRecordIter(
   - {  batch_size => 1, data_shape=> [1,28,28],label_width =>1, path_imgrec => 
"testing.rec", path_root => '.' });
   + {  batch_size => 100, data_shape=> [1,28,28],label_width =>1, path_imgrec 
=> "testing.rec", path_root => '.' });
    
    
     my $training_ite = mx->io->ImageRecordIter(
   - {  batch_size => 1, data_shape=> [1,28,28],label_width =>1, path_imgrec => 
"training.rec", path_root => '.' });
   + {  batch_size => 100, data_shape=> [1,28,28],label_width =>1, path_imgrec 
=> "training.rec", path_root => '.', shuffle => 1, shuffle_chunk_size => 1000 
});
    
    
    # for my $data (@{$training_ite}){
   @@ -44,7 +44,7 @@ my $model = mx->mod->Module(
    $model->fit(
       $training_ite,
       eval_data => $testing_ite,
   -   optimizer_params=>{learning_rate=>0.01, momentum=> 0.9},
   +   optimizer => 'adam',
       num_epoch=>2
    );
    my $res = $model->score($testing_ite, mx->metric->create('acc'));
   ```
 
----------------------------------------------------------------
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