Mxnet学习系列0----问题汇总及解决方法

Mxnet学习系列0----问题汇总及解决方法

 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Sunshine_in_Moon/article/details/52936088

这是我在使用Mxnet过程遇到的一些问题,有的是我自己解决,有的是参考他人的解决方法。在这里做个总结,帮助他人少走些弯路。

1、im2rec.py中参数--exts的问题

我是使用过程中发现,如果使用默认值输出结果是正确的,如果我们在命令行中自己输入参数就无法输出结果。经过研究发现是im2rec.py源码有问题,作者在使用argparse模块是忽视了一个参数:

原始代码如下:

 
  1. cgroup.add_argument('--exts', type=list,default=['.jpeg', '.jpg'],

  2. help='list of acceptable image extensions.')

修改后的正确代码:

 
  1. cgroup.add_argument('--exts', type=list, action='append',default=['.jpeg', '.jpg'],

  2. help='list of acceptable image extensions.')

****注意此处必须加上action='append',否则参数exts无法正确使用。原因是参数exts是list类型,append代表加入即将参数加入列表

2、在Windows下使用im2rec.py将image_list转换成image.rec会报错

原因是multiprocessing不兼容,解决方法可参考:http://www.th7.cn/Program/Python/201607/912223.shtml

也可以点击打开链接下载我已经改好的im2rec_Windows.py.但是我现在强烈不建议你使用im2rec_Windows.py,因为我现在还不能百分之百保证它是正确的。别担心你可以将tools中im2rec.cc编译成im2rec.exe,使用这个肯定是正确的。

3、错误提示:Check failed: (dshape.ndim()) == (4) Input data should be 4D in batch-num_filter-y-x

我们在使用mx.io.NDArray()制作数据迭代器是需要将思维数据转换成二维,如果我们在训练完后直接使用model.predict()预测数据应该是没有错误的。但是如果你像我一样在训练网络后,使用mx.model.FreedWard.load()加载model再调用predict预测的话,此时就会提示上述错误。这个问题是此时的输入必须是个4维数据,因此应当想办法将数据转换成四维,一般使用reshape()函数。

 
  1. #评估模型

  2. model = mx.model.FeedForward.load('model/myself_mnist2',9)

  3. #plt.imshow((X_test[0].reshape((28,28))*255).astype(np.uint8),cmap='Greys_r')

  4. #plt.show()

  5. test = X_test[0:1]

  6. test_data = test.reshape(1,1,28,28)

  7. result = model.predict(test_data)

  8. result1 = result.argmax()

  9. print 'Result:',result1

可参考:https://github.com/dmlc/mxnet/issues/1281

4、mxnet\dmlc-core\src\io\local_filesys.cc:109: LocalFileSystem.ListDirectory ./data error: No such process

出现上述错误的原因很有可能是数据迭代器中的输入文件的参数名字拼写错误,或输入文件路径不存在,请仔细检查!

记录时间:2016/11/5 19:45

5、在运行cifar10-recipe notebook中提示下面错误:

“MXNetError: InferShape Error in concat2: [02:25:49] src/operator/./concat-inl.h:152: Check failed: (dshape[j]) == (tmp[j]) Incorrect shape[1]: (128,80,13,13). (first input shape: (128,160,14,14))“

原来是例程中的代码给错了,幸好在新的版本中已经更正了,我们也可以自己修改,如下:

 
  1. # A Simple Downsampling Factory

  2. def DownsampleFactory(data, ch_3x3):

  3. # conv 3x3

  4. conv = ConvFactory(data=data, kernel=(3, 3), stride=(2, 2), num_filter=ch_3x3, pad=(1, 1))

  5. # pool

  6. pool = mx.symbol.Pooling(data=data, kernel=(3, 3), stride=(2, 2), pad=(1,1),pool_type='max')

  7. # concat

  8. concat = mx.symbol.Concat(*[conv, pool])

  9. return concat

原始代码中pool中是没有pad参数的,加上pad参数就OK!

可参考:https://github.com/dmlc/mxnet/issues/3595

也可参考:https://github.com/dmlc/mxnet/pull/3599

6、在用GPU训练时如果有下面的错误提示:

“/stream_gpu-inl.h:125: Check failed: (err) == (CUDNN_STATUS_SUCCESS) CUDNN_STATUS_INTERNAL_ERROR”

这是因为我们的Gpu内存不够,可以换一个内存更大的GPU,更简单的办法是将batch_size减小就行了!

可参考:https://github.com/dmlc/mxnet/issues/2025

7、如果你遇到了一下错误提示:

“ Check failed: node == e.source.get() Symbol.GetName only works for non-grouped symbol”

你有可能和我一样误操作了

 
  1. softmax,arg_params,aux_params = mx.model.load_checkpoint('model/cifar10',1)

  2. internals = softmax.get_internals()

  3. #print internals #这里不能直接打印,因此报错

  4. #改成如下:

  5. print internals.list_outputs() #OK!

猜你喜欢

转载自blog.csdn.net/CVAIDL/article/details/88801579
今日推荐