code: def test_melspectrogram_correctness(
      n_fft,
      sr,
      hop_length,
      n_ch,
      data_format,
      amin,
      dynamic_range,
      n_mels,
      mel_f_min,
      mel_f_max,
  ):
      """Test the correctness of melspectrogram.
  
      Note that mel filterbank is tested separated
  
      """
  
      def _get_melgram_model(
          return_decibel, amin, dynamic_range, input_shape=None
      ):
          # compute with kapre
          melgram_model = get_melspectrogram_layer(
              n_fft=n_fft,
              sample_rate=sr,
              n_mels=n_mels,
              mel_f_min=mel_f_min,
              mel_f_max=mel_f_max,
              win_length=win_length,
              hop_length=hop_length,
              input_data_format=data_format,
              output_data_format=data_format,
              return_decibel=return_decibel,
              input_shape=input_shape,
              db_amin=amin,
              db_dynamic_range=dynamic_range,
          )
          return melgram_model
  
      src_mono, batch_src, input_shape = get_audio(
          data_format=data_format, n_ch=n_ch
      )
  
      win_length = n_fft  # test with x2
      # compute with librosa
      S_ref = librosa.feature.melspectrogram(
          src_mono,
          sr=sr,
          n_fft=n_fft,
          hop_length=hop_length,
          win_length=win_length,
          center=False,
          power=1.0,
          n_mels=n_mels,
          fmin=mel_f_min,
          fmax=mel_f_max,
      ).T
  
      S_ref = np.expand_dims(S_ref, axis=2)  # time, freq, ch=1
      S_ref = np.tile(S_ref, [1, 1, n_ch])  # time, freq, ch=n_ch
  
      if data_format == "channels_first":
          S_ref = np.transpose(S_ref, (2, 0, 1))  # ch, time, freq
  
      # melgram
      melgram_model = _get_melgram_model(
          return_decibel=False,
          input_shape=input_shape,
          amin=None,
          dynamic_range=120.0,
      )
      S = melgram_model.predict(batch_src)[0]  # 3d representation
      np.testing.assert_allclose(S_ref, S, atol=1e-4)
  
      # log melgram
      melgram_model = _get_melgram_model(
          return_decibel=True,
          input_shape=input_shape,
          amin=amin,
          dynamic_range=dynamic_range,
      )
      S = melgram_model.predict(batch_src)[0]  # 3d representation
      S_ref_db = librosa.power_to_db(
          S_ref, ref=1.0, amin=amin, top_db=dynamic_range
      )
  
      np.testing.assert_allclose(S_ref_db, S, rtol=3e-3)
  
imports: import pytest
  import numpy
  import tensorflow
  import tensorflow.keras
  import librosa
  from kapre import STFT, Magnitude, Phase, Delta, InverseSTFT, ApplyFilterbank, ConcatenateFrequencyMap, STFTTflite, MagnitudeTflite, PhaseTflite
  from kapre.composed import get_melspectrogram_layer, get_log_frequency_spectrogram_layer, get_stft_mag_phase, get_perfectly_reconstructing_stft_istft, get_stft_magnitude_layer, get_frequency_aware_conv2d
  from utils import get_audio, save_load_compare, predict_using_tflite
label_desc: Use image node_id 8 for calling a global function with example usage: test_melspectrogram_correctness(n_fft, sr, hop_length, n_ch, data_format, amin, dynamic_range, n_mels, mel_f_min, mel_f_max) and returns: melgram_model