最近要用caffe训练siamese network,但是对c++并不熟,所有用了某博主的代码,和自己的图片数据,来训练siamese网络.
caffe中的siamese network用于train Mnist dataset,步骤如下:
1.准备数据
将图片分为train.txt, val.txt, test.txt, 通过编译caffe/tools/convert_imageset.cpp将图片转为leveldb格式.
编译:cd caffe/build; make clean; make all -j8
生成: caffe/build/tools/convert_imageset
执行: ./examples/mydata/create_mnist.sh;
生成: train和test set的leveldb格式, 分别是/examples/mydata/mnist_siamese_train_leveldb和/examples/mydata/mnist_siamese_test_leveldb
2.定义general model
/examples/mydata/mnist_siamese.prototxt中定义了siamese net的网络结构;与LeNet model相同,除了top layer.
3.定义detailed siamese network
/examples/mydata/mnist_siamese_train_test.prototxt.
注意修改source path.
3.1读pair data
3.2构建siamese net的first side数据和second side数据
/examples/mydata/mnist_siamese_train_test.prototxt.
3.3添加contrastive loss层
4.定