Neural network 通过pycaffe更改Caffe中的解算器参数

Neural network 通过pycaffe更改Caffe中的解算器参数,neural-network,deep-learning,caffe,Neural Network,Deep Learning,Caffe,如何通过pycaffe更改Caffe中的解算器参数 例如,在调用solver=caffe.get\u solver(solver\u prototxt\u filename)之后,我想更改解算器的参数(学习速率、步长、伽马、动量、基本lr、功率等),而不必更改solver\u prototxt\u filename也许您可以创建一个临时文件 首先,使用加载解算器参数 from caffe.proto import caffe_pb2 from google.protobuf import tex

如何通过pycaffe更改Caffe中的解算器参数


例如,在调用
solver=caffe.get\u solver(solver\u prototxt\u filename)
之后,我想更改解算器的参数(学习速率、步长、伽马、动量、基本lr、功率等),而不必更改
solver\u prototxt\u 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\u config
中设置所需的值(例如
solver\u config.test\u 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\u config
中的stepvalue?当我尝试分配
solver\u config.stepvalue=1000
时,我得到了AttributeError:Assignment不允许分配到协议消息对象中的重复字段“stepvalue”。@TuBui,因为您没有使用“多步”策略。