[英]How to add print OP in TensorFlow layer(GRU)?
我在GRU源代碼中添加了print OP,想調試GRU的輸入,也想用GRU內部的一些操作來調試,但是這個打印什么都沒有。 劑量 tf.print 在 GRU 的源代碼中不起作用。 我希望有人能給我一些建議。 非常感謝!
def call(self, inputs, state):
"""Gated recurrent unit (GRU) with nunits cells."""
import tensorflow as tf
print_GRU = tf.print(inputs) #<<<<<<<<<<<<<<<<<< add print OP HERE
with tf.control_dependencies([print_GRU]):
gate_inputs = math_ops.matmul(
array_ops.concat([inputs, state], 1), self._gate_kernel)
# gate_inputs = math_ops.matmul(
# array_ops.concat([inputs, state], 1), self._gate_kernel)
gate_inputs = nn_ops.bias_add(gate_inputs, self._gate_bias)
value = math_ops.sigmoid(gate_inputs)
r, u = array_ops.split(value=value, num_or_size_splits=2, axis=1)
r_state = r * state
candidate = math_ops.matmul(
array_ops.concat([inputs, r_state], 1), self._candidate_kernel)
candidate = nn_ops.bias_add(candidate, self._candidate_bias)
c = self._activation(candidate)
new_h = u * state + (1 - u) * c
return new_h, new_h
在call
內部,使用這一行:
tf.py_function(func=tf.print, inp=[inputs], Tout=[])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.