将tensorflow的ckpt模型存储为npy的实例-创新互联
实例如下所示:
创新互联公司-专业网站定制、快速模板网站建设、高性价比江津网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式江津网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖江津地区。费用合理售后完善,10多年实体公司更值得信赖。#coding=gbk import numpy as np import tensorflow as tf from tensorflow.python import pywrap_tensorflow checkpoint_path='model.ckpt-5000'#your ckpt path reader=pywrap_tensorflow.NewCheckpointReader(checkpoint_path) var_to_shape_map=reader.get_variable_to_shape_map() alexnet={} alexnet_layer = ['conv1','conv2','conv3','conv4','conv5','fc6','fc7','fc8'] add_info = ['weights','biases'] alexnet={'conv1':[[],[]],'conv2':[[],[]],'conv3':[[],[]],'conv4':[[],[]],'conv5':[[],[]],'fc6':[[],[]],'fc7':[[],[]],'fc8':[[],[]]} for key in var_to_shape_map: #print ("tensor_name",key) str_name = key # 因为模型使用Adam算法优化的,在生成的ckpt中,有Adam后缀的tensor if str_name.find('Adam') > -1: continue print('tensor_name:' , str_name) if str_name.find('/') > -1: names = str_name.split('/') # first layer name and weight, bias layer_name = names[0] layer_add_info = names[1] else: layer_name = str_name layer_add_info = None if layer_add_info == 'weights': alexnet[layer_name][0]=reader.get_tensor(key) elif layer_add_info == 'biases': alexnet[layer_name][1] = reader.get_tensor(key) else: alexnet[layer_name] = reader.get_tensor(key) # save npy np.save('alexnet_pointing04.npy',alexnet) print('save npy over...') #print(alexnet['conv1'][0].shape) #print(alexnet['conv1'][1].shape)
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
当前题目:将tensorflow的ckpt模型存储为npy的实例-创新互联
标题链接:http://myzitong.com/article/piops.html