【问题标题】:Is it possible to access a solver propertiese through Pycaffe?是否可以通过 Pycaffe 访问求解器属性?
【发布时间】:2018-03-29 15:50:21
【问题描述】:

是否可以读取和访问Pycaffe 中的求解器属性?
我需要使用存储在求解器文件中的一些信息,但显然是使用

创建的求解器对象
import caffe  
solver = caffe.get_solver(solver_path)

在这种情况下没有用。有没有其他方法可以解决这个问题?

【问题讨论】:

  • 需要访问哪些参数?
  • @基本上,我想尽可能地自动化。我的意思是,如果一个训练循环需要知道 batch_size、test_iter、max_iter 等,它们都会以编程方式获取。目前有些可以从求解器对象本身访问,但几乎所有其他都不能。我需要这些信息用于日志记录和培训/测试目的。

标签: caffe pycaffe


【解决方案1】:

在使用求解器对象后我找不到我的内容,我最终编写了一个快速函数来解决这个问题:

def retrieve_field(solver_path, field=None):
    '''
    Returns a specific solver parameter value using the specified field  
    or the whole content of the solver file, when no field is provided.

    returns: 
    a string, as a field value or the whole content as list
    '''
    lines = []
    field_segments = []
    with open(solver_path, 'r') as file:
        for line in file: 
            line = line.strip()
            lines.append(line)
            field_segments = line.split(':')
            if (field_segments[0] == field):
                #if that line contains # marks (for comments)
                if('#' in field_segments[-1]):
                    idx = field_segments[-1].index('#')
                    return field_segments[-1][0:idx]
                else:
                    return field_segments[-1]

    return lines

【讨论】:

  • 我认为这不是解决此任务的好方法。您应该使用 caffe_pb2.py 来解析求解器。
  • @Shai,我不知道其他方法,那是什么?你能再解释一下吗?
  • @Shai:非常感谢,我会调查一下 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-11
  • 2011-08-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多