{
  "id": 168166,
  "title": "SpecAugment with Pytorch",
  "url": "/competitions/birdsong-recognition/discussion/168166",
  "author_name": "",
  "post_date": "2020-07-19T13:54:22.197428300Z",
  "votes": 8,
  "comment_count": 1,
  "views": 0,
  "content": "<p>I find very nice audio SpecAugment library with Pytorch.\nHope it help to break the ice!!!!✌️ \n```</p>\n\n<h1>Export</h1>\n\n<p>def freq_mask(spec, F=30, num_masks=1, replace_with_zero=False):\n    cloned = spec.clone()\n    num_mel_channels = cloned.shape[1]</p>\n\n<pre><code>for i in range(0, num_masks):        \n    f = random.randrange(0, F)\n    f_zero = random.randrange(0, num_mel_channels - f)\n\n    # avoids randrange error if values are equal and range is empty\n    if (f_zero == f_zero + f): return cloned\n\n    mask_end = random.randrange(f_zero, f_zero + f) \n    if (replace_with_zero): cloned[0][f_zero:mask_end] = 0\n    else: cloned[0][f_zero:mask_end] = cloned.mean()\n\nreturn cloned\n</code></pre>\n\n<p>```\n<a href=\"https://github.com/zcaceres/spec_augment\">https://github.com/zcaceres/spec_augment</a></p>",
  "messages": [
    {
      "id": "935573",
      "postDate": "07/19/2020 13:54:22",
      "content": "<p>I find very nice audio SpecAugment library with Pytorch.\nHope it help to break the ice!!!!✌️ \n```</p>\n\n<h1>Export</h1>\n\n<p>def freq_mask(spec, F=30, num_masks=1, replace_with_zero=False):\n    cloned = spec.clone()\n    num_mel_channels = cloned.shape[1]</p>\n\n<pre><code>for i in range(0, num_masks):        \n    f = random.randrange(0, F)\n    f_zero = random.randrange(0, num_mel_channels - f)\n\n    # avoids randrange error if values are equal and range is empty\n    if (f_zero == f_zero + f): return cloned\n\n    mask_end = random.randrange(f_zero, f_zero + f) \n    if (replace_with_zero): cloned[0][f_zero:mask_end] = 0\n    else: cloned[0][f_zero:mask_end] = cloned.mean()\n\nreturn cloned\n</code></pre>\n\n<p>```\n<a href=\"https://github.com/zcaceres/spec_augment\">https://github.com/zcaceres/spec_augment</a></p>",
      "rawMarkdown": "I find very nice audio SpecAugment library with Pytorch.\nHope it help to break the ice!!!!✌️ \n```\n\n#Export\ndef freq_mask(spec, F=30, num_masks=1, replace_with_zero=False):\n    cloned = spec.clone()\n    num_mel_channels = cloned.shape[1]\n    \n    for i in range(0, num_masks):        \n        f = random.randrange(0, F)\n        f_zero = random.randrange(0, num_mel_channels - f)\n\n        # avoids randrange error if values are equal and range is empty\n        if (f_zero == f_zero + f): return cloned\n\n        mask_end = random.randrange(f_zero, f_zero + f) \n        if (replace_with_zero): cloned[0][f_zero:mask_end] = 0\n        else: cloned[0][f_zero:mask_end] = cloned.mean()\n    \n    return cloned\n```\nhttps://github.com/zcaceres/spec_augment",
      "votes": null
    },
    {
      "id": "941850",
      "postDate": "07/23/2020 12:55:26",
      "content": "<p>Thank you for sharing! I actually tried training a model using specaugmented spectrograms but LB score worsened</p>",
      "rawMarkdown": "Thank you for sharing! I actually tried training a model using specaugmented spectrograms but LB score worsened",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 941850,
      "author_name": "alanchn31",
      "author_url": "",
      "post_date": "07/23/2020 12:55:26",
      "content": "<p>Thank you for sharing! I actually tried training a model using specaugmented spectrograms but LB score worsened</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "935573": "I find very nice audio SpecAugment library with Pytorch.\nHope it help to break the ice!!!!✌️ \n```\n\n#Export\ndef freq_mask(spec, F=30, num_masks=1, replace_with_zero=False):\n    cloned = spec.clone()\n    num_mel_channels = cloned.shape[1]\n    \n    for i in range(0, num_masks):        \n        f = random.randrange(0, F)\n        f_zero = random.randrange(0, num_mel_channels - f)\n\n        # avoids randrange error if values are equal and range is empty\n        if (f_zero == f_zero + f): return cloned\n\n        mask_end = random.randrange(f_zero, f_zero + f) \n        if (replace_with_zero): cloned[0][f_zero:mask_end] = 0\n        else: cloned[0][f_zero:mask_end] = cloned.mean()\n    \n    return cloned\n```\nhttps://github.com/zcaceres/spec_augment",
    "941850": "Thank you for sharing! I actually tried training a model using specaugmented spectrograms but LB score worsened"
  },
  "source": "meta"
}