如何通过pycaffe更改Caffe中的求解器参数?
E.g。在调用solver = caffe.get_solver(solver_prototxt_filename)
之后我想改变求解器的参数(学习率,步长,伽玛,动量,base_lr,幂等),而不必改变solver_prototxt_filename
。
答案 0 :(得分:4)
也许你可以创建一个临时文件。
首先,使用
加载求解器参数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)
您可以修改任何解算器参数,只需在solver_config
中设置所需的值(例如solver_config.test_interval = 15
)。然后,它只是创建一个临时文件并从中加载你的求解器:
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)