1. 程式人生 > >tensorflow學習筆記-從checkpoint中獲取graph資訊

tensorflow學習筆記-從checkpoint中獲取graph資訊

    程式碼:
import tensorflow as tf

sess = tf.Session()
check_point_path = 'variables' 
saver = tf.train.import_meta_graph('variables/save_variables.ckpt.meta')

saver.restore(sess, tf.train.latest_checkpoint(check_point_path))

graph = tf.get_default_graph()

#print(graph.get_operations())

#with open('op.txt','a') as f:
#    f.write(str(graph.get_operations()))
op1 = graph.get_tensor_by_name('fully_connected/biases:0')
print(op1)

    使用函式graph.get_operations()獲取ckpt.meta中儲存的graph中的所有operation,而tensor_name為'op_name:0'。

然後使用graph.get_tensor_by_name('op_name:0') 獲取tensor資訊。

     程式碼從ckpt檔案中獲取儲存的variable的資料(tensor的name和value):

import os
import tensorflow as tf
from tensorflow.python import pywrap_tensorflow
check_point_path = 'variables'
#checkpoint_path = os.path.join(logs_train_dir, 'model.ckpt')
ckpt = tf.train.get_checkpoint_state(checkpoint_dir=check_point_path)
checkpoint_path = os.path.join('.', ckpt.model_checkpoint_path)
#print(ckpt.model_checkpoint_path)
reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path)
var_to_shape_map = reader.get_variable_to_shape_map()
for key in var_to_shape_map:
    print("tensor_name: ", key)
    #print(reader.get_tensor(key))

法二:

from tensorflow.python.tools.inspect_checkpoint import print_tensors_in_checkpoint_file

print_tensors_in_checkpoint_file("variables/save_variables.ckpt",tensor_name='', all_tensors=False, all_tensor_names=False)

注意:tf.train.latest_checkpoint(check_point_path) 方法用來獲取最後一次ckeckpoint的路徑,等價於

ckpt = tf.train.get_checkpoint_state(check_point_path)
ckpt.model_checkpoint_path
不能將tf.train.latest_checkpoint與tf.train.get_checkpoint_state 搞混了

參考部落格

相關推薦

tensorflow學習筆記-checkpoint獲取graph資訊

    程式碼:import tensorflow as tf sess = tf.Session() check_point_path = 'variables' saver = tf.train.import_meta_graph('variables/save_va

struts2學習筆記(二)—— 獲取登入資訊及計算線上人數

package com.lewa.action; import java.util.Map; import org.apache.struts2.dispatcher.SessionMap; import org.apache.struts2.interceptor.ApplicationAware; i

cookie獲取使用者資訊並新增到session

package com.sale.controller; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import javax.servlet.http.Cookie;

freemarker的DatabaseTemplateLoader資料庫獲取模板資訊

import com.kingnet.xyzs.orm.dao.DmsMdTemplateConfigMapper; import com.kingnet.xyzs.orm.entity.DmsMdTemplateConfig; import freemarker.cach

斯坦福CS20SI TensorFlow學習筆記1——graph、session和op

efault constant 例如 sub 否則 我們 vector 安全 出現 graph即tf.Graph(),session即tf.Session(),很多人經常將兩者混淆,其實二者完全不是同一個東西。 graph定義了計算方式,是一些加減乘除等運算的組合,類似於

tensorflow學習筆記--深度學習的epochs,batch_size,iterations詳解

深度學習框架中涉及很多引數,如果一些基本的引數如果不瞭解,那麼你去看任何一個深度學習框架是都會覺得很困難,下面介紹幾個新手常問的幾個引數。batch深度學習的優化演算法,說白了就是梯度下降。每次的引數更新有兩種方式。第一種,遍歷全部資料集算一次損失函式,然後算函式對各個引數的

筆記】Android開發EditText獲取數字

xml檔案中 <EditText android:id="@+id/editText_age" android:layout_width="match_p

Unity3D學習筆記(4)——獲取單幀函式耗時

Unity3D學習筆記(4) 參考連結1 參考連結2 CheckFunctionTimeInSingleFrame.cs namespace Assets.Scripts { using UnityEngine; public clas

TensorFlow學習筆記(六) tensorflow 的儲存訓練的引數以及載入引數檢測test集

如何儲存訓練好的引數以前面練習的一個小例子,來儲存訓練好的引數:import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data from tensorflow import

學習筆記】Java生成對象的5方法

目標 獲得 cti com pre lan except 我們 highlight 概述:本文介紹以下java五種創建對象的方式: 1.用new語句創建對象,這是最常用的創建對象的方式。 2.使用Class類的newInstance方法 3.運用反射手段,調用java.la

Linux學習筆記4-CentOS7redis3.2.9安裝教程

錯誤 img make .gz 需要 down images red pre redis下載地址:http://www.redis.cn/download.html 1、將下載過來的redis-3.2.9.tar.gz文件復制到/usr/local文件夾下 2、tar x

tensorflow學習筆記(二)

example initial turn rate mnist pac rac test mode import tensorflow as tfimport numpy as npimport mathimport tensorflow.examples.tutorial

Spark StreamingKafka獲取數據,並進行實時單詞統計,統計URL出現的次數

scrip 發送消息 rip mark 3.2 umt 過程 bject ttr 1、創建Maven項目 創建的過程參考:http://blog.csdn.net/tototuzuoquan/article/details/74571374 2、啟動Kafka A:安裝ka

tensorflow學習筆記(三):實現自編碼器

sea start ear var logs cos soft 編碼 red 黃文堅的tensorflow實戰一書中的第四章,講述了tensorflow實現多層感知機。Hiton早年提出過自編碼器的非監督學習算法,書中的代碼給出了一個隱藏層的神經網絡,本人擴展到了多層,改進

超時時間已到。超時時間已到,但是尚未獲取連接。出現這種情況可能是因為所有池連接均在使用,並且達到了最大池大小。

intel weight 關閉 雙擊 itl 手動 瀏覽器 默認 取數據 超時時間已到。超時時間已到,但是尚未從池中獲取連接。出現這種情況可能是因為所有池連接均在使用,並且達到了最大池大小。 解決辦法 1.在代碼裏面,把未關閉的連接關閉 2.擴大共享池,方法如下:

TensorFlow學習筆記(UTF-8 問題解決 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte)

show 學習 github red star ims fas can pri 我使用VS2013 Python3.5 TensorFlow 1.3 的開發環境 UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte

tensorflow學習筆記----TensorBoard講解

幫助 ont 分享圖片 graphs 進行 平均值 all 訓練 一個 TensorBoard簡介

【知了堂學習筆記】java常用集合的理解

style out hset 篩選 arraylist list 內容 必備 foreach   最近學習了java中常用集合類的一些知識,在這裏作為一只小白,我來談談我的理解,順帶總結知識點。 引入:在沒有接觸之前,聽到集合,給我感覺是想到了數學中的集合一樣,裏面存放著一

Mysql DBA 高級運維學習筆記-刪除表數據

全部 邏輯 ase 學習 大於 del dep 記錄 rom 9.11 刪除表中數據 命令語法:delete from 表名 where 表達式 實踐: (1)刪除表student中編號為3的記錄 mysql> use zbf Database changed m

TensorFlow學習筆記(6)讀取數據

官網 com 記錄 mat target 項目 AD 包含 技術 Overview 之前幾次推送的全部例程,使用的都是tensorflow預處理過的數據集,直接載入即可。例如: 然而實際中我們使用的通常不會是這種超級經典的數據集,如果我們有一組圖像存儲在磁盤上