ShuffleNet在Caffe框架下的实现

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

本文是在实现Github上用户farmingyard贴出的加速版ShuffleNet。下面是所包含的文件:

这里写图片描述

作为一个深度学习方面的小白,刚开始真的是一头雾水,在之前的Caffe框架使用中,只是单纯的会把别人的deploy.prototxt,train.prototxt,solver.prototxt拿来用,制作数据集跑一跑,稍微有一点变化,例如有的网络github上只给一个deploy.prototxt文件,或者是像这样还给出 .cpp .cu .hpp文件README.md又是这样的:

这里写图片描述
在写出其他两个文件以后直接巡行会出现以下问题:

I1017 22:40:08.742588  8634 solver.cpp:87] Creating training net from net file: /home/t702/zrx/ShuffleNet/train_val.prototxt
[libprotobuf ERROR google/protobuf/text_format.cc:245] Error parsing text-format caffe.NetParameter: 347:25: Message type "caffe.LayerParameter" has no field named "shuffle_channel_param".
F1017 22:40:08.742987  8634 upgrade_proto.cpp:88] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: /home/t702/zrx/ShuffleNet/train_val.prototxt
*** Check failure stack trace: ***
    @     0x7f3407747daa  (unknown)
    @     0x7f3407747ce4  (unknown)
    @     0x7f34077476e6  (unknown)
    @     0x7f340774a687  (unknown)
    @     0x7f3407e7608e  caffe::ReadNetParamsFromTextFileOrDie()
    @     0x7f3407e47dcc  caffe::Solver<>::InitTrainNet()
    @     0x7f3407e48c83  caffe::Solver<>::Init()
    @     0x7f3407e48f5f  caffe::Solver<>::Solver()
    @     0x7f3407ea5e91  caffe::Creator_SGDSolver<>()
    @           0x40ee6e  caffe::SolverRegistry<>::CreateSolver()
    @           0x407efd  train()
    @           0x40590c  main
    @     0x7f3406753f45  (unknown)
    @           0x40617b  (unknown)
    @              (nil)  (unknown)

下面主要就是针对这一问题进行解决。

1.相关文件的使用问题

如果只给出了一个deploy.prototxt文件,另外两个.prototxt配置文件都是需要我们使用者根据自己的情况和所给出的deploy.prototxt自己写的,询问过一个给出Caffe框架模型的原作者,大神说这是Caffe框架最基本的东西了。T T

然后像这样给出

shuffle_channel_layer.cpp 
shuffle_channel_layer.cu 
shuffle_channel_layer.hpp

三个文件的,基本都是网络结构中自己定义的layer,是Caffe框架本身没有的,需要我们添加到Caffe框架下。
以ShuffleNet为例,具体使用步骤是将:

shuffle_channel_layer.cpp 
shuffle_channel_layer.cu 

放进caffe/src/caffe/layers路径下,而

shuffle_channel_layer.hpp

放进caffe/include/caffe/layers路径下。 然后类似于函数的声明一样,我们需要在caffe/src/caffe/proto/caffe.proto文件中找到message LayerParameter{…}这条语句
并在其中添加语句:

message LayerParameter {
...
optional ShuffleChannelParameter shuffle_channel_param = 164;
...
}
...
message ShuffleChannelParameter {
  optional uint32 group = 1[default = 1]; // The number of group
}

做完上述步骤后,在caffe需要重新编译,也很简单,直接在caffe文件夹下打开命令行:

make all -j4

在运行caffe训练时就可以使用 type: ShuffleChannel1 的layer了。

2.开始训练

然后就是准备好数据集,根据deploy.prototxt文件编写好train.prototxt和solver.prototxt 就可以开始训练了!

Ps:

github还有一个版本的ShuffleNet中直接使用会出现如下报错:

I1017 22:42:00.554802  8701 solver.cpp:87] Creating training net from net file: /home/t702/zrx/ShuffleNet/train.prototxt
[libprotobuf ERROR google/protobuf/text_format.cc:245] Error parsing text-format caffe.NetParameter: 145:17: Message type "caffe.LayerParameter" has no field named "permute_param".
F1017 22:42:00.555064  8701 upgrade_proto.cpp:88] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: /home/t702/zrx/ShuffleNet/train.prototxt
*** Check failure stack trace: ***
    @     0x7f4ef019cdaa  (unknown)
    @     0x7f4ef019cce4  (unknown)
    @     0x7f4ef019c6e6  (unknown)
    @     0x7f4ef019f687  (unknown)
    @     0x7f4ef08cb08e  caffe::ReadNetParamsFromTextFileOrDie()
    @     0x7f4ef089cdcc  caffe::Solver<>::InitTrainNet()
    @     0x7f4ef089dc83  caffe::Solver<>::Init()
    @     0x7f4ef089df5f  caffe::Solver<>::Solver()
    @     0x7f4ef08fae91  caffe::Creator_SGDSolver<>()
    @           0x40ee6e  caffe::SolverRegistry<>::CreateSolver()
    @           0x407efd  train()
    @           0x40590c  main
    @     0x7f4eef1a8f45  (unknown)
    @           0x40617b  (unknown)
    @              (nil)  (unknown)

具体解决方法同上!

猜你喜欢

转载自blog.csdn.net/Chris_zhangrx/article/details/78277957
今日推荐