Changing the solver parameters in Caffe through pycaffe

隐身守侯 提交于 2019-12-07 03:22:30

问题


How can I change the solver parameter in Caffe through pycaffe?

E.g. right after calling solver = caffe.get_solver(solver_prototxt_filename) I would like to change the solver's parameters (learning rate, stepsize, gamma, momentum, base_lr, power, etc.), without having to change solver_prototxt_filename.


回答1:


Maybe you can create a temporary file.

First of all, load your solver parameters with

from caffe.proto import caffe_pb2
from google.protobuf import text_format
solver_config = caffe_pb2.SolverParameter()
with open('/your/solver/path') as f:
    text_format.Merge(str(f.read()), solver_config)

You can modify any solver parameter just setting the desired value in solver_config (e.g. solver_config.test_interval = 15). Then, it's just creating a temp file and load your solver from it:

new_solver_config = text_format.MessageToString(solver_config)
with open('temp.prototxt', 'w') as f:
    f.write(new_solver_config) 
solver = caffe.get_solver('temp.prototxt')
solver.step(1)


来源:https://stackoverflow.com/questions/31823898/changing-the-solver-parameters-in-caffe-through-pycaffe

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