我想在tensorflow中打印张量值,所以我在网上阅读了很多东西,但是我仍然无法使它工作,如果您能理解我在做什么错,我会很高兴,我想这会帮助我更好地了解tensorflow。
sess = tf.InteractiveSession()
with tf.name_scope("embedding"):
#sess = tf.InteractiveSession() #tried to insert also in here
embeddings = tf.gather(self.shared_weights, x)
embeddings *= self.hidden_size ** 0.5
print(embeddings.eval())#this is what I want to print
padding = model_utils.get_padding(x)
embeddings *= tf.expand_dims(1 - padding, -1)
return embeddings
sess.close()
我收到此错误:
FailedPreconditionError(请参阅上面的回溯):尝试使用 未初始化的值 型号/变压器/ embeddding_shared_weights / embedding_and_softmax / weights [[节点: 型号/变压器/ embeddding_shared_weights / embedding_and_softmax / weights / read = IdentityT = DT_FLOAT,_class = [“ loc:@ model / Transformer / embedding_shared_weights / embedding_and_softmax / weights”], _device =“ / job:localhost /副本:0 /任务:0 /设备:CPU:0”]]
这是我尝试过的另一件事:
with tf.name_scope("embedding"):
embeddings = tf.gather(self.shared_weights, x)
x = tf.get_variable('x', [tf.get_shape(embeddings)[0], tf.get_shape(embeddings)[1], tf.get_shape(embeddings)[2]])
x = tf.Print(embeddings, [embeddings])
sess = tf.InteractiveSession()
sess.run(x)
# Scale embedding by the sqrt of the hidden size
embeddings *= self.hidden_size ** 0.5
print(embeddings.eval())
# Create binary array of size [batch_size, length]
# where 1 = padding, 0 = not padding
padding = model_utils.get_padding(x)
# Set all padding embedding values to 0
embeddings *= tf.expand_dims(1 - padding, -1)
return embeddings
我收到此错误:
TypeError:int()参数必须是字符串,类似字节的对象或 数字,而不是“张量”
我尝试了更多的变种,但还是无济于事,如果您能帮助理解我所缺少的内容,我将很高兴。
非常感谢!