是否可以读取和访问Pycaffe中的求解器属性?我需要使用解算器文件中存储的一些信息,但显然是使用创建的求解器对象
进口……
在使用求解器对象后我找不到我的样子,最后我写了一个快速函数来解决这个问题:
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