Get Tensor Variable by Tensor Name – TensorFlow Tutorial

By | June 13, 2019

If you get a pretrained model, how to read tensor value from it?

You can do like this:

Step 1: Get tensor name from this model

You can read this two tutorials.

List All Trainable and Untrainable Variables in TensorFlow

List All Variables including Constant and Placeholder in TensorFlow

Step 2. Get this tensor value from this model

How to get tensor by its name?

Here is an example snippet.

#-*- coding: utf-8 -*-
import numpy as np
import tensorflow as tf

graph = tf.Graph()
with graph.as_default():
sess = tf.Session()
with sess.as_default():
print lstm_w