【问题标题】:In tensorflow is there a way to find out a shape (rank) of elements' outputs while building a graph?在张量流中,有没有办法在构建图形时找出元素输出的形状(等级)?
【发布时间】:2019-09-14 17:16:14
【问题描述】:

我正在尝试在 tensorflow 中构建图表。但这给了我一个错误,即我的形状等级错误。所以,我试图找出在哪一步出了问题。是否有机会在构建图表时找出元素输出的形状?

比如我的代码是:

def inference_decoding_layer(start_token, end_token, embeddings, dec_cell, initial_state, output_layer,
                         max_summary_length, batch_size):
'''Create the inference logits'''


start_tokens = tf.tile(tf.constant([start_token], dtype=tf.int32), [batch_size], name='start_tokens')

inference_helper = tf.contrib.seq2seq.GreedyEmbeddingHelper(embeddings, #shape (2000,25,768)
                                                            start_tokens,
                                                            end_token)


inference_decoder = tf.contrib.seq2seq.BasicDecoder(dec_cell,
                                                    inference_helper,
                                                    initial_state,
                                                    output_layer)

inference_logits, _ , _ = tf.contrib.seq2seq.dynamic_decode(inference_decoder,
                                                        output_time_major=False,
                                                        impute_finished=True,
                                                        maximum_iterations=max_summary_length) 

return inference_decoder

问题出现在 dynamic_decoder。这是错误:

ValueError:形状必须为 3 级,但对于 'decode/decoder/while/BasicDecoderStep/decoder/attention_wrapper/concat_6'(操作:'ConcatV2')为 2 级,输入形状为:[32,25,768]、[32,256] , []。

所以,我想知道有没有办法找出,例如,我们从 GreedyEmbeddingHelper 然后从 BasicDecoder 获得的值的形状......或者可能是我整个代码中的其他东西。所以,我会找出问题所在。

附:如果有任何其他方法/建议如何在这种情况下定位问题,我将非常感激!

【问题讨论】:

    标签: python tensorflow shapes inference seq2seq


    【解决方案1】:

    为了方便调试,引入了eager模式。使用 Eager 模式,您可以在每行代码执行后继续打印输出形状。

    在 TF 1.x 中,要启用它,您必须运行以下代码:

    tf.enable_eager_execution()
    

    在 TF 2.0 中,默认情况下将启用 Eager 模式。此外,您正在处理的软件包已在 TF 2.0 中移至 TensorFlow Addons

    【讨论】:

      猜你喜欢
      • 2018-08-26
      • 1970-01-01
      • 2017-07-26
      • 2019-11-30
      • 2016-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多