是否可以通过 Pycaffe 访问求解器属性?
Is it possible to access a solver propertiese through Pycaffe?
是否可以读取和访问 Pycaffe
中的求解器属性?
我需要使用存储在求解器文件中的一些信息,但显然是使用
创建的求解器对象
import caffe
solver = caffe.get_solver(solver_path)
在这种情况下没有用。有没有其他方法可以解决这个问题?
我在使用求解器对象后找不到我是什么,最后我写了一个快速函数来解决这个问题:
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
是否可以读取和访问 Pycaffe
中的求解器属性?
我需要使用存储在求解器文件中的一些信息,但显然是使用
import caffe
solver = caffe.get_solver(solver_path)
在这种情况下没有用。有没有其他方法可以解决这个问题?
我在使用求解器对象后找不到我是什么,最后我写了一个快速函数来解决这个问题:
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