TensorFlow如何用常量替換變量

2018-10-17 17:46 更新

tf.graph_util.convert_variables_to_constants

convert_variables_to_constants (  
    sess ,  
    input_graph_def ,  
    output_node_names ,  
    variable_names_whitelist = None ,  
    variable_names_blacklist = None
  )

定義在:tensorflow/python/framework/graph_util_impl.py

用相同值的常量替換圖中的所有變量.

如果您有一個(gè)包含變量(Variable)操作的訓(xùn)練有素的圖表,那么可以將它們?nèi)哭D(zhuǎn)換為具有相同值的 CONST 操作.這樣可以用一個(gè) GraphDef 文件完全描述網(wǎng)絡(luò),并允許刪除許多與加載和保存變量相關(guān)的操作.

參數(shù):

  • sess:包含變量的 Active TensorFlow 會(huì)話.
  • input_graph_def:具有網(wǎng)絡(luò)的 GraphDef 對(duì)象.
  • output_node_names:圖表結(jié)果節(jié)點(diǎn)的名稱字符串列表.
  • variable_names_whitelist:要轉(zhuǎn)換的變量名稱集合(默認(rèn)情況下,所有變量都將被轉(zhuǎn)換).
  • variable_names_blacklist:要省略轉(zhuǎn)換為常量的變量名的集合.

返回值:

GraphDef 包含原版的一個(gè)簡化的版本.

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)