Fra*_*urt 6 neural-network deep-learning caffe
如何通过pycaffe更改Caffe中的求解器参数?
例如,在调用之后solver = caffe.get_solver(solver_prototxt_filename)我想改变求解器的参数(学习速率,步长,伽玛,动量,base_lr,功率等),而不必改变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)
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2664 次 |
| 最近记录: |