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

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