我正在尝试使用MXNet (AI::MXNet)的Perl API从ModelZoo (AI::MXNet::Gluon::ModelZoo::Vision)获取一个标准模型并对其进行训练。
下面的代码没有错误,但它不适合()。fit()立即返回。我的数据集是一个(使用im2rec构建的) RecordIO格式的图像文件,我非常确定它是有效的。
我从这里的https://codehex.hateblo.jp/entry/2017/09/12/160149修改了代码,原始作者在这里象征性地创建模型(而不是从ModelZoo)。
原则上,这是从ModelZoo训练模型的正确方式吗?
第二个问题是从一组图像创建数据加载器的最佳实践是什么。我正在做的事情(使用mx->io->ImageRecordIter)可以吗?
use strict;
use warnings;
use AI::MXNet qw/mx/;
use AI::MXNet::Gluon qw/gluon/; # needed for nn-> (which must be replaced by gluon->nn->...)
use AI::MXNet::Gluon::NN qw(nn); # for nn->
use AI::MXNet::Gluon::ModelZoo::Vision::VGG;
use AI::MXNet::Monitor;
my $ctx = mx->cpu(0);
my $vgg = AI::MXNet::Gluon::ModelZoo::Vision->get_vgg(
11, # num layers
(
'classes' => 26, # latin alphabet recognition
'root' => 'abc', # where to save the models
'ctx' => $ctx # context
)
);
die "get the model" unless defined $vgg;
my $batch_size = 4;
# num channels, width, height our png training images of letters:
my $img_shape = [3, 256, 256];
my $training_file = 'training.bin';
my $train_dataiter = mx->io->ImageRecordIter({
'path_imgrec' => $training_file,
'path_imglist' => 'training.lst',
# num channels, width, height
'data_shape' => $img_shape,
'batch_size' => $batch_size,
'label_width' => 1, # dimensionality of labels, for us is 1 (i.e. just the letter name)
});
die "mx->io->ImageRecordIter()" unless defined $train_dataiter;
$vgg->init_params(initializer => mx->init->Xavier(magnitude => 2));
$vgg->init_optimizer(optimizer => 'sgd', optimizer_params => {learning_rate => 0.1});
$vgg->initialize();
print "$0 : fitting ...\n";
$vgg->fit(
$train_dataiter,
'num_epoch' => 1000
);发布于 2020-02-10 09:42:47
现在不是训练的好时机。ModelZoo返回一个胶子混合块。在Module接口中使用'fit‘。看看如何使用胶水进行训练:
https://metacpan.org/source/SKOLYCHEV/AI-MXNet-1.4/examples/gluon/mnist.pl
与模块相同:https://metacpan.org/source/SKOLYCHEV/AI-MXNet-1.4/examples/mnist.pl
您可以像$vgg-> ->export ();https://metacpan.org/source/SKOLYCHEV/AI-MXNet-1.4/lib/AI/MXNet/Gluon/Block.pm#L1242一样调用混合块的导出方法
这将把网络的json结构和当前参数保存到一个文件中。然后,您可以从这些接口初始化Module接口。
https://stackoverflow.com/questions/59458361
复制相似问题