reader=pywrap_tensorflow.NewCheckpointReader(FILE_PATH)
var_to_shape_map=reader.get_variable_to_shape_map()
for key in var_to_shape_map:
print(key)
layers = ['conv1_1', 'conv1_2', 'conv2_1', 'conv2_2','conv3_1', 'conv3_2','conv3_3', 'conv4_1', 'conv4_2','conv4_3','conv5_1','conv5_2', 'conv5_3', 'fc6', 'fc7', 'cls_score','bbox_pred','rpn_cls_score','rpn_bbox_pred']
data = {
'conv1_1': [],
'conv1_2': [],
'conv2_1': [],
'conv2_2': [],
'conv3_1': [],
'conv3_2': [],
'conv3_3': [],
'conv4_1': [],
'conv4_2': [],
'conv4_3': [],
'conv5_1': [],
'conv5_2': [],
'conv5_3': [],
'fc6': [],
'fc7': [],
'cls_score_na': [],
'bbox_pred_na':[],
'rpn_cls_score_na': [],
'rpn_bbox_pred_na':[]
}
for op_name in layers:
biases_variable = reader.get_tensor(op_name+'/biases')
weights_variable = reader.get_tensor(op_name+'/weights')
tmp={'biases':biases_variable,'weights':weights_variable}
data[op_name] = tmp
np.save(OUTPUT_FILE, data)
tensorflow 将ckpt中的参数存储为 npy 格式。
最新推荐文章于 2022-12-27 00:10:00 发布