【问题标题】:Changing the solver parameters in Caffe through pycaffe通过 pycaffe 更改 Caffe 中的求解器参数
【发布时间】:2015-09-03 02:54:55
【问题描述】:

如何通过pycaffe更改Caffe中的solver参数?

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

【问题讨论】:

    标签: neural-network deep-learning caffe


    【解决方案1】:

    也许你可以创建一个临时文件。

    首先,加载你的求解器参数

    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)
    

    【讨论】:

    • 如何修改重复的参数,例如stepvaluesolver_config 然后呢?当我尝试分配 solver_config.stepvalue = 1000 时,我得到 AttributeError: Assignment not allowed to repeat field "stepvalue" in protocol message object。
    • @TuBui 因为你没有使用“多步骤”政策。
    猜你喜欢
    • 1970-01-01
    • 2017-03-18
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多