1

I'm working with checkpoint files and a model with output/tensors that weren't explicitly named.

I understand how naming works:

Tensorflow: What is the output node name in Cifar-10 model? && How does TensorFlow name tensors?

But I am unsure of how to generate the names from existing checkpoint files (no pb's were generated and I need this in order to get that):

model.ckpt.data-00000-of-00001
model.ckpt.index
model.ckpt.meta

The CNN in question is fast-neural-style

Michael Ramos
  • 5,523
  • 8
  • 36
  • 51

2 Answers2

2

From KeyError : The tensor variable , Refer to the tensor which does not exists

This prints out all tensor names and you can try and figure out which one you need.

model_path = "my_model.ckpt"

sess = tf.Session()

saver = tf.train.import_meta_graph(model_path + ".meta")
saver.restore(sess, model_path)
graph = tf.get_default_graph()

for op in graph.get_operations():
    print(op.name)
madvn
  • 33
  • 7
1

So with that current model, I found that in evaluate.py you can access the restored graph and simply print to find out the name.

with g.as_default(), g.device(device_t), \
            tf.Session(config=soft_config) as sess:
        batch_shape = (batch_size,) + img_shape
        img_placeholder = tf.placeholder(tf.float32, shape=batch_shape,
                                         name='img_placeholder')

        preds = transform.net(img_placeholder)
        print(preds)

output:

Tensor("add_37:0", shape=(1, 720, 884, 3), dtype=float32, device=/device:GPU:0)

In this case the operation was add, and tensorflow named it accordingly: add_37

Michael Ramos
  • 5,523
  • 8
  • 36
  • 51