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
.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With