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.

audio_ops.h 4.8 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /**
  2. * Copyright 2019 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. /*!
  17. * \file audio_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_AUDIO_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_AUDIO_OPS_H_
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. *@brief Mel-Frequency Cepstral Coefficient (MFCC) calculation consists of
  26. taking the DCT-II of a log-magnitude mel-scale spectrogram . \n
  27. *@par Inputs:
  28. *Input "spectrogram" is a 3D tensor. Input "sample_rate" is a scalar.
  29. * @li spectrogram: A 3D float tensor.
  30. * @li sample_rate: The MFCC sample rate . \n
  31. *@par Attributes:
  32. *@li upper_frequency_limit: The highest frequency for calculation.
  33. *@li lower_frequency_limit: The lowest frequency for calculation.
  34. *@li filterbank_channel_count: Resolution of the Mel bank.
  35. *@li dct_coefficient_count: Number of output channels to produce
  36. per time slice . \n
  37. *@par Outputs:
  38. *y: A Tensor of type float32 . \n
  39. *@attention Constraints:
  40. *Mfcc runs on the Ascend AI CPU, which delivers poor performance.
  41. *@par Third-party framework compatibility
  42. *Compatible with the TensorFlow operator Mfcc . \n
  43. *@par Restrictions:
  44. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  45. */
  46. REG_OP(Mfcc)
  47. .INPUT(spectrogram, TensorType({DT_FLOAT}))
  48. .INPUT(sample_rate, TensorType({DT_INT32}))
  49. .OUTPUT(y, TensorType({DT_FLOAT}))
  50. .ATTR(upper_frequency_limit, Float, 4000)
  51. .ATTR(lower_frequency_limit, Float, 20)
  52. .ATTR(filterbank_channel_count, Int, 40)
  53. .ATTR(dct_coefficient_count, Int, 13)
  54. .OP_END_FACTORY_REG(Mfcc)
  55. /**
  56. *@brief Decodes and generates spectrogram using wav float tensor . \n
  57. *@par Inputs:
  58. *Input "x" is a 2D matrix.
  59. * x: A float tensor. Float representation of audio data . \n
  60. *@par Attributes:
  61. *@li window_size: Size of the spectrogram window.
  62. *@li stride: Size of the spectrogram stride.
  63. *@li magnitude_squared: If true, uses squared magnitude . \n
  64. *@par Outputs:
  65. *spectrogram: A 3D float Tensor . \n
  66. *@attention Constraints:
  67. *AudioSpectrogram runs on the Ascend AI CPU, which delivers
  68. poor performance . \n
  69. *@par Third-party framework compatibility
  70. *Compatible with the TensorFlow operator AudioSpectrogram . \n
  71. *@par Restrictions:
  72. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  73. */
  74. REG_OP(AudioSpectrogram)
  75. .INPUT(x, TensorType({DT_FLOAT}))
  76. .OUTPUT(spectrogram, TensorType({DT_FLOAT}))
  77. .REQUIRED_ATTR(window_size, Int)
  78. .REQUIRED_ATTR(stride, Int)
  79. .ATTR(magnitude_squared, Bool, false)
  80. .OP_END_FACTORY_REG(AudioSpectrogram)
  81. /**
  82. *@brief Decodes a 16-bit WAV file into a float tensor . \n
  83. *@par Inputs:
  84. *contents: A Tensor of type string. The WAV-encoded audio, usually from a file . \n
  85. *@par Attributes:
  86. *@li desired_channels: An optional int. Defaults to "-1".
  87. Number of sample channels wanted.
  88. *@li desired_samples: An optional int. Defaults to "-1".
  89. Length of audio requested . \n
  90. *@par Outputs:
  91. *@li *audio: A Tensor of type float32.
  92. *@li *sample_rate: A Tensor of type int32 . \n
  93. *@attention Constraints:
  94. *DecodeWav runs on the Ascend AI CPU, which delivers poor performance.
  95. *@par Third-party framework compatibility
  96. *Compatible with the TensorFlow operator DecodeWav . \n
  97. *@par Restrictions:
  98. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  99. */
  100. REG_OP(DecodeWav)
  101. .INPUT(contents, TensorType({DT_STRING}))
  102. .OUTPUT(audio, TensorType({DT_FLOAT}))
  103. .OUTPUT(sample_rate, TensorType({DT_INT32}))
  104. .ATTR(desired_channels, Int, -1)
  105. .ATTR(desired_samples, Int, -1)
  106. .OP_END_FACTORY_REG(DecodeWav)
  107. /**
  108. *@brief Encode audio data using the WAV file format . \n
  109. *@par Inputs:
  110. *Including:
  111. * @li audio: A Tensor of type DT_FLOAT.
  112. * @li sample_rate: A Tensor of type DT_INT32 . \n
  113. *@par Outputs:
  114. *contents: A Tensor of type DT_STRING . \n
  115. *@attention Constraints:
  116. *EncodeWav runs on the Ascend AI CPU, which delivers poor performance.
  117. *@par Third-party framework compatibility
  118. *Compatible with tensorflow Operator EncodeWav . \n
  119. *@par Restrictions:
  120. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  121. */
  122. REG_OP(EncodeWav)
  123. .INPUT(audio, TensorType({DT_FLOAT}))
  124. .INPUT(sample_rate, TensorType({DT_INT32}))
  125. .OUTPUT(contents, TensorType({DT_STRING}))
  126. .OP_END_FACTORY_REG(EncodeWav)
  127. } // namespace ge
  128. #endif // OPS_BUILT_IN_OP_PROTO_INC_AUDIO_OPS_H_

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