我如何通过pycaffe更改Caffe中的求解器参数?
例如,在调用solver = caffe.get_solver(solver_prototxt_filename)
之后,我想更改求解器的参数(学习率、步长、gamma、动量、base_lr、power等),而不必更改solver_prototxt_filename
。
我如何通过pycaffe更改Caffe中的求解器参数?
例如,在调用solver = caffe.get_solver(solver_prototxt_filename)
之后,我想更改求解器的参数(学习率、步长、gamma、动量、base_lr、power等),而不必更改solver_prototxt_filename
。
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)
solver_config
中重复的参数,例如_stepvalue_
?当我尝试赋值solver_config.stepvalue = 1000
时,会出现**AttributeError: Assignment not allowed to repeated field "stepvalue" in protocol message object.**的错误提示。 - Tu Bui