1. 直接使用train.sh启动训练过程,其实也是可以的
#!/usr/bin/env sh
set -e
./build/tools/caffe train --solver=/***/adam_solver.prototxt --gpu=1,2,3
一般会报错:ImportError: No module named python.NormlizedMSE
可能会报错,解决方案
https://blog.csdn.net/bingqingsuimeng/article/details/79907967
2. 解决方案,使用python脚本启动训练过程:
- 将自定义的python层放到caffe_root/python下
- 重新编译pycaffe: make pycaffe
3. 具体操作:
solver.py
import sys
sys.path.append('~/work/caffe_master/python') # for import caffe
sys.path.append('~/work/Myproject/train/') # for python layer, 这里指明python的呼叫路径
import caffe
caffe.set_device(1)
caffe.set_mode_gpu()
solver=caffe.SGDSolver('~/work/Myproject/adam_solver.prototxt')
solver.solve()
prototxt
layer {
type: 'Python'
name: 'loss'
top: 'loss'
bottom: 'Dense3'
bottom: 'landmarks'
python_param {
# 自定义层的名字,注意,这里一定是和上面solver中的路径相配合的
module: 'NormlizedMSE'
# the layer name -- the class name in the module
layer: 'NormlizedMSE'
}
# set loss weight so Caffe knows this is a loss layer.
# since PythonLayer inherits directly from Layer, this isn't automatically
# known to Caffe
loss_weight: 1
}
这里是重点:
NormlizedMSE.py 在路径’~/work/Myproject/train/'下,也就是用于训练的python脚本中呼叫的路径。