转自:https://blog.csdn.net/hong__fang/article/details/78530390
根据ENet说明https://github.com/TimoSaemann/ENet/tree/master/Tutorial ,进行训练遇到以下问题
1 No module named spatial_dropout
新增加的Python层如果用caffe-root/caffe train -solver solver.prototxt方式可能会出现找不到新添加的Python层,此时需要将新添加的Python层文件的路径添加到环境变量中,通过终端python后输入import **.py看是否添加,然后通过Python接口来训练,如下:
ENet通过python接口定义了新层spatial_dropout,根据说明直接在终端启动训练,出现“No module named spatial_dropout”,原因是caffe,python层所在文件夹路径,没有添加到系统PYTHONPATH,一个解决方法是:用Python接口来启动训练:
- import sys
- caffe_root = 'home/f/caffe/'
- sys.path.insert(0,caffe_root+'python')
- import caffe
- caffe.set_device(0)
- caffe.set_mode_gpu()
- solver = caffe.SGDSolver('/home/xxx/data/solver.prototxt')
- solver.solve()
若采用微调的方式进行训练则如下,参考https://blog.csdn.net/lilai619/article/details/54343395
- import sys
- caffe_root = 'home/f/caffe/'
- sys.path.insert(0,caffe_root+'python')
- import caffe
- caffe.set_device(0)
- caffe.set_mode_gpu()
- solver = caffe.SGDSolver('/home/xxx/data/solver.prototxt')
- solver.net.copy_from('models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel')
- # We run the solver for niter times, and record the training loss.
- for it in range(niter):
- solver.step(1) # SGD by Caffe
data层的new_height new_weight不能删掉,根据输入图像设定大小即可。
- layer {
- name: "data"
- type: "DenseImageData"
- top: "data"
- top: "label"
- dense_image_data_param {
- source: "ENet/dataset/train_fine_2columns.txt"
- batch_size: 4
- shuffle: true
- new_height: 512
- new_width: 1024
- label_divide_factor: 8
- }
- }