tf-keras-skeleton.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:LIE 作者: EmbraceLife 项目源码 文件源码
def ctc_decode(y_pred, input_length, greedy=True, beam_width=100, top_paths=1):
      """Decodes the output of a softmax.

      Can use either greedy search (also known as best path)
      or a constrained dictionary search.

      Arguments:
          y_pred: tensor `(samples, time_steps, num_categories)`
              containing the prediction, or output of the softmax.
          input_length: tensor `(samples, )` containing the sequence length for
              each batch item in `y_pred`.
          greedy: perform much faster best-path search if `true`.
              This does not use a dictionary.
          beam_width: if `greedy` is `false`: a beam search decoder will be used
              with a beam of this width.
          top_paths: if `greedy` is `false`,
              how many of the most probable paths will be returned.

      Returns:
          Tuple:
              List: if `greedy` is `true`, returns a list of one element that
                  contains the decoded sequence.
                  If `false`, returns the `top_paths` most probable
                  decoded sequences.
                  Important: blank labels are returned as `-1`.
              Tensor `(top_paths, )` that contains
                  the log probability of each decoded sequence.
      """
      y_pred = math_ops.log(array_ops.transpose(y_pred, perm=[1, 0, 2]) + 1e-8)
      input_length = math_ops.to_int32(input_length)

      if greedy:
        (decoded, log_prob) = ctc.ctc_greedy_decoder(
            inputs=y_pred, sequence_length=input_length)
      else:
        (decoded, log_prob) = ctc.ctc_beam_search_decoder(
            inputs=y_pred,
            sequence_length=input_length,
            beam_width=beam_width,
            top_paths=top_paths)
      decoded_dense = [
          sparse_ops.sparse_to_dense(
              st.indices, st.dense_shape, st.values, default_value=-1)
          for st in decoded
      ]
      return (decoded_dense, log_prob)


    # HIGH ORDER FUNCTIONS
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号