第一次见到它,我特别害怕,
很大一个文件,还是二进制的,是什么意思呢?该文件是深度学习模型训练完成之后由模型的输出数据保存的结果数据;
在线JSON编译器
JSON Editor Online
把文件传上去!
发现是一个大大的dictinary
,
回忆起,在代码里保存的时候,使用的是长这样的语句:
final_logs = logger.get_logs()
print('\nSaving session data to {}/logs.json'.format(P['save_path']))
with open(os.path.join(P['save_path'], 'logs.json'), 'w') as f:
json.dump(final_logs, f)
其中logger
类如下所示(其他函数未展示)
class train_logger:
'''
An instance of this class keeps track of various metrics throughout
the training process.
'''
def __init__(self, params):
self.params = params
# epoch-level objects:
self.best_stop_metric = -np.Inf
self.best_epoch = -1
self.running_loss = 0.0
self.num_examples = 0
# batch-level objects:
self.temp_preds = []
self.temp_true = [] # true labels
self.temp_obs = [] # observed labels
self.temp_indices = [] # indices for each example
self.temp_batch_loss = []
self.temp_batch_reg = []
# output objects:
self.logs = {}
self.logs['metrics'] = {}
self.logs['best_preds'] = {}
self.logs['gt'] ={}
self.logs['obs'] = {}
self.logs['targ'] = {}
self.logs['idx'] = {}
for field in self.logs:
for phase in ['train', 'val', 'test']:
self.logs[field][phase] = {}
再不敏感,也在铺天盖地里的中括号[]
看出来了,使用的是dictionary
类型的变量,最后保存在logs.json
文件中;
怎么使用呢?
可以试着读取logs.json
,通过用log['key1']['key2']
的方式读取其中的值,打印出来看看,这下就觉得不过如此,原来那么大的json文件,细想来就是一个字典而已;