Mxnet 训练自己的数据

Prepare the input data
Because the input data’s formt of MXNet is rec,so we must turn the image into the .rec format,as folow:

First, we prepare some face images data stored in ‘test_face’ file:

step1:build the txt or lst format from the images 
Now,we have so many images in hand.Next,we make some changes to them that generate a list or a txt about the images.As for the list or txt,its format as folllows:

 
To see explicitly,we can see an image below:

Of course, we still need the test.lst or test.txt.

step2:generate the .rec from txt or lst

Under our MXNet root diretory,we can see

so,we can build the rec doc by using ‘im2rec’.

The comman as folows:

Here,we can see three parameters.They are:

the first param: the path of your lst or txt have been build;

the second one: the path of your images;

the third one: the path of your .rec.

OK,so far we have the rec doc of train data,but we still lack the rec of test data.In that,we can generate the test.rec with the same method.Finally,you can get four files:

Good luck!

Construct the net
In this step,we can construct the net ourselves,but at first best do not.Because we can use the off-the-shelf models or net to achieve more higher use.And furthermore,it can save twists and turns at first.And it is so-called ‘standing on the shoulders of giants’.Hence,the simplest way is to make a little change on the off-th-shelf net.

As for the off-the-shelf examples,we can find under ‘mxnet/examples/image-classification/’ and ‘mxnet/tests/python/’ .

step1:New a folder named ‘MyTrainMxnet’;the folder path is freewill;

step2:Copy four files below to th new folder ‘MyTrainMxnet’;

Attention:Here we choose the ineption-bn-28-small net,of course, you can choose others,e.g alexnet..

step3:Let’s make some changes.

1.Rename the ‘symbol_inception-bn-28-small.py’ as ‘my-inception.py’;

2.Rename the ‘train_mnist.py’ as ‘train_face.py’;

3.Open ‘train_face.py’ and do some changes;

Delete the ‘symbol’,otherwise your model file must begin with ‘symbol’.

Train the model
Of course we can choose not do these changes.Instead,we can add ‘–network’ and ‘–data-dir’ in the command,as folows:

In addition, we can add other params if we need in the command above.

Attention:If you want to save the trained-well model after every epoch,please must add ‘–model-prefix’.And you will get it when making prediction afterwards.

Ok,the training step may need much time when cpu-only.So we can wait in patience.

Make a prediction
When you complete the training work,you will find:

Now,we can make a prediction using the test data.

First,we need write a prediction file named ‘predict_face.py’,its contents as follow:

Attention:Remember to change the path into yours.

Ok,hereto it’s over.

If yu want to make predition using new data,please keep attention.

Be continued!
--------------------- 
作者:eternity1118_ 
来源:CSDN 
原文:https://blog.csdn.net/eternity1118_/article/details/70860938?utm_source=copy 
版权声明:本文为博主原创文章,转载请附上博文链接!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值