2017-12-11 7 views
2

操作の出力とテンソルのペア間のユークリッド距離を計算したいと思います。私はhereのコードを使用しています。ここに私のコードの要点を以下に示します。Tensorflow - 操作をTensorに変換できません

# Suppose logits has shape [32, 128] 
    logits = tf.get_default_graph().get_operation_by_name('Tanh') 
    y = tf.placeholder(tf.float32, shape=[10, 128]) 

    m1, m2, k = 32, tf.shape(y)[0], latent_dim 

    # Get the pairwise distances 
    p1 = tf.matmul(tf.expand_dims(tf.reduce_sum(tf.square(logits), 1), 1), 
        tf.ones(shape=(1, m2))) 
    p2 = tf.transpose(tf.matmul(
     tf.reshape(tf.reduce_sum(tf.square(y), 1), shape=[-1, 1]), 
     tf.ones(shape=(m1, 1)), 
     transpose_b=True 
    )) 
    distance_predictions = tf.sqrt(tf.add(p1, p2) - 2 * 
     tf.matmul(logits, y, transpose_b=True))   

私は次のエラーを取得するしかし:

この行のために
TypeError: Can't convert Operation '.../Tanh' to Tensor (target dtype=None, name=u'x', as_ref=False) 

p1 = tf.matmul(tf.expand_dims(tf.reduce_sum(tf.square(logits), 1), 1), 
       tf.ones(shape=(1, m2))) 

が、私はこれをどのように修正する必要がありますか? tf.get_default_graph().get_operation_by_nameを呼び出すことにより、

+0

との最初の行を交換するのですか? – GPhilo

+0

私の質問を編集しました! –

+0

MCVE(https://stackoverflow.com/help/mcve)を見せてください。私はあなたのエラーを再現しようとしましたが、私のシナリオではすべて正常に動作しました。 –

答えて

1

、私は双曲線正接の活性化を計算OPSを得ていました。しかし、代わりに私が必要とするのは、その操作の出力です。tf.get_default_graph().get_tensor_by_nameを呼び出すと見つかります。

したがって修正でエラーが発生します何行

logits = tf.get_default_graph().get_tensor_by_name('Tanh:0')

関連する問題