Changing the input data layer during training in Caffe

让人想犯罪 __ 提交于 2019-12-06 13:50:05
Anoop K. Prabhu

Your problem could be solved with the help of Python layers, as suggested in comments. An example of the usage of python layer can be found within caffe here.

Within the python script you could write the code to shuffle both the data by preserving their alignments.

I want to provide an answer without python interface, I did it in C++ source code.

Intel/caffe is used as example because currently I am working on it, but you can easily try with blvc/caffe. I assume you can compile caffe source code.

Here is one proper place to change in the source code(right after loading the train_text.prototxt):

    https://github.com/intel/caffe/blob/master/src/caffe/solver.cpp#L156

inside the block, add following:

    net_param.mutable_layer(0)->mutable_data_param()->set_source("/test/data/path/");
    net_param.mutable_layer(1)->mutable_data_param()->set_source("/test/data/path/");
    LOG(INFO) << "+++> " << net_param.layer(0).data_param().source();
    LOG(INFO) << "+++> " << net_param.layer(1).data_param().source();

You will change the data source of first two layers(train data layer and test data layer).

So if you want to change the data source in other scenarios, just find the context of net_param, layer and data_param, then you can use above function calls to change your own data path.

Actually as caffe uses google protobuffer, so if you want to understand the full interfaces of net_param, layer and data_param, you need to build caffe, then check file: .build_release/src/caffe/proto/caffe.pb.h(I used Makefile to build, not cmake). I don't really understand protobuffer, if you know it, you can check source code: src/caffe/proto/caffe.proto.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!