You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ctc_ops.h 2.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef GE_OP_CTC_OPS_H
  17. #define GE_OP_CTC_OPS_H
  18. #include "graph/operator.h"
  19. #include "graph/operator_reg.h"
  20. namespace ge {
  21. /**
  22. *@brief Calculates the CTC Loss (log probability) for each batch entry. \n
  23. Also calculates the gradient.
  24. *@par Inputs:
  25. *@li inputs: 3-D, shape: `(max_time x batch_size x num_classes)`, the logits.
  26. *@li labels_indices: The indices of a `SparseTensor<int32, 2>`. \n
  27. `labels_indices(i, :) == [b, t]` means `labels_values(i)` stores the id for \n
  28. `(batch b, time t)`.
  29. *@li labels_values: The values (labels) associated with the given batch and time.
  30. *@li sequence_length: A vector containing sequence lengths (batch).
  31. *@par Outputs:
  32. *@li loss: A vector (batch) containing log-probabilities.
  33. *@li gradient: The gradient of `loss`. 3-D, shape: `(max_time x \n
  34. batch_size x num_classes)`.
  35. *@par Attributes:
  36. *@li preprocess_collapse_repeated: Scalar, if true then repeated labels are collapsed prior to \n
  37. the CTC calculation.If not specified, defaults to false
  38. *@li ctc_merge_repeated: Scalar. If set to false, *during* CTC calculation \n
  39. repeated non-blank labels will not be merged and are interpreted as \n
  40. individual labels. This is a simplified version of CTC. \n
  41. If not specified, defaults to true
  42. *@par Third-party framework compatibility
  43. * Compatible with TensorFlow CTCLoss operator.
  44. */
  45. REG_OP(CTCLoss)
  46. .INPUT(inputs, TensorType({DT_FLOAT, DT_DOUBLE}))
  47. .INPUT(labels_indices, TensorType({DT_INT64}))
  48. .INPUT(labels_values, TensorType({DT_INT32}))
  49. .INPUT(sequence_length, TensorType({DT_INT32}))
  50. .OUTPUT(loss, TensorType({DT_FLOAT, DT_DOUBLE}))
  51. .OUTPUT(gradient, TensorType({DT_FLOAT, DT_DOUBLE}))
  52. .ATTR(preprocess_collapse_repeated, Bool, false)
  53. .ATTR(ctc_merge_repeated, Bool, true)
  54. .ATTR(ignore_longer_outputs_than_inputs, Bool, false)
  55. .OP_END_FACTORY_REG(CTCLoss)
  56. } // namespace ge
  57. #endif //GE_OP_CTC_OPS_H

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示