老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業提供網站建設、域名注冊、服務器等服務

keras模型如何保存為tensorflow的二進制模型-創新互聯

這篇文章主要講解了keras模型如何保存為tensorflow的二進制模型,內容清晰明了,對此有興趣的小伙伴可以學習一下,相信大家閱讀完之后會有幫助。

成都創新互聯是一家專業提供澄海企業網站建設,專注與成都網站設計、成都網站建設H5響應式網站、小程序制作等業務。10年已為澄海眾多企業、政府機構等服務。創新互聯專業網絡公司優惠進行中。

最近需要將使用keras訓練的模型移植到手機上使用, 因此需要轉換到tensorflow的二進制模型。

折騰一下午,終于找到一個合適的方法,廢話不多說,直接上代碼:

# coding=utf-8
import sys

from keras.models import load_model
import tensorflow as tf
import os
import os.path as osp
from keras import backend as K

def freeze_session(session, keep_var_names=None, output_names=None, clear_devices=True):
 """
 Freezes the state of a session into a prunned computation graph.

 Creates a new computation graph where variable nodes are replaced by
 constants taking their current value in the session. The new graph will be
 prunned so subgraphs that are not neccesary to compute the requested
 outputs are removed.
 @param session The TensorFlow session to be frozen.
 @param keep_var_names A list of variable names that should not be frozen,
       or None to freeze all the variables in the graph.
 @param output_names Names of the relevant graph outputs.
 @param clear_devices Remove the device directives from the graph for better portability.
 @return The frozen graph definition.
 """
 from tensorflow.python.framework.graph_util import convert_variables_to_constants
 graph = session.graph
 with graph.as_default():
  freeze_var_names = list(set(v.op.name for v in tf.global_variables()).difference(keep_var_names or []))
  output_names = output_names or []
  output_names += [v.op.name for v in tf.global_variables()]
  input_graph_def = graph.as_graph_def()
  if clear_devices:
   for node in input_graph_def.node:
    node.device = ""
  frozen_graph = convert_variables_to_constants(session, input_graph_def,
              output_names, freeze_var_names)
  return frozen_graph

input_fld = sys.path[0]
weight_file = 'your_model.h6'
output_graph_name = 'tensor_model.pb'

output_fld = input_fld + '/tensorflow_model/'
if not os.path.isdir(output_fld):
 os.mkdir(output_fld)
weight_file_path = osp.join(input_fld, weight_file)

K.set_learning_phase(0)
net_model = load_model(weight_file_path)

print('input is :', net_model.input.name)
print ('output is:', net_model.output.name)

sess = K.get_session()

frozen_graph = freeze_session(K.get_session(), output_names=[net_model.output.op.name])

from tensorflow.python.framework import graph_io

graph_io.write_graph(frozen_graph, output_fld, output_graph_name, as_text=False)

print('saved the constant graph (ready for inference) at: ', osp.join(output_fld, output_graph_name))

另外有需要云服務器可以了解下創新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。


分享文章:keras模型如何保存為tensorflow的二進制模型-創新互聯
文章路徑:http://www.xueling.net.cn/article/ccidjp.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 精品麻豆国产色欲色欲色欲WWW | 国产成人无码A区视频 | 国产亚洲欧美日韩精品一区二区三区 | 久久无码中文字幕无码 | 精品国产一区二区三区高潮视 | 免费av网址在线观看 | 夜夜爽爽爽久久久久久魔女 | 小粉嫩直流白浆 | 无码人妻AⅤ一区二区三区麻豆 | 中文字幕四虎 | 亚洲精品区无码欧美日韩 | www一区二区三区 | 人妻精品久久无码专区精东影业 | 91精品国| 亚洲最新免费视频 | 亚洲不卡一卡2卡三卡4卡5卡 | 国产又爽又刺激的视频 | 色妞www精品视频观看软件 | 秋霞一级鲁丝片免费观看 | 国产亚洲色婷婷久久99精品 | 精品成人免费视频 | 亚洲精品国产高清一线久久 | 在线不卡123| 久久精品国语对话 | 91情趣视频 | 亚洲一区中文日韩 | 一区二区三区激情视频 | 女的被弄到高潮娇喘喷水视频 | 亚洲男人的天堂视频 | 亚州AⅤ中文Aⅴ无码Aⅴ | 久草av在线播放 | 91九色丨porny丨丝袜 | 免费看日韩视频 | 91影视在线?看 | 加勒比色老久久爱综合网 | 亚洲成人网在线播放 | 激情超碰 | 欧美国产激情一区二区三区蜜月 | 第84页国产精品 | 亚洲国产一区二区波多野结衣 | 日本公妇被公侵犯中文字幕2 |