Nam*_*g-K 23 python bidirectional deep-learning tensorflow recurrent-neural-network
我正在使用张量流中的双向动态RNN进行文本标记.在加工输入维度后,我尝试运行一个Session.这是blstm设置部分:
fw_lstm_cell = BasicLSTMCell(LSTM_DIMS)
bw_lstm_cell = BasicLSTMCell(LSTM_DIMS)
(fw_outputs, bw_outputs), _ = bidirectional_dynamic_rnn(fw_lstm_cell,
bw_lstm_cell,
x_place,
sequence_length=SEQLEN,
dtype='float32')
Run Code Online (Sandbox Code Playgroud)
这是运行部分:
with tf.Graph().as_default():
# Placehoder Settings
x_place, y_place = set_placeholder(BATCH_SIZE, EM_DIMS, MAXLEN)
# BLSTM Model Building
hlogits = tf_kcpt.build_blstm(x_place)
# Compute loss
loss = tf_kcpt.get_loss(log_likelihood)
# Training
train_op = tf_kcpt.training(loss)
# load Eval method
eval_correct = tf_kcpt.evaluation(logits, y_place)
# Session Setting & Init
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
# tensor summary setting
summary = tf.summary.merge_all()
summary_writer = tf.summary.FileWriter(LOG_DIR, sess.graph)
# Save
saver = tf.train.Saver()
# Run epoch
for step in range(EPOCH):
start_time = time.time()
feed_dict = fill_feed_dict(KCPT_SET['train'], x_place, y_place)
_, loss_value = sess.run([train_op, loss], feed_dict=feed_dict)
Run Code Online (Sandbox Code Playgroud)
但是,它给了我错误:
ValueError:Tensor("Shape:0",shape =(1,),dtype = int32)必须与Tensor在同一个图形中("bidirectional_rnn/fw/fw/stack_2:0",shape =(1,),dtype = INT32).
请帮帮我
小智 39
TensorFlow将所有操作存储在操作图上.此图定义了输出到哪里的函数,并将它们全部链接在一起,以便它可以按照您在图中设置的步骤生成最终输出.如果您尝试在一个图表上输入Tensor或操作到Tensor或在另一个图表上操作,它将失败.一切都必须在同一个执行图上.
尝试删除 with tf.Graph().as_default():
TensorFlow为您提供了一个默认图表,如果您未指定图表,则会引用该图表.您可能正在使用训练块中的一个位置和另一个图形中的默认图形.
似乎没有理由在此处将图表指定为默认值,并且很可能您在事故中使用单独的图表.如果你真的想要指定一个图形,那么你可能想把它作为变量传递,而不是像这样设置它.
如果您将 tf 2.x 与 Keras 一起使用 - 那么在构建模型图之前禁用即时执行可能会有所帮助。所以要禁用急切执行 - 在定义模型之前添加以下行。
tf.compat.v1.disable_eager_execution()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29245 次 |
| 最近记录: |