How to get the dimensions of a tensor (in TensorFlow) at graph construction time?

后端 未结 6 885
你的背包
你的背包 2021-01-30 20:54

I am trying an Op that is not behaving as expected.

graph = tf.Graph()
with graph.as_default():
  train_dataset = tf.placeholder(tf.int32, shape=[128, 2])
  embe         


        
6条回答
  •  迷失自我
    2021-01-30 21:32

    Just print out the embed after construction graph (ops) without running:

    import tensorflow as tf
    
    ...
    
    train_dataset = tf.placeholder(tf.int32, shape=[128, 2])
    embeddings = tf.Variable(
        tf.random_uniform([50000, 64], -1.0, 1.0))
    embed = tf.nn.embedding_lookup(embeddings, train_dataset)
    print (embed)
    

    This will show the shape of the embed tensor:

    Tensor("embedding_lookup:0", shape=(128, 2, 64), dtype=float32)
    

    Usually, it's good to check shapes of all tensors before training your models.

提交回复
热议问题