{
  "id": 237916,
  "title": "why is the result of torchaudio.MelSpectrogram different from that of librosa",
  "url": "/competitions/birdclef-2021/discussion/237916",
  "author_name": "",
  "post_date": "2021-05-10T16:28:37.176198400Z",
  "votes": 7,
  "comment_count": 4,
  "views": 0,
  "content": "<p><code>\ny, sr = sf.read(\"xxxxx.ogg\")\n</code></p>\n<p><code>melspec = librosa.feature.melspectrogram(y, sr=sr, n_mels=128, fmin=20, fmax=16000,center=True)</code></p>\n<p><code>y = torch.from_numpy(y)[None, ...].float()</code></p>\n<p><code>melspec_audio = torchaudio.transforms.MelSpectrogram(\n        sample_rate=sr,\n        n_fft=2048,\n        win_length=2048,\n        hop_length=512,\n        f_min=20,\n        f_max=16000,\n        center=True,\n    )(y)</code></p>\n<p>I test with the code above.<br>\nwhy melspec is different from melspec_audio?</p>\n<p>Thanks.!</p>",
  "messages": [
    {
      "id": "1300691",
      "postDate": "05/10/2021 16:28:37",
      "content": "<p><code>\ny, sr = sf.read(\"xxxxx.ogg\")\n</code></p>\n<p><code>melspec = librosa.feature.melspectrogram(y, sr=sr, n_mels=128, fmin=20, fmax=16000,center=True)</code></p>\n<p><code>y = torch.from_numpy(y)[None, ...].float()</code></p>\n<p><code>melspec_audio = torchaudio.transforms.MelSpectrogram(\n        sample_rate=sr,\n        n_fft=2048,\n        win_length=2048,\n        hop_length=512,\n        f_min=20,\n        f_max=16000,\n        center=True,\n    )(y)</code></p>\n<p>I test with the code above.<br>\nwhy melspec is different from melspec_audio?</p>\n<p>Thanks.!</p>",
      "rawMarkdown": "`\ny, sr = sf.read(\"xxxxx.ogg\")\n`\n\n`melspec = librosa.feature.melspectrogram(y, sr=sr, n_mels=128, fmin=20, fmax=16000,center=True)`\n\n`y = torch.from_numpy(y)[None, ...].float()`\n\n`melspec_audio = torchaudio.transforms.MelSpectrogram(\n        sample_rate=sr,\n        n_fft=2048,\n        win_length=2048,\n        hop_length=512,\n        f_min=20,\n        f_max=16000,\n        center=True,\n    )(y)`\n\n\nI test with the code above.\nwhy melspec is different from melspec_audio?\n\nThanks.!",
      "votes": null
    },
    {
      "id": "1300807",
      "postDate": "05/10/2021 18:18:57",
      "content": "<p>how much different?  This is floating point computation hence you should not test equality of result as is.  You should compute the average (or max) delta between the two.</p>",
      "rawMarkdown": "how much different?  This is floating point computation hence you should not test equality of result as is.  You should compute the average (or max) delta between the two.",
      "votes": null
    },
    {
      "id": "1301246",
      "postDate": "05/11/2021 01:55:50",
      "content": "<p>Thanks!!  <br>\nFor example, i test <code>acafly/XC6671.ogg</code><br>\n<code>melspec</code> (from librosa) mean is 0.063499, max is 101.2<br>\n<code>melspec_audio</code> (from torchaudio) mean is 9.5461, max is 16972.</p>\n<p>Is there something wrong with me</p>\n<p>[SOLVED]: For librosa,  htk == true make MAE between them is reasonable</p>",
      "rawMarkdown": "Thanks!!  \nFor example, i test `acafly/XC6671.ogg`\n`melspec` (from librosa) mean is 0.063499, max is 101.2\n`melspec_audio` (from torchaudio) mean is 9.5461, max is 16972.\n\nIs there something wrong with me\n\n\n[SOLVED]: For librosa,  htk == true make MAE between them is reasonable",
      "votes": null
    },
    {
      "id": "1301544",
      "postDate": "05/11/2021 06:15:30",
      "content": "<p>Tx for following up.  Indeed the difference was significant.  But you found the parameter setting that explained it.</p>",
      "rawMarkdown": "Tx for following up.  Indeed the difference was significant.  But you found the parameter setting that explained it.",
      "votes": null
    },
    {
      "id": "1312379",
      "postDate": "05/18/2021 02:52:31",
      "content": "<p>In my memory, 2 years ago I was irritated by lot's of torchaudio's source code default setting values were different from librosa's when creating Mel spectrogram.<br>\nNow it looks to be much easier to use, but it seems they still has some default differences.</p>",
      "rawMarkdown": "In my memory, 2 years ago I was irritated by lot's of torchaudio's source code default setting values were different from librosa's when creating Mel spectrogram.\nNow it looks to be much easier to use, but it seems they still has some default differences.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1300807,
      "author_name": "cpmpml",
      "author_url": "",
      "post_date": "05/10/2021 18:18:57",
      "content": "<p>how much different?  This is floating point computation hence you should not test equality of result as is.  You should compute the average (or max) delta between the two.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1301246,
          "author_name": "changewow",
          "author_url": "",
          "post_date": "05/11/2021 01:55:50",
          "content": "<p>Thanks!!  <br>\nFor example, i test <code>acafly/XC6671.ogg</code><br>\n<code>melspec</code> (from librosa) mean is 0.063499, max is 101.2<br>\n<code>melspec_audio</code> (from torchaudio) mean is 9.5461, max is 16972.</p>\n<p>Is there something wrong with me</p>\n<p>[SOLVED]: For librosa,  htk == true make MAE between them is reasonable</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1301544,
          "author_name": "cpmpml",
          "author_url": "",
          "post_date": "05/11/2021 06:15:30",
          "content": "<p>Tx for following up.  Indeed the difference was significant.  But you found the parameter setting that explained it.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1312379,
      "author_name": "ryunosukeishizaki",
      "author_url": "",
      "post_date": "05/18/2021 02:52:31",
      "content": "<p>In my memory, 2 years ago I was irritated by lot's of torchaudio's source code default setting values were different from librosa's when creating Mel spectrogram.<br>\nNow it looks to be much easier to use, but it seems they still has some default differences.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1300691": "`\ny, sr = sf.read(\"xxxxx.ogg\")\n`\n\n`melspec = librosa.feature.melspectrogram(y, sr=sr, n_mels=128, fmin=20, fmax=16000,center=True)`\n\n`y = torch.from_numpy(y)[None, ...].float()`\n\n`melspec_audio = torchaudio.transforms.MelSpectrogram(\n        sample_rate=sr,\n        n_fft=2048,\n        win_length=2048,\n        hop_length=512,\n        f_min=20,\n        f_max=16000,\n        center=True,\n    )(y)`\n\n\nI test with the code above.\nwhy melspec is different from melspec_audio?\n\nThanks.!",
    "1300807": "how much different?  This is floating point computation hence you should not test equality of result as is.  You should compute the average (or max) delta between the two.",
    "1301246": "Thanks!!  \nFor example, i test `acafly/XC6671.ogg`\n`melspec` (from librosa) mean is 0.063499, max is 101.2\n`melspec_audio` (from torchaudio) mean is 9.5461, max is 16972.\n\nIs there something wrong with me\n\n\n[SOLVED]: For librosa,  htk == true make MAE between them is reasonable",
    "1301544": "Tx for following up.  Indeed the difference was significant.  But you found the parameter setting that explained it.",
    "1312379": "In my memory, 2 years ago I was irritated by lot's of torchaudio's source code default setting values were different from librosa's when creating Mel spectrogram.\nNow it looks to be much easier to use, but it seems they still has some default differences."
  },
  "source": "meta"
}