通过pycaffe更改Caffe中的求解器参数 [英] Changing the solver parameters in Caffe through pycaffe

查看:61
本文介绍了通过pycaffe更改Caffe中的求解器参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I change the solver parameter in Caffe through pycaffe?

例如在调用solver = caffe.get_solver(solver_prototxt_filename)之后,我想更改求解器的参数(学习率,步长,伽玛,动量,base_lr,幂等),而不必更改solver_prototxt_filename.

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)

您可以修改任何求解器参数,只需在solver_config中设置所需的值即可(例如solver_config.test_interval = 15).然后,它只是创建一个临时文件并从中加载您的求解器:

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)

这篇关于通过pycaffe更改Caffe中的求解器参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆