{
  "id": 261721,
  "title": "Things I've tried and how they worked out",
  "url": "/competitions/g2net-gravitational-wave-detection/discussion/261721",
  "author_name": "Fractal Feelings",
  "post_date": "2021-08-05T00:02:07.277000",
  "votes": 161,
  "comment_count": 83,
  "views": 0,
  "content": "<p>Since this was my first time using a NN, GPU/TPU and Tensorflow I had a steep learning curve. I tried a lot of things and thought I'd share what I learnt. </p>\n<p>In summary I used Keras to build a model that </p>\n<ul>\n<li>applies a bandpass filter, </li>\n<li>rescales the waveform to [-1, 1]</li>\n<li>Applies a time-frequency transform (e.g., STFT, CQT, CWT) to  create a scalogram</li>\n<li>Classifies  using Efficient Net.</li>\n</ul>\n<p>Is is very similar to what many others have done. I  currently have a AUC score of 0.872, which puts me in the middle of the leaderboard.</p>\n<p>What I learnt from experimenting with this was. </p>\n<ul>\n<li>The bandpass filter (20hz-500Hz) has quite an impact. I think this is because the noise below 20 Hz is high and signal is weaker at low frequencies, i.e., very low SNR. I chose 500 Hz because the highest signal frequency for a black hole event is 350 Hz.  I could not find articles on the frequency range for other types of events so I picked 500 as there are some strong noise sources just above that. It also looks like the best SNR is around 350-500Hz</li>\n<li>Rescaling was  essential. I'd be interested to hear from an Kaggel Expert if they found this and if so why? </li>\n<li>I started with nnAudio Constant Quality Transform (CQT) and found this a lot faster than librosa. The entire processing, i.e., load the data, bandpass filter,  creating the a 64x64 scalogram in nnAUdio and classifying in EFN B4 took about 8hrs on a CPU and  <strong>2hrs on a GPU</strong>. </li>\n<li>I discovered a  TF  implementation of Continuous Wavelet Transform  and updated it to TF 2.0,  optimised the algorithm, and made it a Keras Layer. This enables me to have a single Kera model for the scalogram -&gt; EFN that runs on a TPU. The entire processing time dropped to about <strong>30 min</strong>.</li>\n<li>I pre-processed the numpy input files into TFRecords and first epoch takes <strong>3 min</strong> and subsequent took 30s.</li>\n</ul>\n<p>This gave me an experimental test bed for further experimentation.  </p>\n<ul>\n<li>Larger scalograms, e.g., 256x256 and 512x512 gives a small boost.</li>\n<li>Different CWT wavelet_width, 8 seems optimal, give a small boost. I found making this paramater trainable also gave a small boost.</li>\n<li>Transfer Learning (i.e., freeze the EFN layer) followed by Fine Tuning (unfreeze). Marginal improvement</li>\n<li>DIfferent EFN models, e.g., B0, B4, B7, with B7 having a slight boost</li>\n</ul>\n<p>As I was running a lot of experiments I found that I needed a better way to record the results and started using Neptune.ai, which has been very useful.</p>\n<p>My best result so far is B7 with a 512x512 scalogram </p>",
  "messages": [
    {
      "id": 1449690,
      "postDate": "2021-08-05T00:02:07.277Z",
      "content": "<p>Since this was my first time using a NN, GPU/TPU and Tensorflow I had a steep learning curve. I tried a lot of things and thought I'd share what I learnt. </p>\n<p>In summary I used Keras to build a model that </p>\n<ul>\n<li>applies a bandpass filter, </li>\n<li>rescales the waveform to [-1, 1]</li>\n<li>Applies a time-frequency transform (e.g., STFT, CQT, CWT) to  create a scalogram</li>\n<li>Classifies  using Efficient Net.</li>\n</ul>\n<p>Is is very similar to what many others have done. I  currently have a AUC score of 0.872, which puts me in the middle of the leaderboard.</p>\n<p>What I learnt from experimenting with this was. </p>\n<ul>\n<li>The bandpass filter (20hz-500Hz) has quite an impact. I think this is because the noise below 20 Hz is high and signal is weaker at low frequencies, i.e., very low SNR. I chose 500 Hz because the highest signal frequency for a black hole event is 350 Hz.  I could not find articles on the frequency range for other types of events so I picked 500 as there are some strong noise sources just above that. It also looks like the best SNR is around 350-500Hz</li>\n<li>Rescaling was  essential. I'd be interested to hear from an Kaggel Expert if they found this and if so why? </li>\n<li>I started with nnAudio Constant Quality Transform (CQT) and found this a lot faster than librosa. The entire processing, i.e., load the data, bandpass filter,  creating the a 64x64 scalogram in nnAUdio and classifying in EFN B4 took about 8hrs on a CPU and  <strong>2hrs on a GPU</strong>. </li>\n<li>I discovered a  TF  implementation of Continuous Wavelet Transform  and updated it to TF 2.0,  optimised the algorithm, and made it a Keras Layer. This enables me to have a single Kera model for the scalogram -&gt; EFN that runs on a TPU. The entire processing time dropped to about <strong>30 min</strong>.</li>\n<li>I pre-processed the numpy input files into TFRecords and first epoch takes <strong>3 min</strong> and subsequent took 30s.</li>\n</ul>\n<p>This gave me an experimental test bed for further experimentation.  </p>\n<ul>\n<li>Larger scalograms, e.g., 256x256 and 512x512 gives a small boost.</li>\n<li>Different CWT wavelet_width, 8 seems optimal, give a small boost. I found making this paramater trainable also gave a small boost.</li>\n<li>Transfer Learning (i.e., freeze the EFN layer) followed by Fine Tuning (unfreeze). Marginal improvement</li>\n<li>DIfferent EFN models, e.g., B0, B4, B7, with B7 having a slight boost</li>\n</ul>\n<p>As I was running a lot of experiments I found that I needed a better way to record the results and started using Neptune.ai, which has been very useful.</p>\n<p>My best result so far is B7 with a 512x512 scalogram </p>",
      "rawMarkdown": "Since this was my first time using a NN, GPU/TPU and Tensorflow I had a steep learning curve. I tried a lot of things and thought I'd share what I learnt. \n\nIn summary I used Keras to build a model that \n* applies a bandpass filter, \n* rescales the waveform to [-1, 1]\n* Applies a time-frequency transform (e.g., STFT, CQT, CWT) to  create a scalogram\n* Classifies  using Efficient Net.\n\nIs is very similar to what many others have done. I  currently have a AUC score of 0.872, which puts me in the middle of the leaderboard.\n\nWhat I learnt from experimenting with this was. \n* The bandpass filter (20hz-500Hz) has quite an impact. I think this is because the noise below 20 Hz is high and signal is weaker at low frequencies, i.e., very low SNR. I chose 500 Hz because the highest signal frequency for a black hole event is 350 Hz.  I could not find articles on the frequency range for other types of events so I picked 500 as there are some strong noise sources just above that. It also looks like the best SNR is around 350-500Hz\n*  Rescaling was  essential. I'd be interested to hear from an Kaggel Expert if they found this and if so why? \n* I started with nnAudio Constant Quality Transform (CQT) and found this a lot faster than librosa. The entire processing, i.e., load the data, bandpass filter,  creating the a 64x64 scalogram in nnAUdio and classifying in EFN B4 took about 8hrs on a CPU and  **2hrs on a GPU**. \n* I discovered a  TF  implementation of Continuous Wavelet Transform  and updated it to TF 2.0,  optimised the algorithm, and made it a Keras Layer. This enables me to have a single Kera model for the scalogram -> EFN that runs on a TPU. The entire processing time dropped to about **30 min**.\n* I pre-processed the numpy input files into TFRecords and first epoch takes **3 min** and subsequent took 30s.\n\nThis gave me an experimental test bed for further experimentation.  \n* Larger scalograms, e.g., 256x256 and 512x512 gives a small boost.\n* Different CWT wavelet_width, 8 seems optimal, give a small boost. I found making this paramater trainable also gave a small boost.\n* Transfer Learning (i.e., freeze the EFN layer) followed by Fine Tuning (unfreeze). Marginal improvement\n* DIfferent EFN models, e.g., B0, B4, B7, with B7 having a slight boost\n\nAs I was running a lot of experiments I found that I needed a better way to record the results and started using Neptune.ai, which has been very useful.\n\nMy best result so far is B7 with a 512x512 scalogram ",
      "votes": 158
    },
    {
      "id": 1454700,
      "postDate": "2021-08-06T09:49:59.203Z",
      "content": "<p>Good work.</p>\n<p>You're not just tweaking public notebooks.  This is how to make a difference here.  Keep pushing (but not too hard, I'd like to stay ahead of you … )</p>",
      "rawMarkdown": "Good work.\n\nYou're not just tweaking public notebooks.  This is how to make a difference here.  Keep pushing (but not too hard, I'd like to stay ahead of you ... )",
      "votes": 21,
      "replies": [
        {
          "id": 1458571,
          "postDate": "2021-08-08T00:28:43.560Z",
          "content": "<p>and I'd like to catch up ;-)</p>",
          "rawMarkdown": "and I'd like to catch up ;-)",
          "votes": 11
        }
      ]
    },
    {
      "id": 1487386,
      "postDate": "2021-08-23T15:39:24.517Z",
      "content": "<p>I tried to add your work into my pipeline. Hower the AUC is always around 0.5😦…</p>",
      "rawMarkdown": "I tried to add your work into my pipeline. Hower the AUC is always around 0.5😦...",
      "votes": 5,
      "replies": [
        {
          "id": 1488625,
          "postDate": "2021-08-24T12:11:50.530Z",
          "content": "<p>I set CQT trainable=True, AUC is 0.5.</p>",
          "rawMarkdown": "I set CQT trainable=True, AUC is 0.5.",
          "votes": 2
        },
        {
          "id": 1488703,
          "postDate": "2021-08-24T13:19:01.493Z",
          "content": "<p>I also noticed that trainable CQT gives quite bad results.</p>",
          "rawMarkdown": "I also noticed that trainable CQT gives quite bad results.",
          "votes": 2
        },
        {
          "id": 1492122,
          "postDate": "2021-08-26T22:52:27.133Z",
          "content": "<p>I experienced the same behavior. The loss doesn't decrease when the trainable=True</p>",
          "rawMarkdown": "I experienced the same behavior. The loss doesn't decrease when the trainable=True"
        },
        {
          "id": 1516587,
          "postDate": "2021-09-18T13:38:01.623Z",
          "content": "<p>Is this still the same or has anyone figure how to make <code>trainable=True</code> work for them? I understand if no one wants to share now, we will see after the end. 👌</p>",
          "rawMarkdown": "Is this still the same or has anyone figure how to make `trainable=True` work for them? I understand if no one wants to share now, we will see after the end. 👌"
        },
        {
          "id": 1516775,
          "postDate": "2021-09-18T17:27:17.250Z",
          "content": "<p>Tried with trainable:</p>\n<pre><code>Epoch 1 - Score: 0.8622\nEpoch 1 - Save Best Score: 0.8622 Model\nEpoch 1 - Save Best Loss: 0.4206 Model\nEpoch 2 - Score: 0.8670\nEpoch 2 - Save Best Score: 0.8670 Model\nEpoch 2 - Save Best Loss: 0.4167 Model\nEpoch 3 - Score: 0.8690\nEpoch 3 - Save Best Score: 0.8690 Model\nEpoch 3 - Save Best Loss: 0.4150 Model\n</code></pre>\n<p>Looks like its converging just fine(?), though it takes 2698s / epoch.</p>\n<p><strong>UPDATE</strong><br>\nLet it ran 3 more epochs and it overfit at #4.</p>",
          "rawMarkdown": "Tried with trainable:\n\n```\nEpoch 1 - Score: 0.8622\nEpoch 1 - Save Best Score: 0.8622 Model\nEpoch 1 - Save Best Loss: 0.4206 Model\nEpoch 2 - Score: 0.8670\nEpoch 2 - Save Best Score: 0.8670 Model\nEpoch 2 - Save Best Loss: 0.4167 Model\nEpoch 3 - Score: 0.8690\nEpoch 3 - Save Best Score: 0.8690 Model\nEpoch 3 - Save Best Loss: 0.4150 Model\n```\n\nLooks like its converging just fine(?), though it takes 2698s / epoch.\n\n**UPDATE**\nLet it ran 3 more epochs and it overfit at #4."
        }
      ]
    },
    {
      "id": 1475260,
      "postDate": "2021-08-16T14:35:46.873Z",
      "content": "<p>Regarding the rescaling. You always want your data to have zero mean and unity standard deviation. This allows deep neural networks to train well, see the famous paper on this: <a href=\"http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf\" target=\"_blank\">http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf</a></p>\n<p>Hope I got youe question correclty.</p>",
      "rawMarkdown": "Regarding the rescaling. You always want your data to have zero mean and unity standard deviation. This allows deep neural networks to train well, see the famous paper on this: http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf\n\nHope I got youe question correclty.",
      "votes": 3
    },
    {
      "id": 1466846,
      "postDate": "2021-08-11T16:47:49.447Z",
      "content": "<p>Could you share the TF implementation of CWT you have been using?</p>\n<p>I found <a href=\"https://github.com/nickgeoca/cwt-tensorflow\" target=\"_blank\">this</a> version and tried implementing it in PyTorch, however, the performance is significantly worse than Q-Transform.</p>\n<p>My PyTorch implementation is <a href=\"https://www.kaggle.com/anjum48/continuous-wavelet-transform-cwt-in-pytorch\" target=\"_blank\">here</a></p>",
      "rawMarkdown": "Could you share the TF implementation of CWT you have been using?\n\nI found [this](https://github.com/nickgeoca/cwt-tensorflow) version and tried implementing it in PyTorch, however, the performance is significantly worse than Q-Transform.\n\nMy PyTorch implementation is [here](https://www.kaggle.com/anjum48/continuous-wavelet-transform-cwt-in-pytorch)",
      "votes": 3,
      "replies": [
        {
          "id": 1467424,
          "postDate": "2021-08-12T01:24:26.667Z",
          "content": "<p>I looked at your pytorch implementation and its great to see original work! You can find my TF implementation here, its based on an unoptimised TF 1.0 implementation</p>\n<pre><code>!pip install git+https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance --no-deps &gt; /dev/null\n</code></pre>\n<p>The repo is a mess as I've not merged all the changes yet. You can find more  information on my work in  the comments below.<br>\nWith regards to your CWT implementation the following might help:</p>\n<ul>\n<li>Vectorising the code to avoid for loops/appends. Take a look at my TF implementation so see how that is done using Covd2D. Note the code takes batches of sample data, i.e. a sample is  (3, 4096). With a GPU I found the optimal batch size was 32 samples (i.e., the tensor is  32, 3, 4096) and the processing time was 0.05ms cf 1.03ms for a CPU, i..e, the GPU is 20x faster!</li>\n<li>Using TPUs I found the next bottleneck was reading the data from many small files. I switched to TFrecords (some links below) and got a 10x speedup.<br>\nWith these optimisation training my NN, (i.e.,  CWT that creates 64x64x3 image and EfficientnetB4) takes 4min for the first epoc and 1.5 min for subsequent epochs.  I've not done a careful comparison however it looks running this on a GPU takes about 10x longer.  <br>\nSo, bottom line:</li>\n<li>Vectorize your code, i.e., remove for loops with appends </li>\n<li>Optimise data reading, i.e., TFrecords.</li>\n<li>Consider TF 2.0 on TPUs</li>\n</ul>",
          "rawMarkdown": " I looked at your pytorch implementation and its great to see original work! You can find my TF implementation here, its based on an unoptimised TF 1.0 implementation\n```\n!pip install git+https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance --no-deps > /dev/null\n```\nThe repo is a mess as I've not merged all the changes yet. You can find more  information on my work in  the comments below.\n\nWith regards to your CWT implementation the following might help:\n- Vectorising the code to avoid for loops/appends. Take a look at my TF implementation so see how that is done using Covd2D. Note the code takes batches of sample data, i.e. a sample is  (3, 4096). With a GPU I found the optimal batch size was 32 samples (i.e., the tensor is  32, 3, 4096) and the processing time was 0.05ms cf 1.03ms for a CPU, i..e, the GPU is 20x faster!\n-  Using TPUs I found the next bottleneck was reading the data from many small files. I switched to TFrecords (some links below) and got a 10x speedup.\n\n\nWith these optimisation training my NN, (i.e.,  CWT that creates 64x64x3 image and EfficientnetB4) takes 4min for the first epoc and 1.5 min for subsequent epochs.  I've not done a careful comparison however it looks running this on a GPU takes about 10x longer.  \n\nSo, bottom line:\n- Vectorize your code, i.e., remove for loops with appends \n- Optimise data reading, i.e., TFrecords.\n- Consider TF 2.0 on TPUs",
          "votes": 8
        },
        {
          "id": 1467928,
          "postDate": "2021-08-12T07:24:34.613Z",
          "content": "<p>Thank you so much for sharing! The 2D conv is a great suggestion, I'll give it a try and let you know how I get on :)</p>",
          "rawMarkdown": "Thank you so much for sharing! The 2D conv is a great suggestion, I'll give it a try and let you know how I get on :)",
          "votes": 3
        },
        {
          "id": 1468180,
          "postDate": "2021-08-12T09:40:57.087Z",
          "content": "<p>Thank you both for sharing so much! So far I have just been using pywt which is quite slow..</p>",
          "rawMarkdown": "Thank you both for sharing so much! So far I have just been using pywt which is quite slow.."
        },
        {
          "id": 1468219,
          "postDate": "2021-08-12T09:59:56.943Z",
          "content": "<p>Seems sensible to me. I started out with PYCBC to get an understanding and quickly prototype an approach, then looked for faster tools.</p>",
          "rawMarkdown": "Seems sensible to me. I started out with PYCBC to get an understanding and quickly prototype an approach, then looked for faster tools.",
          "votes": 2
        },
        {
          "id": 1498875,
          "postDate": "2021-09-01T09:16:38.380Z",
          "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a>  i am getting this error upon using CWT and your TF ds  this peculiarly happens when 7th epoch is about to complete. before that all epoch would run fine. </p>\n<pre><code>OutOfRangeError: 9 root error(s) found.\n  (0) Out of range: {{function_node __inference_train_function_599323}} End of sequence\n     [[{{node IteratorGetNext_6}}]]\n     [[cluster_train_function/_execute_2_0/_91]]\n  (1) Out of range: {{function_node __inference_train_function_599323}} End of sequence\n     [[{{node IteratorGetNext_6}}]]\n  (2) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (3) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (4) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (5) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (6) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (7) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (8) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n0 successful operations.\n</code></pre>\n<p>any help appreciated…</p>\n<p>Thanks in advance. I am not so good in Keras.. its this competition m trying to learn .</p>",
          "rawMarkdown": "@kevinmcisaac  i am getting this error upon using CWT and your TF ds  this peculiarly happens when 7th epoch is about to complete. before that all epoch would run fine. \n\n```\nOutOfRangeError: 9 root error(s) found.\n  (0) Out of range: {{function_node __inference_train_function_599323}} End of sequence\n\t [[{{node IteratorGetNext_6}}]]\n\t [[cluster_train_function/_execute_2_0/_91]]\n  (1) Out of range: {{function_node __inference_train_function_599323}} End of sequence\n\t [[{{node IteratorGetNext_6}}]]\n  (2) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (3) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (4) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (5) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (6) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (7) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (8) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n0 successful operations.\n```\nany help appreciated...\n\nThanks in advance. I am not so good in Keras.. its this competition m trying to learn ."
        },
        {
          "id": 1498904,
          "postDate": "2021-09-01T09:53:27.870Z",
          "content": "<p>I've not see this before. Can you post your code for \"fit\"</p>\n<p>The only thing that I've runing into that was similar is the  need to use drop_remainder with the batches so that every batch is a full batch, </p>\n<p><code>dataset = dataset.batch(batch_size, drop_remainder=drop_remainder)</code></p>",
          "rawMarkdown": "I've not see this before. Can you post your code for \"fit\"\n\nThe only thing that I've runing into that was similar is the  need to use drop_remainder with the batches so that every batch is a full batch, \n\n`dataset = dataset.batch(batch_size, drop_remainder=drop_remainder)`"
        },
        {
          "id": 1499075,
          "postDate": "2021-09-01T12:25:16.890Z",
          "content": "<p>i hope no issues with dataset path we use.I get two gcs paths  that seem to include all files</p>\n<pre><code>with strategy.scope():\n     model = build_model(\n         size=IMAGE_SIZE, \n         efficientnet_size=EFFICIENTNET_SIZE,\n         weights=WEIGHTS, \n         count=train_image_count // BATCH_SIZE // REPLICAS // 4)\n\n model_ckpt = tf.keras.callbacks.ModelCheckpoint(\n     str(SAVEDIR / f\"fold{fold}.h5\"), monitor=\"val_auc\", verbose=1, save_best_only=True,\n     save_weights_only=True, mode=\"max\", save_freq=\"epoch\"\n )\nhistory = model.fit(\n     get_dataset(files_train, labeled=True, batch_size=128,  \n                 buffer_size=tf.data.experimental.AUTOTUNE, drop_remainder=True),\n#         get_dataset(files_train, batch_size=BATCH_SIZE, shuffle=True, repeat=True, aug=True),\n     epochs=EPOCHS,\n     callbacks=[model_ckpt, get_lr_callback(BATCH_SIZE, REPLICAS)],\n     steps_per_epoch=train_image_count // BATCH_SIZE // REPLICAS // 4,\n#         validation_data=get_dataset(files_valid, batch_size=BATCH_SIZE * 4, repeat=True, shuffle=False, aug=True, val=True),\n     validation_data=get_dataset(files_valid, labeled=True, batch_size=BATCH_SIZE * 4, shuffle=False, drop_remainder=False),\n     verbose=1\n )\n</code></pre>\n<p>Below is error log</p>\n<pre><code>37 #         validation_data=get_dataset(files_valid, batch_size=BATCH_SIZE * 4, repeat=True, shuffle=False, aug=True, val=True),\n  38         validation_data=get_dataset(files_valid, labeled=True, batch_size=BATCH_SIZE * 4, shuffle=False, drop_remainder=False),\n---&gt; 39         verbose=1\n  40     )\n  41 \n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)\n1143           epoch_logs.update(val_logs)\n1144 \n-&gt; 1145         callbacks.on_epoch_end(epoch, epoch_logs)\n1146         training_logs = epoch_logs\n1147         if self.stop_training:\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in on_epoch_end(self, epoch, logs)\n 426     for callback in self.callbacks:\n 427       if getattr(callback, '_supports_tf_logs', False):\n--&gt; 428         callback.on_epoch_end(epoch, logs)\n 429       else:\n 430         if numpy_logs is None:  # Only convert once.\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in on_epoch_end(self, epoch, logs)\n1029 \n1030   def on_epoch_end(self, epoch, logs=None):\n-&gt; 1031     self._finalize_progbar(logs, self._train_step)\n1032 \n1033   def on_test_end(self, logs=None):\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in _finalize_progbar(self, logs, counter)\n1086 \n1087   def _finalize_progbar(self, logs, counter):\n-&gt; 1088     logs = tf_utils.to_numpy_or_python_type(logs or {})\n1089     if self.target is None:\n1090       if counter is not None:\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/utils/tf_utils.py in to_numpy_or_python_type(tensors)\n 512     return t  # Don't turn ragged or sparse tensors to NumPy.\n 513 \n--&gt; 514   return nest.map_structure(_to_single_numpy_or_python_type, tensors)\n 515 \n 516 \n/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/nest.py in map_structure(func, *structure, **kwargs)\n 657 \n 658   return pack_sequence_as(\n--&gt; 659       structure[0], [func(*x) for x in entries],\n 660       expand_composites=expand_composites)\n 661 \n/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/nest.py in &lt;listcomp&gt;(.0)\n 657 \n 658   return pack_sequence_as(\n--&gt; 659       structure[0], [func(*x) for x in entries],\n 660       expand_composites=expand_composites)\n 661 \n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/utils/tf_utils.py in _to_single_numpy_or_python_type(t)\n 508   def _to_single_numpy_or_python_type(t):\n 509     if isinstance(t, ops.Tensor):\n--&gt; 510       x = t.numpy()\n 511       return x.item() if np.ndim(x) == 0 else x\n 512     return t  # Don't turn ragged or sparse tensors to NumPy.\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in numpy(self)\n1069     \"\"\"\n1070     # TODO(slebedev): Consider avoiding a copy for non-CPU or remote tensors.\n-&gt; 1071     maybe_arr = self._numpy()  # pylint: disable=protected-access\n1072     return maybe_arr.copy() if isinstance(maybe_arr, np.ndarray) else maybe_arr\n1073 \n/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in _numpy(self)\n1037       return self._numpy_internal()\n1038     except core._NotOkStatusException as e:  # pylint: disable=protected-access\n-&gt; 1039       six.raise_from(core._status_to_exception(e.code, e.message), None)  # pylint: disable=protected-access\n1040 \n1041   @property\n</code></pre>\n<pre><code>tOfRangeError: 9 root error(s) found.\n(0) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n[[Shape_19/_120]]\n(1) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n(2) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n[[GroupCrossDeviceControlEdges_0/Identity_7/_325]]\n(3) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n[[strided_slice_27/_232]]\n(4) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n[[tpu_compile_succeeded_assert/_10601166017813830618/_5/_257]]\n(5) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n[[Pad_5/paddings/_148]]\n(6) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n</code></pre>",
          "rawMarkdown": "   i hope no issues with dataset path we use.I get two gcs paths  that seem to include all files\n \n   ```\nwith strategy.scope():\n        model = build_model(\n            size=IMAGE_SIZE, \n            efficientnet_size=EFFICIENTNET_SIZE,\n            weights=WEIGHTS, \n            count=train_image_count // BATCH_SIZE // REPLICAS // 4)\n    \n    model_ckpt = tf.keras.callbacks.ModelCheckpoint(\n        str(SAVEDIR / f\"fold{fold}.h5\"), monitor=\"val_auc\", verbose=1, save_best_only=True,\n        save_weights_only=True, mode=\"max\", save_freq=\"epoch\"\n    )\n\n history = model.fit(\n        get_dataset(files_train, labeled=True, batch_size=128,  \n                    buffer_size=tf.data.experimental.AUTOTUNE, drop_remainder=True),\n#         get_dataset(files_train, batch_size=BATCH_SIZE, shuffle=True, repeat=True, aug=True),\n        epochs=EPOCHS,\n        callbacks=[model_ckpt, get_lr_callback(BATCH_SIZE, REPLICAS)],\n        steps_per_epoch=train_image_count // BATCH_SIZE // REPLICAS // 4,\n#         validation_data=get_dataset(files_valid, batch_size=BATCH_SIZE * 4, repeat=True, shuffle=False, aug=True, val=True),\n        validation_data=get_dataset(files_valid, labeled=True, batch_size=BATCH_SIZE * 4, shuffle=False, drop_remainder=False),\n        verbose=1\n    )\n```\nBelow is error log\n\n   ```\n  37 #         validation_data=get_dataset(files_valid, batch_size=BATCH_SIZE * 4, repeat=True, shuffle=False, aug=True, val=True),\n     38         validation_data=get_dataset(files_valid, labeled=True, batch_size=BATCH_SIZE * 4, shuffle=False, drop_remainder=False),\n---> 39         verbose=1\n     40     )\n     41 \n\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)\n   1143           epoch_logs.update(val_logs)\n   1144 \n-> 1145         callbacks.on_epoch_end(epoch, epoch_logs)\n   1146         training_logs = epoch_logs\n   1147         if self.stop_training:\n\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in on_epoch_end(self, epoch, logs)\n    426     for callback in self.callbacks:\n    427       if getattr(callback, '_supports_tf_logs', False):\n--> 428         callback.on_epoch_end(epoch, logs)\n    429       else:\n    430         if numpy_logs is None:  # Only convert once.\n\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in on_epoch_end(self, epoch, logs)\n   1029 \n   1030   def on_epoch_end(self, epoch, logs=None):\n-> 1031     self._finalize_progbar(logs, self._train_step)\n   1032 \n   1033   def on_test_end(self, logs=None):\n\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in _finalize_progbar(self, logs, counter)\n   1086 \n   1087   def _finalize_progbar(self, logs, counter):\n-> 1088     logs = tf_utils.to_numpy_or_python_type(logs or {})\n   1089     if self.target is None:\n   1090       if counter is not None:\n\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/utils/tf_utils.py in to_numpy_or_python_type(tensors)\n    512     return t  # Don't turn ragged or sparse tensors to NumPy.\n    513 \n--> 514   return nest.map_structure(_to_single_numpy_or_python_type, tensors)\n    515 \n    516 \n\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/nest.py in map_structure(func, *structure, **kwargs)\n    657 \n    658   return pack_sequence_as(\n--> 659       structure[0], [func(*x) for x in entries],\n    660       expand_composites=expand_composites)\n    661 \n\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/nest.py in <listcomp>(.0)\n    657 \n    658   return pack_sequence_as(\n--> 659       structure[0], [func(*x) for x in entries],\n    660       expand_composites=expand_composites)\n    661 \n\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/utils/tf_utils.py in _to_single_numpy_or_python_type(t)\n    508   def _to_single_numpy_or_python_type(t):\n    509     if isinstance(t, ops.Tensor):\n--> 510       x = t.numpy()\n    511       return x.item() if np.ndim(x) == 0 else x\n    512     return t  # Don't turn ragged or sparse tensors to NumPy.\n\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in numpy(self)\n   1069     \"\"\"\n   1070     # TODO(slebedev): Consider avoiding a copy for non-CPU or remote tensors.\n-> 1071     maybe_arr = self._numpy()  # pylint: disable=protected-access\n   1072     return maybe_arr.copy() if isinstance(maybe_arr, np.ndarray) else maybe_arr\n   1073 \n\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in _numpy(self)\n   1037       return self._numpy_internal()\n   1038     except core._NotOkStatusException as e:  # pylint: disable=protected-access\n-> 1039       six.raise_from(core._status_to_exception(e.code, e.message), None)  # pylint: disable=protected-access\n   1040 \n   1041   @property\n```\n\n```\ntOfRangeError: 9 root error(s) found.\n  (0) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n\t [[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n\t [[Shape_19/_120]]\n  (1) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n\t [[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n  (2) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n\t [[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n\t [[GroupCrossDeviceControlEdges_0/Identity_7/_325]]\n  (3) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n\t [[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n\t [[strided_slice_27/_232]]\n  (4) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n\t [[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n\t [[tpu_compile_succeeded_assert/_10601166017813830618/_5/_257]]\n  (5) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n\t [[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n\t [[Pad_5/paddings/_148]]\n  (6) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n\t [[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n```",
          "votes": -1
        },
        {
          "id": 1499265,
          "postDate": "2021-09-01T14:33:13.873Z",
          "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a>  when i do image counts for valid and train<br>\ni get <br>\n1)1680000 560000</p>\n<p>print(train_image_count,valid_image_count)</p>\n<p>how can we use folds as per your tfrecords set. i get 80 files set..</p>\n<p>2 ) How you performed it there are multiple ways mentioned <br>\n<code>rescales the waveform to [-1, 1]</code></p>",
          "rawMarkdown": "@kevinmcisaac  when i do image counts for valid and train\ni get \n1)1680000 560000\n\nprint(train_image_count,valid_image_count)\n\nhow can we use folds as per your tfrecords set. i get 80 files set..\n\n2 ) How you performed it there are multiple ways mentioned \n`rescales the waveform to [-1, 1]`\n"
        },
        {
          "id": 1514505,
          "postDate": "2021-09-16T06:25:50.023Z",
          "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a>  just a slight reminder. I feel your datasets folds are not built properly if u see above. any suggestion ?</p>",
          "rawMarkdown": "@kevinmcisaac  just a slight reminder. I feel your datasets folds are not built properly if u see above. any suggestion ?"
        }
      ]
    },
    {
      "id": 1505096,
      "postDate": "2021-09-07T00:34:50.220Z",
      "content": "<p>\"Rescaling was essential.\"<br>\nthe reason could be the use of stride=2 in the cnn network (especially the first one)</p>\n<p>by using enlarged image, you could have a sub-pixel convolution?</p>",
      "rawMarkdown": "\"Rescaling was essential.\"\nthe reason could be the use of stride=2 in the cnn network (especially the first one)\n\nby using enlarged image, you could have a sub-pixel convolution?",
      "votes": 2
    },
    {
      "id": 1489163,
      "postDate": "2021-08-24T18:45:28.073Z",
      "content": "<blockquote>\n  <p>Rescaling was essential. I'd be interested to hear from an Kaggel Expert if they found this and if so why?</p>\n</blockquote>\n<p>I guess it's due to original data has very small value(around 1e-20 range), that's why many people divide tha data with max() first to scale to [some value, 1]. </p>",
      "rawMarkdown": "> Rescaling was essential. I'd be interested to hear from an Kaggel Expert if they found this and if so why?\n\nI guess it's due to original data has very small value(around 1e-20 range), that's why many people divide tha data with max() first to scale to [some value, 1]. ",
      "votes": 1
    },
    {
      "id": 1450145,
      "postDate": "2021-08-05T03:51:25.433Z",
      "content": "<p>Any plans on sharing your keras layer of CWT ?</p>",
      "rawMarkdown": "Any plans on sharing your keras layer of CWT ?",
      "replies": [
        {
          "id": 1458576,
          "postDate": "2021-08-08T00:31:18.317Z",
          "content": "<p>I've not had time to clean up the repo, but you can use this<br>\n!pip install git+<a href=\"https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance\" target=\"_blank\">https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance</a> --no-deps &gt; /dev/null</p>\n<p>and there is basic documentation.</p>",
          "rawMarkdown": "I've not had time to clean up the repo, but you can use this\n!pip install git+https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance --no-deps > /dev/null\n\nand there is basic documentation.",
          "votes": 5
        },
        {
          "id": 1459052,
          "postDate": "2021-08-08T07:37:53.680Z",
          "content": "<p>So we have to just feed the npy files to the models by adding this layer ?</p>",
          "rawMarkdown": "So we have to just feed the npy files to the models by adding this layer ?"
        },
        {
          "id": 1460514,
          "postDate": "2021-08-08T23:30:37.480Z",
          "content": "<p>Yes (see earlier comments) though to get the TPU performance you must use TFRecords (see early comments for links to these datasets)</p>",
          "rawMarkdown": "Yes (see earlier comments) though to get the TPU performance you must use TFRecords (see early comments for links to these datasets)",
          "votes": 3
        },
        {
          "id": 1470768,
          "postDate": "2021-08-13T17:48:44.130Z",
          "content": "<p>You can find a Keras CWT layer in <a href=\"https://www.kaggle.com/mistag/wavelet1d-custom-keras-wavelet-transform-layer?scriptVersionId=71528111\" target=\"_blank\">this notebook</a>. No bandpass filtering is required with this one, as it only computes the scaleogram for a frequency range of interest.</p>",
          "rawMarkdown": "You can find a Keras CWT layer in [this notebook](https://www.kaggle.com/mistag/wavelet1d-custom-keras-wavelet-transform-layer?scriptVersionId=71528111). No bandpass filtering is required with this one, as it only computes the scaleogram for a frequency range of interest."
        },
        {
          "id": 1470965,
          "postDate": "2021-08-13T20:23:30.790Z",
          "rawMarkdown": "",
          "votes": 1,
          "isDeleted": true
        }
      ]
    },
    {
      "id": 1559722,
      "postDate": "2021-10-27T07:09:24.783Z",
      "content": "<p>Hey All,</p>\n<p>Thank you all for taking part in our competition. The participation has been overwhelmingly positive. We are currently conducting a survey to gauge the demographic and outreach achieved. Kindly spare 2min and fill in this survey <a href=\"https://forms.gle/QP9L16niPexozyhu5\" target=\"_blank\">https://forms.gle/QP9L16niPexozyhu5</a>.</p>\n<p>Thank you all,</p>\n<p>Regards,<br>\nChris</p>",
      "rawMarkdown": "Hey All,\n\nThank you all for taking part in our competition. The participation has been overwhelmingly positive. We are currently conducting a survey to gauge the demographic and outreach achieved. Kindly spare 2min and fill in this survey https://forms.gle/QP9L16niPexozyhu5.\n\nThank you all,\n\nRegards,\nChris"
    },
    {
      "id": 1504887,
      "postDate": "2021-09-06T18:37:49.603Z",
      "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> nice work! may I ask what does the parameter <code>wavelet_width: default = 1</code> in CWT ? what range of values should we consider ? <br>\nI saw the demo in your git repo where it uses 1, but not sure if that is the case for our data here</p>",
      "rawMarkdown": "@kevinmcisaac nice work! may I ask what does the parameter `wavelet_width: default = 1` in CWT ? what range of values should we consider ? \nI saw the demo in your git repo where it uses 1, but not sure if that is the case for our data here"
    },
    {
      "id": 1499318,
      "postDate": "2021-09-01T15:09:16.090Z",
      "content": "<p>Thanks for sharing <a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> , may I ask what do you mean by \"rescales the waveform to [-1, 1]\"? It's like standardize as -mean and /std, or min/max to [0, 1] then scale and shift to [-1, 1]? Thanks.</p>",
      "rawMarkdown": "Thanks for sharing @kevinmcisaac , may I ask what do you mean by \"rescales the waveform to [-1, 1]\"? It's like standardize as -mean and /std, or min/max to [0, 1] then scale and shift to [-1, 1]? Thanks.",
      "replies": [
        {
          "id": 1499842,
          "postDate": "2021-09-02T01:22:00.070Z",
          "content": "<p>Its Min/Max</p>",
          "rawMarkdown": "Its Min/Max",
          "votes": 1
        }
      ]
    },
    {
      "id": 1495884,
      "postDate": "2021-08-29T21:25:53.740Z",
      "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> Can you guide me what is bandpass filter and CWT</p>",
      "rawMarkdown": " @kevinmcisaac Can you guide me what is bandpass filter and CWT",
      "replies": [
        {
          "id": 1495948,
          "postDate": "2021-08-30T00:15:50.607Z",
          "content": "<p>Your best option is to do some reading on the internet.<br>\n<a href=\"https://en.wikipedia.org/wiki/Band-pass_filter\" target=\"_blank\">https://en.wikipedia.org/wiki/Band-pass_filter</a><br>\n<a href=\"https://www.kaggle.com/asauve/a-gentle-introduction-to-wavelet-for-data-analysis\" target=\"_blank\">https://www.kaggle.com/asauve/a-gentle-introduction-to-wavelet-for-data-analysis</a></p>\n<p>In short a filter removes some frequencies from a wave and a band pass only allows frequencies in the band to pass.</p>\n<p>A CWT is an alternative approach to Short Term Fourier Transform or Constant Quality Transform to converting a wave from time/amplitude to time/Frequency</p>",
          "rawMarkdown": "Your best option is to do some reading on the internet.\nhttps://en.wikipedia.org/wiki/Band-pass_filter\nhttps://www.kaggle.com/asauve/a-gentle-introduction-to-wavelet-for-data-analysis\n\nIn short a filter removes some frequencies from a wave and a band pass only allows frequencies in the band to pass.\n\nA CWT is an alternative approach to Short Term Fourier Transform or Constant Quality Transform to converting a wave from time/amplitude to time/Frequency",
          "votes": 1
        }
      ]
    },
    {
      "id": 1490958,
      "postDate": "2021-08-26T03:31:55.107Z",
      "content": "<p>I have learned a lot from your summary!</p>",
      "rawMarkdown": "I have learned a lot from your summary!"
    },
    {
      "id": 1485990,
      "postDate": "2021-08-22T14:59:01.930Z",
      "content": "<p>Hello, how is your single model's lb and cv?</p>",
      "rawMarkdown": "Hello, how is your single model's lb and cv?"
    },
    {
      "id": 1480712,
      "postDate": "2021-08-19T06:31:35.727Z",
      "content": "<p>Good post. Thanks for sharing your inputs. Well written indeed! <a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> 👍</p>",
      "rawMarkdown": "Good post. Thanks for sharing your inputs. Well written indeed! @kevinmcisaac 👍"
    },
    {
      "id": 1478898,
      "postDate": "2021-08-18T07:26:34.500Z",
      "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a>  does the order Bandpass filter makes any difference, Like apply CQT then BandPass </p>",
      "rawMarkdown": "@kevinmcisaac  does the order Bandpass filter makes any difference, Like apply CQT then BandPass "
    },
    {
      "id": 1478581,
      "postDate": "2021-08-18T04:16:57.947Z",
      "content": "<p>I thought b7 on 512x512 would cause memory issue on many GPUs. Mind sharing GPUs you are using?</p>",
      "rawMarkdown": "I thought b7 on 512x512 would cause memory issue on many GPUs. Mind sharing GPUs you are using?",
      "replies": [
        {
          "id": 1478728,
          "postDate": "2021-08-18T05:51:12.157Z",
          "content": "<p>I've been running on a TPU and find I get better performance, say 10-20x</p>",
          "rawMarkdown": "I've been running on a TPU and find I get better performance, say 10-20x",
          "votes": 1
        }
      ]
    },
    {
      "id": 1464254,
      "postDate": "2021-08-10T14:01:40.647Z",
      "content": "<p>Than you for sharing </p>",
      "rawMarkdown": "Than you for sharing "
    },
    {
      "id": 1461695,
      "postDate": "2021-08-09T14:19:55.917Z",
      "content": "<p>Good work. <a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> </p>",
      "rawMarkdown": "Good work. @kevinmcisaac "
    },
    {
      "id": 1459244,
      "postDate": "2021-08-08T09:37:33.613Z",
      "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> Hey Thanks for the detailed approach overview.<br>\nI just had a doubt. At what step are you resizing the scalograms?</p>\n<p><code>.npy files -&gt; CQT (keras layer) -&gt; Resizing (?) -&gt; EFN Model (keras model)</code></p>\n<p>Won't this be a bottleneck here?</p>",
      "rawMarkdown": "@kevinmcisaac Hey Thanks for the detailed approach overview.\nI just had a doubt. At what step are you resizing the scalograms?\n\n``` .npy files -> CQT (keras layer) -> Resizing (?) -> EFN Model (keras model) ```\n\nWon't this be a bottleneck here?",
      "replies": [
        {
          "id": 1460496,
          "postDate": "2021-08-08T23:09:08.840Z",
          "content": "<p><a href=\"https://www.kaggle.com/yerramvarun\" target=\"_blank\">@yerramvarun</a> I don't resize the CWT for the EFN. My model looks like</p>\n<p><code>\n model = tf.keras.Sequential([L.InputLayer(input_shape=(3, 4096),\n                                     ComplexMorletCWT(n_scales = 64, stride=64, \n                                                                         output='magnitude', data_format='channels_first'), \n                                     L.Permute((2, 3, 1)), # transpose to channel last [:, time, n_scales, channels]\n                                     efn.EfficientnetB4(include_top=False,weights='imagenet'),\n                                     L.GlobalAveragePooling2D(),\n                                     L.Dense(32,activation='relu'),\n                                     L.Dense(1, activation='sigmoid')\n                                    ])\n</code><br>\nI guess you are asking at the Keras documentation for EFN states each model uses a specific size. I found this confusing and discovered they worked Ok with other sizes. I'd be interested to hear from someone with more experience about this?</p>\n<p>Note: I'm using Continuious Wavelett Transfroms (CWT) not CQT using the keras layer in this<br>\n!pip install git+<a href=\"https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance\" target=\"_blank\">https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance</a> --no-deps &gt; /dev/null</p>",
          "rawMarkdown": "@yerramvarun I don't resize the CWT for the EFN. My model looks like\n\n`\n model = tf.keras.Sequential([L.InputLayer(input_shape=(3, 4096),\n                                     ComplexMorletCWT(n_scales = 64, stride=64, \n                                                                         output='magnitude', data_format='channels_first'), \n                                     L.Permute((2, 3, 1)), # transpose to channel last [:, time, n_scales, channels]\n                                     efn.EfficientnetB4(include_top=False,weights='imagenet'),\n                                     L.GlobalAveragePooling2D(),\n                                     L.Dense(32,activation='relu'),\n                                     L.Dense(1, activation='sigmoid')\n                                    ])\n`\nI guess you are asking at the Keras documentation for EFN states each model uses a specific size. I found this confusing and discovered they worked Ok with other sizes. I'd be interested to hear from someone with more experience about this?\n\nNote: I'm using Continuious Wavelett Transfroms (CWT) not CQT using the keras layer in this\n!pip install git+https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance --no-deps > /dev/null",
          "votes": 4
        },
        {
          "id": 1460727,
          "postDate": "2021-08-09T03:48:03.490Z",
          "rawMarkdown": "",
          "votes": 1,
          "isDeleted": true
        },
        {
          "id": 1461285,
          "postDate": "2021-08-09T10:18:10.603Z",
          "content": "<p>That makes sense. Thanks for clearing that up for me</p>",
          "rawMarkdown": "That makes sense. Thanks for clearing that up for me",
          "votes": 2
        },
        {
          "id": 1494194,
          "postDate": "2021-08-28T13:36:27.907Z",
          "content": "<p>where do you resize your image to different square sizes <a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> </p>",
          "rawMarkdown": "where do you resize your image to different square sizes @kevinmcisaac "
        },
        {
          "id": 1495919,
          "postDate": "2021-08-29T22:40:10.310Z",
          "content": "<p>I use the n_scales and strides parameters to determine the size of the image, e.g., n_scales = 128, stride=32 creates a spectrogram that is 128x128. While efficient net was trained on specific image sizes, it can accept any size.</p>",
          "rawMarkdown": "I use the n_scales and strides parameters to determine the size of the image, e.g., n_scales = 128, stride=32 creates a spectrogram that is 128x128. While efficient net was trained on specific image sizes, it can accept any size."
        },
        {
          "id": 1495924,
          "postDate": "2021-08-29T22:55:35.327Z",
          "content": "<p>Let's say you want image of WIDTH x HEIGHT size. Then you should set  <code>n_scales=WIDTH</code>, and <code>strides = int(np.ceil(4096/HEIGHT))</code> (assuming your input has (3, 4096) shape). This works for me.</p>",
          "rawMarkdown": "Let's say you want image of WIDTH x HEIGHT size. Then you should set  `n_scales=WIDTH`, and `strides = int(np.ceil(4096/HEIGHT))` (assuming your input has (3, 4096) shape). This works for me.",
          "votes": 3
        }
      ]
    },
    {
      "id": 1456944,
      "postDate": "2021-08-07T06:54:51.320Z",
      "content": "<blockquote>\n  <p>I started with nnAudio Constant Quality Transform (CQT) and found this a lot faster than librosa. The entire processing, i.e., load the data, bandpass filter, creating the a 64x64 scalogram in nnAUdio and classifying in EFN B4 took about 8hrs on a CPU and 2hrs on a GPU. </p>\n</blockquote>\n<p>can you tell me how many epochs you did in 2 hours you mentioned ?</p>",
      "rawMarkdown": "> I started with nnAudio Constant Quality Transform (CQT) and found this a lot faster than librosa. The entire processing, i.e., load the data, bandpass filter, creating the a 64x64 scalogram in nnAUdio and classifying in EFN B4 took about 8hrs on a CPU and 2hrs on a GPU. \n\ncan you tell me how many epochs you did in 2 hours you mentioned ?",
      "replies": [
        {
          "id": 1458555,
          "postDate": "2021-08-08T00:08:40.940Z",
          "content": "<p>My notes are not the best for the old  nnAudio runs. For recent runs with a CWT that create an 64x64 image and B4 I get the following<br>\nTPU 32s per epoch, ran 30 epochs. <br>\nGPU 260s per epoch,   29 epochs </p>\n<p>The total notebook time, including set and inferencing was 28 min and 2hrs 14 respectively.</p>",
          "rawMarkdown": "My notes are not the best for the old  nnAudio runs. For recent runs with a CWT that create an 64x64 image and B4 I get the following\nTPU 32s per epoch, ran 30 epochs. \nGPU 260s per epoch,   29 epochs \n\nThe total notebook time, including set and inferencing was 28 min and 2hrs 14 respectively.\n\n",
          "votes": 2
        },
        {
          "id": 1458814,
          "postDate": "2021-08-08T04:51:42.973Z",
          "content": "<p>Thanks! Can you tell me how you optimized the preprocessing / process of conversion to TFrecords ? When I was trying to do some custom preprocessing and trying to convert them to TFrecords, each notebook had only 5GB output size. So, it will take me 16 runs, each around 4GB. This seems to be a bottleneck. </p>",
          "rawMarkdown": "Thanks! Can you tell me how you optimized the preprocessing / process of conversion to TFrecords ? When I was trying to do some custom preprocessing and trying to convert them to TFrecords, each notebook had only 5GB output size. So, it will take me 16 runs, each around 4GB. This seems to be a bottleneck. "
        },
        {
          "id": 1460513,
          "postDate": "2021-08-08T23:28:43.087Z",
          "content": "<p>I found I could do this as three batches; 2 for train and 1 for submissions.  </p>\n<p>These are  public datasets named like this <a href=\"https://www.kaggle.com/kevinmcisaac/g2net-tfrecords-with-20500hz-bandpass\" target=\"_blank\">G2NET TFRecords with 20-500Hz bandpass Part I</a></p>\n<p>You can then look at the notebook that generated this which  use this <a href=\"https://www.kaggle.com/kevinmcisaac/g2nettfrec\" target=\"_blank\">utility script</a></p>",
          "rawMarkdown": "I found I could do this as three batches; 2 for train and 1 for submissions.  \n\nThese are  public datasets named like this [G2NET TFRecords with 20-500Hz bandpass Part I](https://www.kaggle.com/kevinmcisaac/g2net-tfrecords-with-20500hz-bandpass)\n\nYou can then look at the notebook that generated this which  use this [utility script](https://www.kaggle.com/kevinmcisaac/g2nettfrec)",
          "votes": 2
        },
        {
          "id": 1467960,
          "postDate": "2021-08-12T07:41:29.597Z",
          "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> can you tell me how many training samples are in each tfrecord of your dataset ? I can't seem to find any number from your utility script</p>",
          "rawMarkdown": "@kevinmcisaac can you tell me how many training samples are in each tfrecord of your dataset ? I can't seem to find any number from your utility script"
        },
        {
          "id": 1468089,
          "postDate": "2021-08-12T09:00:06.677Z",
          "content": "<p>Rather than pick a number of samples per TFR The approach  I used was to create a specific number of TFrecord files so that each was large enough to get good read performance and there were enough file to enable overlapping parallel reads.  </p>\n<p>You can see in the notebook I created 70 files so each trf file has  560000/70 = 8,000 samples</p>",
          "rawMarkdown": "Rather than pick a number of samples per TFR The approach  I used was to create a specific number of TFrecord files so that each was large enough to get good read performance and there were enough file to enable overlapping parallel reads.  \n\nYou can see in the notebook I created 70 files so each trf file has  560000/70 = 8,000 samples",
          "votes": 2
        },
        {
          "id": 1468528,
          "postDate": "2021-08-12T13:06:55.060Z",
          "rawMarkdown": "",
          "isDeleted": true
        },
        {
          "id": 1469484,
          "postDate": "2021-08-13T01:02:39.323Z",
          "content": "<p>I converted the inputs to np.float32 as part of the preprocessing.  Having read <a href=\"https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus\" target=\"_blank\">this</a> I now understand why you are asking a however not familiar enough with TF 2.0 to be able to answer the question of using mixed precision.</p>\n<p>If you have the skills you could fork the repo and make the necessary changes. I'd be keen to hear how that goes.</p>",
          "rawMarkdown": "I converted the inputs to np.float32 as part of the preprocessing.  Having read [this](https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus) I now understand why you are asking a however not familiar enough with TF 2.0 to be able to answer the question of using mixed precision.\n\nIf you have the skills you could fork the repo and make the necessary changes. I'd be keen to hear how that goes.",
          "votes": 1
        },
        {
          "id": 1471865,
          "postDate": "2021-08-14T14:16:33.637Z",
          "rawMarkdown": "",
          "votes": 1,
          "isDeleted": true
        }
      ]
    },
    {
      "id": 1452494,
      "postDate": "2021-08-05T16:11:29.170Z",
      "content": "<p>Can you tell which package you used for making a bandpass filter?</p>",
      "rawMarkdown": "Can you tell which package you used for making a bandpass filter?",
      "replies": [
        {
          "id": 1452559,
          "postDate": "2021-08-05T16:28:27.047Z",
          "rawMarkdown": "",
          "votes": 3,
          "isDeleted": true
        },
        {
          "id": 1458564,
          "postDate": "2021-08-08T00:16:35.877Z",
          "content": "<p>I used scipy.signal.  Here is the code I used.</p>\n<pre><code>from scipy import signal\n\nbHP, aHP = signal.butter(8, (20, 500), btype='bandpass', fs= 2048)\ndef filterSig(waves, a=aHP, b=bHP):\n    '''Apply a 20Hz high pass filter to the three events'''\n    return np.array([signal.filtfilt(b, a, wave) for wave in waves]) #lfilter introduces a larger spike around 20hz\n</code></pre>\n<p>Initially issued gwpy but its a lot of baggage just to do a simple filter.  I use this in a pre-processing step that re-writes the data s TFrecords to speed up data loading and keep the TPUs busy.</p>\n<p>What I'd like to do is make a bandpass filter in Keras and include that in my NN</p>",
          "rawMarkdown": "I used scipy.signal.  Here is the code I used.\n```\nfrom scipy import signal\n\nbHP, aHP = signal.butter(8, (20, 500), btype='bandpass', fs= 2048)\ndef filterSig(waves, a=aHP, b=bHP):\n    '''Apply a 20Hz high pass filter to the three events'''\n    return np.array([signal.filtfilt(b, a, wave) for wave in waves]) #lfilter introduces a larger spike around 20hz\n```\n\nInitially issued gwpy but its a lot of baggage just to do a simple filter.  I use this in a pre-processing step that re-writes the data s TFrecords to speed up data loading and keep the TPUs busy.\n\nWhat I'd like to do is make a bandpass filter in Keras and include that in my NN",
          "votes": 10
        },
        {
          "id": 1459232,
          "postDate": "2021-08-08T09:30:52.680Z",
          "content": "<p>I think for a 20-500Hz cuts you need to use something like:</p>\n<pre><code>nyq = 0.5 * fs  # Nyquist frequency\nlow = 20 / nyq\nhigh = 500 / nyq\nb, a = butter(order, [low, high], btype='bandpass')\n</code></pre>\n<p>From: <a href=\"https://scipy-cookbook.readthedocs.io/items/ButterworthBandpass.html\" target=\"_blank\">https://scipy-cookbook.readthedocs.io/items/ButterworthBandpass.html</a></p>\n<p>Edit: I just found out that if you pass the <code>fs</code> arg, you don't need to do this :)</p>",
          "rawMarkdown": "I think for a 20-500Hz cuts you need to use something like:\n```\nnyq = 0.5 * fs  # Nyquist frequency\nlow = 20 / nyq\nhigh = 500 / nyq\nb, a = butter(order, [low, high], btype='bandpass')\n```\nFrom: https://scipy-cookbook.readthedocs.io/items/ButterworthBandpass.html\n\nEdit: I just found out that if you pass the `fs` arg, you don't need to do this :)",
          "votes": 9
        },
        {
          "id": 1463688,
          "postDate": "2021-08-10T09:33:20.680Z",
          "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> should this be applied before or after normalization ?</p>",
          "rawMarkdown": "@kevinmcisaac should this be applied before or after normalization ?",
          "votes": 1
        },
        {
          "id": 1463981,
          "postDate": "2021-08-10T12:07:08.570Z",
          "content": "<p>I applied the scaling after the bandpass filter but I don't think the order matter.  </p>",
          "rawMarkdown": "I applied the scaling after the bandpass filter but I don't think the order matter.  ",
          "votes": 1
        },
        {
          "id": 1464039,
          "postDate": "2021-08-10T12:29:37.577Z",
          "content": "<p>Just tried both after and before scaling. They both look the same</p>",
          "rawMarkdown": "Just tried both after and before scaling. They both look the same",
          "votes": 2
        },
        {
          "id": 1464081,
          "postDate": "2021-08-10T12:47:05.490Z",
          "content": "<p>Good to know</p>",
          "rawMarkdown": "Good to know",
          "votes": 3
        },
        {
          "id": 1464124,
          "postDate": "2021-08-10T13:06:32.067Z",
          "rawMarkdown": "",
          "votes": 2,
          "isDeleted": true
        },
        {
          "id": 1465337,
          "postDate": "2021-08-11T02:33:43.033Z",
          "content": "<p>Yes I did. The results are reported <a href=\"https://www.kaggle.com/c/g2net-gravitational-wave-detection/discussion/252396\" target=\"_blank\">here</a>.<br>\nTL;DR i make the AUC 10% worse.</p>",
          "rawMarkdown": "Yes I did. The results are reported [here](https://www.kaggle.com/c/g2net-gravitational-wave-detection/discussion/252396).\nTL;DR i make the AUC 10% worse.",
          "votes": 3
        },
        {
          "id": 1483732,
          "postDate": "2021-08-20T20:15:13.830Z",
          "content": "<p>Thanks to all who replied. This info is quite useful.</p>",
          "rawMarkdown": "Thanks to all who replied. This info is quite useful.",
          "votes": 1
        }
      ]
    },
    {
      "id": 1497459,
      "postDate": "2021-08-31T08:03:53.073Z",
      "rawMarkdown": "",
      "isDeleted": true,
      "replies": [
        {
          "id": 1497469,
          "postDate": "2021-08-31T08:12:45.913Z",
          "content": "<p>No, I change the size of n_scales and or stride to create the desired sized scalogram, e.g, </p>\n<blockquote>\n  <p>ComplexMorletCWT(n_scales = 64, stride=64)</p>\n</blockquote>\n<p>creates a 64 x 64 image.</p>\n<ul>\n<li>n_scales determines how many samples we take in the frequencey axis ie 64<ul>\n<li>stride termines how many time steps to move for each claculation. Since the signals length is 4096, a stride of 64 means we will have 4096/64 = 64 sample on the time axis</li></ul></li>\n</ul>",
          "rawMarkdown": "No, I change the size of n_scales and or stride to create the desired sized scalogram, e.g, \n\n> ComplexMorletCWT(n_scales = 64, stride=64)\n\ncreates a 64 x 64 image.\n * n_scales determines how many samples we take in the frequencey axis ie 64\n*  stride termines how many time steps to move for each claculation. Since the signals length is 4096, a stride of 64 means we will have 4096/64 = 64 sample on the time axis\n",
          "votes": 3
        },
        {
          "id": 1497494,
          "postDate": "2021-08-31T08:36:45.847Z",
          "rawMarkdown": "",
          "isDeleted": true
        }
      ]
    },
    {
      "id": 1464122,
      "postDate": "2021-08-10T13:05:54.923Z",
      "rawMarkdown": "",
      "isDeleted": true
    },
    {
      "id": 1460735,
      "postDate": "2021-08-09T03:55:08.823Z",
      "rawMarkdown": "",
      "votes": 1,
      "isDeleted": true,
      "replies": [
        {
          "id": 1474806,
          "postDate": "2021-08-16T09:21:23.033Z",
          "content": "<p>I simply divided by a fixed scale factor, i.e., the same number for each channel (detector) and all samples.  </p>\n<p>I started out by dividing each channel by the max of the absolute value of that channel, i.e., standardize into the range [-1,1] but then I thought this might lose some important information so I switch to a common number across all.  Since there is a large dynamic range across the various samples, and across teh detectors, I just picked something that seemed reasonable for many samples (i.e., more art than science).</p>",
          "rawMarkdown": "I simply divided by a fixed scale factor, i.e., the same number for each channel (detector) and all samples.  \n\nI started out by dividing each channel by the max of the absolute value of that channel, i.e., standardize into the range [-1,1] but then I thought this might lose some important information so I switch to a common number across all.  Since there is a large dynamic range across the various samples, and across teh detectors, I just picked something that seemed reasonable for many samples (i.e., more art than science).",
          "votes": 4
        }
      ]
    },
    {
      "id": 1451854,
      "postDate": "2021-08-05T12:59:10.630Z",
      "rawMarkdown": "",
      "votes": 2,
      "isDeleted": true,
      "replies": [
        {
          "id": 1452016,
          "postDate": "2021-08-05T13:55:38.030Z",
          "rawMarkdown": "",
          "votes": 2,
          "isDeleted": true
        },
        {
          "id": 1458574,
          "postDate": "2021-08-08T00:30:34.733Z",
          "content": "<p>I've not tried ENetV2 yet. How much improvement did you get, i.e., %? </p>",
          "rawMarkdown": "I've not tried ENetV2 yet. How much improvement did you get, i.e., %? ",
          "votes": 1
        },
        {
          "id": 1459249,
          "postDate": "2021-08-08T09:40:25.407Z",
          "rawMarkdown": "",
          "votes": 1,
          "isDeleted": true
        },
        {
          "id": 1478994,
          "postDate": "2021-08-18T08:33:41.167Z",
          "content": "<p>How was efficientnetv2 XL comparable to efficientnet B7 ?</p>",
          "rawMarkdown": "How was efficientnetv2 XL comparable to efficientnet B7 ?",
          "votes": 1
        }
      ]
    },
    {
      "id": 1473217,
      "postDate": "2021-08-15T12:40:49.160Z",
      "content": "<p>Thanks for sharing!</p>",
      "rawMarkdown": "Thanks for sharing!"
    },
    {
      "id": 1464152,
      "postDate": "2021-08-10T13:15:57.927Z",
      "content": "<p>Thanks for sharing ! 😁😁</p>",
      "rawMarkdown": "Thanks for sharing ! 😁😁"
    },
    {
      "id": 1455557,
      "postDate": "2021-08-06T15:51:22.947Z",
      "content": "<p>Thanks for sharing your insights </p>",
      "rawMarkdown": "Thanks for sharing your insights "
    },
    {
      "id": 1454015,
      "postDate": "2021-08-06T04:32:03.510Z",
      "content": "<p>Thanks for sharing!</p>",
      "rawMarkdown": "Thanks for sharing!\n"
    }
  ],
  "comments": [
    {
      "id": 1454700,
      "author_name": "CPMP",
      "author_url": "",
      "post_date": "2021-08-06T09:49:59.203000",
      "content": "<p>Good work.</p>\n<p>You're not just tweaking public notebooks.  This is how to make a difference here.  Keep pushing (but not too hard, I'd like to stay ahead of you … )</p>",
      "votes": 21,
      "replies": [
        {
          "id": 1458571,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-08T00:28:43.560000",
          "content": "<p>and I'd like to catch up ;-)</p>",
          "votes": 11,
          "replies": []
        }
      ]
    },
    {
      "id": 1487386,
      "author_name": "toxu",
      "author_url": "",
      "post_date": "2021-08-23T15:39:24.517000",
      "content": "<p>I tried to add your work into my pipeline. Hower the AUC is always around 0.5😦…</p>",
      "votes": 5,
      "replies": [
        {
          "id": 1488625,
          "author_name": "Correlation",
          "author_url": "",
          "post_date": "2021-08-24T12:11:50.530000",
          "content": "<p>I set CQT trainable=True, AUC is 0.5.</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1488703,
          "author_name": "Araik Tamazian",
          "author_url": "",
          "post_date": "2021-08-24T13:19:01.493000",
          "content": "<p>I also noticed that trainable CQT gives quite bad results.</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1492122,
          "author_name": "Sinan Calisir",
          "author_url": "",
          "post_date": "2021-08-26T22:52:27.133000",
          "content": "<p>I experienced the same behavior. The loss doesn't decrease when the trainable=True</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1516587,
          "author_name": "Yassine Alouini",
          "author_url": "",
          "post_date": "2021-09-18T13:38:01.623000",
          "content": "<p>Is this still the same or has anyone figure how to make <code>trainable=True</code> work for them? I understand if no one wants to share now, we will see after the end. 👌</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1516775,
          "author_name": "عثمان",
          "author_url": "",
          "post_date": "2021-09-18T17:27:17.250000",
          "content": "<p>Tried with trainable:</p>\n<pre><code>Epoch 1 - Score: 0.8622\nEpoch 1 - Save Best Score: 0.8622 Model\nEpoch 1 - Save Best Loss: 0.4206 Model\nEpoch 2 - Score: 0.8670\nEpoch 2 - Save Best Score: 0.8670 Model\nEpoch 2 - Save Best Loss: 0.4167 Model\nEpoch 3 - Score: 0.8690\nEpoch 3 - Save Best Score: 0.8690 Model\nEpoch 3 - Save Best Loss: 0.4150 Model\n</code></pre>\n<p>Looks like its converging just fine(?), though it takes 2698s / epoch.</p>\n<p><strong>UPDATE</strong><br>\nLet it ran 3 more epochs and it overfit at #4.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1475260,
      "author_name": "sapor",
      "author_url": "",
      "post_date": "2021-08-16T14:35:46.873000",
      "content": "<p>Regarding the rescaling. You always want your data to have zero mean and unity standard deviation. This allows deep neural networks to train well, see the famous paper on this: <a href=\"http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf\" target=\"_blank\">http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf</a></p>\n<p>Hope I got youe question correclty.</p>",
      "votes": 3,
      "replies": []
    },
    {
      "id": 1466846,
      "author_name": "datasaurus",
      "author_url": "",
      "post_date": "2021-08-11T16:47:49.447000",
      "content": "<p>Could you share the TF implementation of CWT you have been using?</p>\n<p>I found <a href=\"https://github.com/nickgeoca/cwt-tensorflow\" target=\"_blank\">this</a> version and tried implementing it in PyTorch, however, the performance is significantly worse than Q-Transform.</p>\n<p>My PyTorch implementation is <a href=\"https://www.kaggle.com/anjum48/continuous-wavelet-transform-cwt-in-pytorch\" target=\"_blank\">here</a></p>",
      "votes": 3,
      "replies": [
        {
          "id": 1467424,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-12T01:24:26.667000",
          "content": "<p>I looked at your pytorch implementation and its great to see original work! You can find my TF implementation here, its based on an unoptimised TF 1.0 implementation</p>\n<pre><code>!pip install git+https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance --no-deps &gt; /dev/null\n</code></pre>\n<p>The repo is a mess as I've not merged all the changes yet. You can find more  information on my work in  the comments below.<br>\nWith regards to your CWT implementation the following might help:</p>\n<ul>\n<li>Vectorising the code to avoid for loops/appends. Take a look at my TF implementation so see how that is done using Covd2D. Note the code takes batches of sample data, i.e. a sample is  (3, 4096). With a GPU I found the optimal batch size was 32 samples (i.e., the tensor is  32, 3, 4096) and the processing time was 0.05ms cf 1.03ms for a CPU, i..e, the GPU is 20x faster!</li>\n<li>Using TPUs I found the next bottleneck was reading the data from many small files. I switched to TFrecords (some links below) and got a 10x speedup.<br>\nWith these optimisation training my NN, (i.e.,  CWT that creates 64x64x3 image and EfficientnetB4) takes 4min for the first epoc and 1.5 min for subsequent epochs.  I've not done a careful comparison however it looks running this on a GPU takes about 10x longer.  <br>\nSo, bottom line:</li>\n<li>Vectorize your code, i.e., remove for loops with appends </li>\n<li>Optimise data reading, i.e., TFrecords.</li>\n<li>Consider TF 2.0 on TPUs</li>\n</ul>",
          "votes": 8,
          "replies": []
        },
        {
          "id": 1467928,
          "author_name": "datasaurus",
          "author_url": "",
          "post_date": "2021-08-12T07:24:34.613000",
          "content": "<p>Thank you so much for sharing! The 2D conv is a great suggestion, I'll give it a try and let you know how I get on :)</p>",
          "votes": 3,
          "replies": []
        },
        {
          "id": 1468180,
          "author_name": "Hannes Öhler",
          "author_url": "",
          "post_date": "2021-08-12T09:40:57.087000",
          "content": "<p>Thank you both for sharing so much! So far I have just been using pywt which is quite slow..</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1468219,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-12T09:59:56.943000",
          "content": "<p>Seems sensible to me. I started out with PYCBC to get an understanding and quickly prototype an approach, then looked for faster tools.</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1498875,
          "author_name": "Jaideep",
          "author_url": "",
          "post_date": "2021-09-01T09:16:38.380000",
          "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a>  i am getting this error upon using CWT and your TF ds  this peculiarly happens when 7th epoch is about to complete. before that all epoch would run fine. </p>\n<pre><code>OutOfRangeError: 9 root error(s) found.\n  (0) Out of range: {{function_node __inference_train_function_599323}} End of sequence\n     [[{{node IteratorGetNext_6}}]]\n     [[cluster_train_function/_execute_2_0/_91]]\n  (1) Out of range: {{function_node __inference_train_function_599323}} End of sequence\n     [[{{node IteratorGetNext_6}}]]\n  (2) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (3) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (4) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (5) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (6) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (7) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n  (8) Cancelled: {{function_node __inference_train_function_599323}} Function was cancelled before it was started\n0 successful operations.\n</code></pre>\n<p>any help appreciated…</p>\n<p>Thanks in advance. I am not so good in Keras.. its this competition m trying to learn .</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1498904,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-09-01T09:53:27.870000",
          "content": "<p>I've not see this before. Can you post your code for \"fit\"</p>\n<p>The only thing that I've runing into that was similar is the  need to use drop_remainder with the batches so that every batch is a full batch, </p>\n<p><code>dataset = dataset.batch(batch_size, drop_remainder=drop_remainder)</code></p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1499075,
          "author_name": "Jaideep",
          "author_url": "",
          "post_date": "2021-09-01T12:25:16.890000",
          "content": "<p>i hope no issues with dataset path we use.I get two gcs paths  that seem to include all files</p>\n<pre><code>with strategy.scope():\n     model = build_model(\n         size=IMAGE_SIZE, \n         efficientnet_size=EFFICIENTNET_SIZE,\n         weights=WEIGHTS, \n         count=train_image_count // BATCH_SIZE // REPLICAS // 4)\n\n model_ckpt = tf.keras.callbacks.ModelCheckpoint(\n     str(SAVEDIR / f\"fold{fold}.h5\"), monitor=\"val_auc\", verbose=1, save_best_only=True,\n     save_weights_only=True, mode=\"max\", save_freq=\"epoch\"\n )\nhistory = model.fit(\n     get_dataset(files_train, labeled=True, batch_size=128,  \n                 buffer_size=tf.data.experimental.AUTOTUNE, drop_remainder=True),\n#         get_dataset(files_train, batch_size=BATCH_SIZE, shuffle=True, repeat=True, aug=True),\n     epochs=EPOCHS,\n     callbacks=[model_ckpt, get_lr_callback(BATCH_SIZE, REPLICAS)],\n     steps_per_epoch=train_image_count // BATCH_SIZE // REPLICAS // 4,\n#         validation_data=get_dataset(files_valid, batch_size=BATCH_SIZE * 4, repeat=True, shuffle=False, aug=True, val=True),\n     validation_data=get_dataset(files_valid, labeled=True, batch_size=BATCH_SIZE * 4, shuffle=False, drop_remainder=False),\n     verbose=1\n )\n</code></pre>\n<p>Below is error log</p>\n<pre><code>37 #         validation_data=get_dataset(files_valid, batch_size=BATCH_SIZE * 4, repeat=True, shuffle=False, aug=True, val=True),\n  38         validation_data=get_dataset(files_valid, labeled=True, batch_size=BATCH_SIZE * 4, shuffle=False, drop_remainder=False),\n---&gt; 39         verbose=1\n  40     )\n  41 \n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)\n1143           epoch_logs.update(val_logs)\n1144 \n-&gt; 1145         callbacks.on_epoch_end(epoch, epoch_logs)\n1146         training_logs = epoch_logs\n1147         if self.stop_training:\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in on_epoch_end(self, epoch, logs)\n 426     for callback in self.callbacks:\n 427       if getattr(callback, '_supports_tf_logs', False):\n--&gt; 428         callback.on_epoch_end(epoch, logs)\n 429       else:\n 430         if numpy_logs is None:  # Only convert once.\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in on_epoch_end(self, epoch, logs)\n1029 \n1030   def on_epoch_end(self, epoch, logs=None):\n-&gt; 1031     self._finalize_progbar(logs, self._train_step)\n1032 \n1033   def on_test_end(self, logs=None):\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in _finalize_progbar(self, logs, counter)\n1086 \n1087   def _finalize_progbar(self, logs, counter):\n-&gt; 1088     logs = tf_utils.to_numpy_or_python_type(logs or {})\n1089     if self.target is None:\n1090       if counter is not None:\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/utils/tf_utils.py in to_numpy_or_python_type(tensors)\n 512     return t  # Don't turn ragged or sparse tensors to NumPy.\n 513 \n--&gt; 514   return nest.map_structure(_to_single_numpy_or_python_type, tensors)\n 515 \n 516 \n/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/nest.py in map_structure(func, *structure, **kwargs)\n 657 \n 658   return pack_sequence_as(\n--&gt; 659       structure[0], [func(*x) for x in entries],\n 660       expand_composites=expand_composites)\n 661 \n/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/nest.py in &lt;listcomp&gt;(.0)\n 657 \n 658   return pack_sequence_as(\n--&gt; 659       structure[0], [func(*x) for x in entries],\n 660       expand_composites=expand_composites)\n 661 \n/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/utils/tf_utils.py in _to_single_numpy_or_python_type(t)\n 508   def _to_single_numpy_or_python_type(t):\n 509     if isinstance(t, ops.Tensor):\n--&gt; 510       x = t.numpy()\n 511       return x.item() if np.ndim(x) == 0 else x\n 512     return t  # Don't turn ragged or sparse tensors to NumPy.\n/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in numpy(self)\n1069     \"\"\"\n1070     # TODO(slebedev): Consider avoiding a copy for non-CPU or remote tensors.\n-&gt; 1071     maybe_arr = self._numpy()  # pylint: disable=protected-access\n1072     return maybe_arr.copy() if isinstance(maybe_arr, np.ndarray) else maybe_arr\n1073 \n/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in _numpy(self)\n1037       return self._numpy_internal()\n1038     except core._NotOkStatusException as e:  # pylint: disable=protected-access\n-&gt; 1039       six.raise_from(core._status_to_exception(e.code, e.message), None)  # pylint: disable=protected-access\n1040 \n1041   @property\n</code></pre>\n<pre><code>tOfRangeError: 9 root error(s) found.\n(0) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n[[Shape_19/_120]]\n(1) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n(2) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n[[GroupCrossDeviceControlEdges_0/Identity_7/_325]]\n(3) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n[[strided_slice_27/_232]]\n(4) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n[[tpu_compile_succeeded_assert/_10601166017813830618/_5/_257]]\n(5) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n[[Pad_5/paddings/_148]]\n(6) Out of range: {{function_node __inference_train_function_1081877}} End of sequence\n[[{{node cond_11/else/_106/cond_11/IteratorGetNext}}]]\n</code></pre>",
          "votes": -1,
          "replies": []
        },
        {
          "id": 1499265,
          "author_name": "Jaideep",
          "author_url": "",
          "post_date": "2021-09-01T14:33:13.873000",
          "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a>  when i do image counts for valid and train<br>\ni get <br>\n1)1680000 560000</p>\n<p>print(train_image_count,valid_image_count)</p>\n<p>how can we use folds as per your tfrecords set. i get 80 files set..</p>\n<p>2 ) How you performed it there are multiple ways mentioned <br>\n<code>rescales the waveform to [-1, 1]</code></p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1514505,
          "author_name": "Jaideep",
          "author_url": "",
          "post_date": "2021-09-16T06:25:50.023000",
          "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a>  just a slight reminder. I feel your datasets folds are not built properly if u see above. any suggestion ?</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1505096,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "2021-09-07T00:34:50.220000",
      "content": "<p>\"Rescaling was essential.\"<br>\nthe reason could be the use of stride=2 in the cnn network (especially the first one)</p>\n<p>by using enlarged image, you could have a sub-pixel convolution?</p>",
      "votes": 2,
      "replies": []
    },
    {
      "id": 1489163,
      "author_name": "Hao",
      "author_url": "",
      "post_date": "2021-08-24T18:45:28.073000",
      "content": "<blockquote>\n  <p>Rescaling was essential. I'd be interested to hear from an Kaggel Expert if they found this and if so why?</p>\n</blockquote>\n<p>I guess it's due to original data has very small value(around 1e-20 range), that's why many people divide tha data with max() first to scale to [some value, 1]. </p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1450145,
      "author_name": "Mithil Salunkhe",
      "author_url": "",
      "post_date": "2021-08-05T03:51:25.433000",
      "content": "<p>Any plans on sharing your keras layer of CWT ?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1458576,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-08T00:31:18.317000",
          "content": "<p>I've not had time to clean up the repo, but you can use this<br>\n!pip install git+<a href=\"https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance\" target=\"_blank\">https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance</a> --no-deps &gt; /dev/null</p>\n<p>and there is basic documentation.</p>",
          "votes": 5,
          "replies": []
        },
        {
          "id": 1459052,
          "author_name": "Mithil Salunkhe",
          "author_url": "",
          "post_date": "2021-08-08T07:37:53.680000",
          "content": "<p>So we have to just feed the npy files to the models by adding this layer ?</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1460514,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-08T23:30:37.480000",
          "content": "<p>Yes (see earlier comments) though to get the TPU performance you must use TFRecords (see early comments for links to these datasets)</p>",
          "votes": 3,
          "replies": []
        },
        {
          "id": 1470768,
          "author_name": "Geir Drange",
          "author_url": "",
          "post_date": "2021-08-13T17:48:44.130000",
          "content": "<p>You can find a Keras CWT layer in <a href=\"https://www.kaggle.com/mistag/wavelet1d-custom-keras-wavelet-transform-layer?scriptVersionId=71528111\" target=\"_blank\">this notebook</a>. No bandpass filtering is required with this one, as it only computes the scaleogram for a frequency range of interest.</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1470965,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-08-13T20:23:30.790000",
          "content": "",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1559722,
      "author_name": "ChristopherZerafa",
      "author_url": "",
      "post_date": "2021-10-27T07:09:24.783000",
      "content": "<p>Hey All,</p>\n<p>Thank you all for taking part in our competition. The participation has been overwhelmingly positive. We are currently conducting a survey to gauge the demographic and outreach achieved. Kindly spare 2min and fill in this survey <a href=\"https://forms.gle/QP9L16niPexozyhu5\" target=\"_blank\">https://forms.gle/QP9L16niPexozyhu5</a>.</p>\n<p>Thank you all,</p>\n<p>Regards,<br>\nChris</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1504887,
      "author_name": "Ioannis M",
      "author_url": "",
      "post_date": "2021-09-06T18:37:49.603000",
      "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> nice work! may I ask what does the parameter <code>wavelet_width: default = 1</code> in CWT ? what range of values should we consider ? <br>\nI saw the demo in your git repo where it uses 1, but not sure if that is the case for our data here</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1499318,
      "author_name": "Hao",
      "author_url": "",
      "post_date": "2021-09-01T15:09:16.090000",
      "content": "<p>Thanks for sharing <a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> , may I ask what do you mean by \"rescales the waveform to [-1, 1]\"? It's like standardize as -mean and /std, or min/max to [0, 1] then scale and shift to [-1, 1]? Thanks.</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1499842,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-09-02T01:22:00.070000",
          "content": "<p>Its Min/Max</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1495884,
      "author_name": "Tanish Gupta",
      "author_url": "",
      "post_date": "2021-08-29T21:25:53.740000",
      "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> Can you guide me what is bandpass filter and CWT</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1495948,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-30T00:15:50.607000",
          "content": "<p>Your best option is to do some reading on the internet.<br>\n<a href=\"https://en.wikipedia.org/wiki/Band-pass_filter\" target=\"_blank\">https://en.wikipedia.org/wiki/Band-pass_filter</a><br>\n<a href=\"https://www.kaggle.com/asauve/a-gentle-introduction-to-wavelet-for-data-analysis\" target=\"_blank\">https://www.kaggle.com/asauve/a-gentle-introduction-to-wavelet-for-data-analysis</a></p>\n<p>In short a filter removes some frequencies from a wave and a band pass only allows frequencies in the band to pass.</p>\n<p>A CWT is an alternative approach to Short Term Fourier Transform or Constant Quality Transform to converting a wave from time/amplitude to time/Frequency</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1490958,
      "author_name": "Lowerce",
      "author_url": "",
      "post_date": "2021-08-26T03:31:55.107000",
      "content": "<p>I have learned a lot from your summary!</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1485990,
      "author_name": "Zekun",
      "author_url": "",
      "post_date": "2021-08-22T14:59:01.930000",
      "content": "<p>Hello, how is your single model's lb and cv?</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1480712,
      "author_name": "Kalilur Rahman",
      "author_url": "",
      "post_date": "2021-08-19T06:31:35.727000",
      "content": "<p>Good post. Thanks for sharing your inputs. Well written indeed! <a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> 👍</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1478898,
      "author_name": "Jaideep",
      "author_url": "",
      "post_date": "2021-08-18T07:26:34.500000",
      "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a>  does the order Bandpass filter makes any difference, Like apply CQT then BandPass </p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1478581,
      "author_name": "dan",
      "author_url": "",
      "post_date": "2021-08-18T04:16:57.947000",
      "content": "<p>I thought b7 on 512x512 would cause memory issue on many GPUs. Mind sharing GPUs you are using?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1478728,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-18T05:51:12.157000",
          "content": "<p>I've been running on a TPU and find I get better performance, say 10-20x</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1464254,
      "author_name": "Srushti Sawant",
      "author_url": "",
      "post_date": "2021-08-10T14:01:40.647000",
      "content": "<p>Than you for sharing </p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1461695,
      "author_name": "stallone",
      "author_url": "",
      "post_date": "2021-08-09T14:19:55.917000",
      "content": "<p>Good work. <a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> </p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1459244,
      "author_name": "Yerram Varun",
      "author_url": "",
      "post_date": "2021-08-08T09:37:33.613000",
      "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> Hey Thanks for the detailed approach overview.<br>\nI just had a doubt. At what step are you resizing the scalograms?</p>\n<p><code>.npy files -&gt; CQT (keras layer) -&gt; Resizing (?) -&gt; EFN Model (keras model)</code></p>\n<p>Won't this be a bottleneck here?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1460496,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-08T23:09:08.840000",
          "content": "<p><a href=\"https://www.kaggle.com/yerramvarun\" target=\"_blank\">@yerramvarun</a> I don't resize the CWT for the EFN. My model looks like</p>\n<p><code>\n model = tf.keras.Sequential([L.InputLayer(input_shape=(3, 4096),\n                                     ComplexMorletCWT(n_scales = 64, stride=64, \n                                                                         output='magnitude', data_format='channels_first'), \n                                     L.Permute((2, 3, 1)), # transpose to channel last [:, time, n_scales, channels]\n                                     efn.EfficientnetB4(include_top=False,weights='imagenet'),\n                                     L.GlobalAveragePooling2D(),\n                                     L.Dense(32,activation='relu'),\n                                     L.Dense(1, activation='sigmoid')\n                                    ])\n</code><br>\nI guess you are asking at the Keras documentation for EFN states each model uses a specific size. I found this confusing and discovered they worked Ok with other sizes. I'd be interested to hear from someone with more experience about this?</p>\n<p>Note: I'm using Continuious Wavelett Transfroms (CWT) not CQT using the keras layer in this<br>\n!pip install git+<a href=\"https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance\" target=\"_blank\">https://github.com//Kevin-McIsaac/cmorlet-tensorflow@Performance</a> --no-deps &gt; /dev/null</p>",
          "votes": 4,
          "replies": []
        },
        {
          "id": 1460727,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-08-09T03:48:03.490000",
          "content": "",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1461285,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-09T10:18:10.603000",
          "content": "<p>That makes sense. Thanks for clearing that up for me</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1494194,
          "author_name": "Jaideep",
          "author_url": "",
          "post_date": "2021-08-28T13:36:27.907000",
          "content": "<p>where do you resize your image to different square sizes <a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> </p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1495919,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-29T22:40:10.310000",
          "content": "<p>I use the n_scales and strides parameters to determine the size of the image, e.g., n_scales = 128, stride=32 creates a spectrogram that is 128x128. While efficient net was trained on specific image sizes, it can accept any size.</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1495924,
          "author_name": "Araik Tamazian",
          "author_url": "",
          "post_date": "2021-08-29T22:55:35.327000",
          "content": "<p>Let's say you want image of WIDTH x HEIGHT size. Then you should set  <code>n_scales=WIDTH</code>, and <code>strides = int(np.ceil(4096/HEIGHT))</code> (assuming your input has (3, 4096) shape). This works for me.</p>",
          "votes": 3,
          "replies": []
        }
      ]
    },
    {
      "id": 1456944,
      "author_name": "Md Zarif Ul Alam",
      "author_url": "",
      "post_date": "2021-08-07T06:54:51.320000",
      "content": "<blockquote>\n  <p>I started with nnAudio Constant Quality Transform (CQT) and found this a lot faster than librosa. The entire processing, i.e., load the data, bandpass filter, creating the a 64x64 scalogram in nnAUdio and classifying in EFN B4 took about 8hrs on a CPU and 2hrs on a GPU. </p>\n</blockquote>\n<p>can you tell me how many epochs you did in 2 hours you mentioned ?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1458555,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-08T00:08:40.940000",
          "content": "<p>My notes are not the best for the old  nnAudio runs. For recent runs with a CWT that create an 64x64 image and B4 I get the following<br>\nTPU 32s per epoch, ran 30 epochs. <br>\nGPU 260s per epoch,   29 epochs </p>\n<p>The total notebook time, including set and inferencing was 28 min and 2hrs 14 respectively.</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1458814,
          "author_name": "Md Zarif Ul Alam",
          "author_url": "",
          "post_date": "2021-08-08T04:51:42.973000",
          "content": "<p>Thanks! Can you tell me how you optimized the preprocessing / process of conversion to TFrecords ? When I was trying to do some custom preprocessing and trying to convert them to TFrecords, each notebook had only 5GB output size. So, it will take me 16 runs, each around 4GB. This seems to be a bottleneck. </p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1460513,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-08T23:28:43.087000",
          "content": "<p>I found I could do this as three batches; 2 for train and 1 for submissions.  </p>\n<p>These are  public datasets named like this <a href=\"https://www.kaggle.com/kevinmcisaac/g2net-tfrecords-with-20500hz-bandpass\" target=\"_blank\">G2NET TFRecords with 20-500Hz bandpass Part I</a></p>\n<p>You can then look at the notebook that generated this which  use this <a href=\"https://www.kaggle.com/kevinmcisaac/g2nettfrec\" target=\"_blank\">utility script</a></p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1467960,
          "author_name": "Md Zarif Ul Alam",
          "author_url": "",
          "post_date": "2021-08-12T07:41:29.597000",
          "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> can you tell me how many training samples are in each tfrecord of your dataset ? I can't seem to find any number from your utility script</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1468089,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-12T09:00:06.677000",
          "content": "<p>Rather than pick a number of samples per TFR The approach  I used was to create a specific number of TFrecord files so that each was large enough to get good read performance and there were enough file to enable overlapping parallel reads.  </p>\n<p>You can see in the notebook I created 70 files so each trf file has  560000/70 = 8,000 samples</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1468528,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-08-12T13:06:55.060000",
          "content": "",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1469484,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-13T01:02:39.323000",
          "content": "<p>I converted the inputs to np.float32 as part of the preprocessing.  Having read <a href=\"https://cloud.google.com/blog/products/ai-machine-learning/bfloat16-the-secret-to-high-performance-on-cloud-tpus\" target=\"_blank\">this</a> I now understand why you are asking a however not familiar enough with TF 2.0 to be able to answer the question of using mixed precision.</p>\n<p>If you have the skills you could fork the repo and make the necessary changes. I'd be keen to hear how that goes.</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1471865,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-08-14T14:16:33.637000",
          "content": "",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1452494,
      "author_name": "Araik Tamazian",
      "author_url": "",
      "post_date": "2021-08-05T16:11:29.170000",
      "content": "<p>Can you tell which package you used for making a bandpass filter?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1452559,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-08-05T16:28:27.047000",
          "content": "",
          "votes": 3,
          "replies": []
        },
        {
          "id": 1458564,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-08T00:16:35.877000",
          "content": "<p>I used scipy.signal.  Here is the code I used.</p>\n<pre><code>from scipy import signal\n\nbHP, aHP = signal.butter(8, (20, 500), btype='bandpass', fs= 2048)\ndef filterSig(waves, a=aHP, b=bHP):\n    '''Apply a 20Hz high pass filter to the three events'''\n    return np.array([signal.filtfilt(b, a, wave) for wave in waves]) #lfilter introduces a larger spike around 20hz\n</code></pre>\n<p>Initially issued gwpy but its a lot of baggage just to do a simple filter.  I use this in a pre-processing step that re-writes the data s TFrecords to speed up data loading and keep the TPUs busy.</p>\n<p>What I'd like to do is make a bandpass filter in Keras and include that in my NN</p>",
          "votes": 10,
          "replies": []
        },
        {
          "id": 1459232,
          "author_name": "datasaurus",
          "author_url": "",
          "post_date": "2021-08-08T09:30:52.680000",
          "content": "<p>I think for a 20-500Hz cuts you need to use something like:</p>\n<pre><code>nyq = 0.5 * fs  # Nyquist frequency\nlow = 20 / nyq\nhigh = 500 / nyq\nb, a = butter(order, [low, high], btype='bandpass')\n</code></pre>\n<p>From: <a href=\"https://scipy-cookbook.readthedocs.io/items/ButterworthBandpass.html\" target=\"_blank\">https://scipy-cookbook.readthedocs.io/items/ButterworthBandpass.html</a></p>\n<p>Edit: I just found out that if you pass the <code>fs</code> arg, you don't need to do this :)</p>",
          "votes": 9,
          "replies": []
        },
        {
          "id": 1463688,
          "author_name": "Mithil Salunkhe",
          "author_url": "",
          "post_date": "2021-08-10T09:33:20.680000",
          "content": "<p><a href=\"https://www.kaggle.com/kevinmcisaac\" target=\"_blank\">@kevinmcisaac</a> should this be applied before or after normalization ?</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1463981,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-10T12:07:08.570000",
          "content": "<p>I applied the scaling after the bandpass filter but I don't think the order matter.  </p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1464039,
          "author_name": "Mithil Salunkhe",
          "author_url": "",
          "post_date": "2021-08-10T12:29:37.577000",
          "content": "<p>Just tried both after and before scaling. They both look the same</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1464081,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-10T12:47:05.490000",
          "content": "<p>Good to know</p>",
          "votes": 3,
          "replies": []
        },
        {
          "id": 1464124,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-08-10T13:06:32.067000",
          "content": "",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1465337,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-11T02:33:43.033000",
          "content": "<p>Yes I did. The results are reported <a href=\"https://www.kaggle.com/c/g2net-gravitational-wave-detection/discussion/252396\" target=\"_blank\">here</a>.<br>\nTL;DR i make the AUC 10% worse.</p>",
          "votes": 3,
          "replies": []
        },
        {
          "id": 1483732,
          "author_name": "Araik Tamazian",
          "author_url": "",
          "post_date": "2021-08-20T20:15:13.830000",
          "content": "<p>Thanks to all who replied. This info is quite useful.</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1497459,
      "author_name": "",
      "author_url": "",
      "post_date": "2021-08-31T08:03:53.073000",
      "content": "",
      "votes": 0,
      "replies": [
        {
          "id": 1497469,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-31T08:12:45.913000",
          "content": "<p>No, I change the size of n_scales and or stride to create the desired sized scalogram, e.g, </p>\n<blockquote>\n  <p>ComplexMorletCWT(n_scales = 64, stride=64)</p>\n</blockquote>\n<p>creates a 64 x 64 image.</p>\n<ul>\n<li>n_scales determines how many samples we take in the frequencey axis ie 64<ul>\n<li>stride termines how many time steps to move for each claculation. Since the signals length is 4096, a stride of 64 means we will have 4096/64 = 64 sample on the time axis</li></ul></li>\n</ul>",
          "votes": 3,
          "replies": []
        },
        {
          "id": 1497494,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-08-31T08:36:45.847000",
          "content": "",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1464122,
      "author_name": "",
      "author_url": "",
      "post_date": "2021-08-10T13:05:54.923000",
      "content": "",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1460735,
      "author_name": "",
      "author_url": "",
      "post_date": "2021-08-09T03:55:08.823000",
      "content": "",
      "votes": 1,
      "replies": [
        {
          "id": 1474806,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-16T09:21:23.033000",
          "content": "<p>I simply divided by a fixed scale factor, i.e., the same number for each channel (detector) and all samples.  </p>\n<p>I started out by dividing each channel by the max of the absolute value of that channel, i.e., standardize into the range [-1,1] but then I thought this might lose some important information so I switch to a common number across all.  Since there is a large dynamic range across the various samples, and across teh detectors, I just picked something that seemed reasonable for many samples (i.e., more art than science).</p>",
          "votes": 4,
          "replies": []
        }
      ]
    },
    {
      "id": 1451854,
      "author_name": "",
      "author_url": "",
      "post_date": "2021-08-05T12:59:10.630000",
      "content": "",
      "votes": 2,
      "replies": [
        {
          "id": 1452016,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-08-05T13:55:38.030000",
          "content": "",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1458574,
          "author_name": "Fractal Feelings",
          "author_url": "",
          "post_date": "2021-08-08T00:30:34.733000",
          "content": "<p>I've not tried ENetV2 yet. How much improvement did you get, i.e., %? </p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1459249,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-08-08T09:40:25.407000",
          "content": "",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1478994,
          "author_name": "Mithil Salunkhe",
          "author_url": "",
          "post_date": "2021-08-18T08:33:41.167000",
          "content": "<p>How was efficientnetv2 XL comparable to efficientnet B7 ?</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1473217,
      "author_name": "Yuri Sun",
      "author_url": "",
      "post_date": "2021-08-15T12:40:49.160000",
      "content": "<p>Thanks for sharing!</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1464152,
      "author_name": "Mohamed Iniesta",
      "author_url": "",
      "post_date": "2021-08-10T13:15:57.927000",
      "content": "<p>Thanks for sharing ! 😁😁</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1455557,
      "author_name": "Saurav Maheshkar ☕️",
      "author_url": "",
      "post_date": "2021-08-06T15:51:22.947000",
      "content": "<p>Thanks for sharing your insights </p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1454015,
      "author_name": "Sunnymoon Sultan",
      "author_url": "",
      "post_date": "2021-08-06T04:32:03.510000",
      "content": "<p>Thanks for sharing!</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1449690": "Since this was my first time using a NN, GPU/TPU and Tensorflow I had a steep learning curve. I tried a lot of things and thought I'd share what I learnt. \n\nIn summary I used Keras to build a model that \n* applies a bandpass filter, \n* rescales the waveform to [-1, 1]\n* Applies a time-frequency transform (e.g., STFT, CQT, CWT) to  create a scalogram\n* Classifies  using Efficient Net.\n\nIs is very similar to what many others have done. I  currently have a AUC score of 0.872, which puts me in the middle of the leaderboard.\n\nWhat I learnt from experimenting with this was. \n* The bandpass filter (20hz-500Hz) has quite an impact. I think this is because the noise below 20 Hz is high and signal is weaker at low frequencies, i.e., very low SNR. I chose 500 Hz because the highest signal frequency for a black hole event is 350 Hz.  I could not find articles on the frequency range for other types of events so I picked 500 as there are some strong noise sources just above that. It also looks like the best SNR is around 350-500Hz\n*  Rescaling was  essential. I'd be interested to hear from an Kaggel Expert if they found this and if so why? \n* I started with nnAudio Constant Quality Transform (CQT) and found this a lot faster than librosa. The entire processing, i.e., load the data, bandpass filter,  creating the a 64x64 scalogram in nnAUdio and classifying in EFN B4 took about 8hrs on a CPU and  **2hrs on a GPU**. \n* I discovered a  TF  implementation of Continuous Wavelet Transform  and updated it to TF 2.0,  optimised the algorithm, and made it a Keras Layer. This enables me to have a single Kera model for the scalogram -> EFN that runs on a TPU. The entire processing time dropped to about **30 min**.\n* I pre-processed the numpy input files into TFRecords and first epoch takes **3 min** and subsequent took 30s.\n\nThis gave me an experimental test bed for further experimentation.  \n* Larger scalograms, e.g., 256x256 and 512x512 gives a small boost.\n* Different CWT wavelet_width, 8 seems optimal, give a small boost. I found making this paramater trainable also gave a small boost.\n* Transfer Learning (i.e., freeze the EFN layer) followed by Fine Tuning (unfreeze). Marginal improvement\n* DIfferent EFN models, e.g., B0, B4, B7, with B7 having a slight boost\n\nAs I was running a lot of experiments I found that I needed a better way to record the results and started using Neptune.ai, which has been very useful.\n\nMy best result so far is B7 with a 512x512 scalogram ",
    "1454700": "Good work.\n\nYou're not just tweaking public notebooks.  This is how to make a difference here.  Keep pushing (but not too hard, I'd like to stay ahead of you ... )",
    "1487386": "I tried to add your work into my pipeline. Hower the AUC is always around 0.5😦...",
    "1475260": "Regarding the rescaling. You always want your data to have zero mean and unity standard deviation. This allows deep neural networks to train well, see the famous paper on this: http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf\n\nHope I got youe question correclty.",
    "1466846": "Could you share the TF implementation of CWT you have been using?\n\nI found [this](https://github.com/nickgeoca/cwt-tensorflow) version and tried implementing it in PyTorch, however, the performance is significantly worse than Q-Transform.\n\nMy PyTorch implementation is [here](https://www.kaggle.com/anjum48/continuous-wavelet-transform-cwt-in-pytorch)",
    "1505096": "\"Rescaling was essential.\"\nthe reason could be the use of stride=2 in the cnn network (especially the first one)\n\nby using enlarged image, you could have a sub-pixel convolution?",
    "1489163": "> Rescaling was essential. I'd be interested to hear from an Kaggel Expert if they found this and if so why?\n\nI guess it's due to original data has very small value(around 1e-20 range), that's why many people divide tha data with max() first to scale to [some value, 1]. ",
    "1450145": "Any plans on sharing your keras layer of CWT ?",
    "1559722": "Hey All,\n\nThank you all for taking part in our competition. The participation has been overwhelmingly positive. We are currently conducting a survey to gauge the demographic and outreach achieved. Kindly spare 2min and fill in this survey https://forms.gle/QP9L16niPexozyhu5.\n\nThank you all,\n\nRegards,\nChris",
    "1504887": "@kevinmcisaac nice work! may I ask what does the parameter `wavelet_width: default = 1` in CWT ? what range of values should we consider ? \nI saw the demo in your git repo where it uses 1, but not sure if that is the case for our data here",
    "1499318": "Thanks for sharing @kevinmcisaac , may I ask what do you mean by \"rescales the waveform to [-1, 1]\"? It's like standardize as -mean and /std, or min/max to [0, 1] then scale and shift to [-1, 1]? Thanks.",
    "1495884": " @kevinmcisaac Can you guide me what is bandpass filter and CWT",
    "1490958": "I have learned a lot from your summary!",
    "1485990": "Hello, how is your single model's lb and cv?",
    "1480712": "Good post. Thanks for sharing your inputs. Well written indeed! @kevinmcisaac 👍",
    "1478898": "@kevinmcisaac  does the order Bandpass filter makes any difference, Like apply CQT then BandPass ",
    "1478581": "I thought b7 on 512x512 would cause memory issue on many GPUs. Mind sharing GPUs you are using?",
    "1464254": "Than you for sharing ",
    "1461695": "Good work. @kevinmcisaac ",
    "1459244": "@kevinmcisaac Hey Thanks for the detailed approach overview.\nI just had a doubt. At what step are you resizing the scalograms?\n\n``` .npy files -> CQT (keras layer) -> Resizing (?) -> EFN Model (keras model) ```\n\nWon't this be a bottleneck here?",
    "1456944": "> I started with nnAudio Constant Quality Transform (CQT) and found this a lot faster than librosa. The entire processing, i.e., load the data, bandpass filter, creating the a 64x64 scalogram in nnAUdio and classifying in EFN B4 took about 8hrs on a CPU and 2hrs on a GPU. \n\ncan you tell me how many epochs you did in 2 hours you mentioned ?",
    "1452494": "Can you tell which package you used for making a bandpass filter?",
    "1497459": "",
    "1464122": "",
    "1460735": "",
    "1451854": "",
    "1473217": "Thanks for sharing!",
    "1464152": "Thanks for sharing ! 😁😁",
    "1455557": "Thanks for sharing your insights ",
    "1454015": "Thanks for sharing!\n"
  }
}