{
  "id": 492414,
  "title": " A small trick to improve scores - inputting multiple sets of data for one patient",
  "url": "/competitions/hms-harmful-brain-activity-classification/discussion/492414",
  "author_name": "",
  "post_date": "2024-04-09T15:19:33.240464200Z",
  "votes": 8,
  "comment_count": 3,
  "views": 0,
  "content": "<p>I'd like to share a little trick that can boost scores slightly. I've noticed that a single patient often corresponds to multiple eeg_id and spectrogram_id, yet the final expert_consensus and the labels to be predicted for the same patient are indeed very similar. So, when loading the data, I load four other sets of similar data for one patient to predict the final result together. This approach can increase scores by 0.01 to 0.02.</p>",
  "messages": [
    {
      "id": "2743687",
      "postDate": "04/09/2024 15:19:33",
      "content": "<p>I'd like to share a little trick that can boost scores slightly. I've noticed that a single patient often corresponds to multiple eeg_id and spectrogram_id, yet the final expert_consensus and the labels to be predicted for the same patient are indeed very similar. So, when loading the data, I load four other sets of similar data for one patient to predict the final result together. This approach can increase scores by 0.01 to 0.02.</p>",
      "rawMarkdown": "I'd like to share a little trick that can boost scores slightly. I've noticed that a single patient often corresponds to multiple eeg_id and spectrogram_id, yet the final expert_consensus and the labels to be predicted for the same patient are indeed very similar. So, when loading the data, I load four other sets of similar data for one patient to predict the final result together. This approach can increase scores by 0.01 to 0.02.",
      "votes": null
    },
    {
      "id": "2743793",
      "postDate": "04/09/2024 16:09:30",
      "content": "<p>I used a similar idea. </p>\n<p>First, the model was trained to predict one of the 6 classes, but then I cut off the final classifiers and predicted embedding of each item.</p>\n<p>Second, all the items with the same patient_id were grouped, and their embeddings were averaged. </p>\n<p>Third, I trained a new classifier, which takes both item embedding and averaged embedding as its input.</p>\n<p>This approach allows to deal with any number of items in each group. Also it takes into account both the information about what diagnosis is usual for the patient, and what is specific in each particular eeg/sg.</p>",
      "rawMarkdown": "I used a similar idea. \n\nFirst, the model was trained to predict one of the 6 classes, but then I cut off the final classifiers and predicted embedding of each item.\n\nSecond, all the items with the same patient_id were grouped, and their embeddings were averaged. \n\nThird, I trained a new classifier, which takes both item embedding and averaged embedding as its input.\n\nThis approach allows to deal with any number of items in each group. Also it takes into account both the information about what diagnosis is usual for the patient, and what is specific in each particular eeg/sg.",
      "votes": null
    },
    {
      "id": "2744587",
      "postDate": "04/10/2024 02:21:14",
      "content": "<p>Thank you for your sharing.😀Your approach is quite innovative! You achieve a more comprehensive feature representation.<br>\nThis is what I did:<br>\n`    <br>\ndef __data_generation(self, index):<br>\n        \"\"\"<br>\n        Generates data containing batch_size samples.<br>\n        \"\"\"<br>\n        X = np.zeros((128, 256, 40), dtype='float32')<br>\n        y = np.zeros(7, dtype='float32')<br>\n        img = np.ones((128,256), dtype='float32')<br>\n        row = self.df.iloc[index]<br>\n        patient_id = row['patient_id']<br>\n        ddf = self.df[self.df['patient_id'] == patient_id]<br>\n        if ddf.shape[0] &gt;= 4:<br>\n            rows = ddf.sample(n=4,random_state=42)<br>\n        else:<br>\n            rows = ddf.sample(n=4, replace=True,random_state=42)<br>\n        row2 = rows.iloc[0]<br>\n        row3 = rows.iloc[1]<br>\n        row4 = rows.iloc[2]<br>\n        row5 = rows.iloc[3]<br>\n        if self.mode=='test': <br>\n            r = 0<br>\n        else: <br>\n            r = int(row['spectrogram_label_offset_seconds'] // 2)</p>\n<pre><code>     = self.spectograms[row.spec_id][r:r+, :].T.reshape(, , )\n\n    \n     = np.clip(spectogram_data, np.exp(-), np.exp())\n     = np.log(spectogram_data)\n\n    \n     = np.nanmean(spectogram_data, axis=(, ))\n     = np.nanstd(spectogram_data, axis=(, ))\n    = spectogram_data.transpose(,,)\n     = (spectogram_data - mu[ None, None,:]) / (std[ None, None,:] + e-)\n     = np.nan_to_num(spectogram_data, nan=.)\n\n    \n    [:-, :, :] = spectogram_data[:, :-, :] / .\n     = self.eeg_spectograms[row.eeg_id]\n    [:, :, :] = img\n\n\n\n     self.mode=='test': \n         = \n    : \n         = int(row2['spectrogram_label_offset_seconds'] // )\n\n     = self.spectograms[row2.spec_id][r:r+, :].T.reshape(, , )\n\n    \n     = np.clip(spectogram_data, np.exp(-), np.exp())\n     = np.log(spectogram_data)\n\n    \n     = np.nanmean(spectogram_data, axis=(, ))\n     = np.nanstd(spectogram_data, axis=(, ))\n     = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + e-)\n     = np.nan_to_num(spectogram_data, nan=.)\n\n\n    \n    [:-, :, :] = spectogram_data.transpose(,,)[:, :-, :] / .\n     = self.eeg_spectograms[row2.eeg_id]\n    [:, :, :] = img        \n\n\n     self.mode=='test': \n         = \n    : \n         = int(row3['spectrogram_label_offset_seconds'] // )\n\n     = self.spectograms[row3.spec_id][r:r+, :].T.reshape(, , )\n\n    \n     = np.clip(spectogram_data, np.exp(-), np.exp())\n     = np.log(spectogram_data)\n\n    \n     = np.nanmean(spectogram_data, axis=(, ))\n     = np.nanstd(spectogram_data, axis=(, ))\n     = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + e-)\n     = np.nan_to_num(spectogram_data, nan=.)\n\n\n    \n    [:-, :, :] = spectogram_data.transpose(,,)[:, :-, :] / .\n     = self.eeg_spectograms[row3.eeg_id]\n    [:, :, :] = img    \n\n\n     self.mode=='test': \n         = \n    : \n         = int(row4['spectrogram_label_offset_seconds'] // )\n\n     = self.spectograms[row4.spec_id][r:r+, :].T.reshape(, , )\n\n    \n     = np.clip(spectogram_data, np.exp(-), np.exp())\n     = np.log(spectogram_data)\n\n    \n     = np.nanmean(spectogram_data, axis=(, ))\n     = np.nanstd(spectogram_data, axis=(, ))\n     = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + e-)\n     = np.nan_to_num(spectogram_data, nan=.)\n\n\n    \n    [:-, :, :] = spectogram_data.transpose(,,)[:, :-, :] / .\n     = self.eeg_spectograms[row4.eeg_id]\n    [:, :, :] = img    \n\n\n\n     self.mode=='test': \n         = \n    : \n         = int(row5['spectrogram_label_offset_seconds'] // )\n\n      \n     = self.spectograms[row5.spec_id][r:r+, :].T.reshape(, , )\n\n    \n     = np.clip(spectogram_data, np.exp(-), np.exp())\n     = np.log(spectogram_data)\n\n    \n     = np.nanmean(spectogram_data, axis=(, ))\n     = np.nanstd(spectogram_data, axis=(, ))\n     = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + e-)\n     = np.nan_to_num(spectogram_data, nan=.)\n\n\n    \n    [:-, :, :] = spectogram_data.transpose(,,)[:, :-, :] / .\n     = self.eeg_spectograms[row5.eeg_id]\n    [:, :, :] = img    \n\n\n\n     self.mode != 'test':\n        [:-] = row[TARGETS].values.astype(np.float32)\n        [-] = row['total_evaluators']\n\n     X, y`\n</code></pre>",
      "rawMarkdown": "Thank you for your sharing.😀Your approach is quite innovative! You achieve a more comprehensive feature representation.\nThis is what I did:\n`    \ndef __data_generation(self, index):\n        \"\"\"\n        Generates data containing batch_size samples.\n        \"\"\"\n        X = np.zeros((128, 256, 40), dtype='float32')\n        y = np.zeros(7, dtype='float32')\n        img = np.ones((128,256), dtype='float32')\n        row = self.df.iloc[index]\n        patient_id = row['patient_id']\n        ddf = self.df[self.df['patient_id'] == patient_id]\n        if ddf.shape[0] >= 4:\n            rows = ddf.sample(n=4,random_state=42)\n        else:\n            rows = ddf.sample(n=4, replace=True,random_state=42)\n        row2 = rows.iloc[0]\n        row3 = rows.iloc[1]\n        row4 = rows.iloc[2]\n        row5 = rows.iloc[3]\n        if self.mode=='test': \n            r = 0\n        else: \n            r = int(row['spectrogram_label_offset_seconds'] // 2)\n            \n        spectogram_data = self.spectograms[row.spec_id][r:r+300, :400].T.reshape(4, 100, 300)\n\n        # Log transform\n        spectogram_data = np.clip(spectogram_data, np.exp(-4), np.exp(8))\n        spectogram_data = np.log(spectogram_data)\n\n        # Standardize per image\n        mu = np.nanmean(spectogram_data, axis=(1, 2))\n        std = np.nanstd(spectogram_data, axis=(1, 2))\n        spectogram_data= spectogram_data.transpose(1,2,0)\n        spectogram_data = (spectogram_data - mu[ None, None,:]) / (std[ None, None,:] + 1e-6)\n        spectogram_data = np.nan_to_num(spectogram_data, nan=0.0)\n\n        # Update X\n        X[14:-14, :, :4] = spectogram_data[:, 22:-22, :] / 2.0\n        img = self.eeg_spectograms[row.eeg_id]\n        X[:, :, 4:8] = img\n\n            \n            \n        if self.mode=='test': \n            r = 0\n        else: \n            r = int(row2['spectrogram_label_offset_seconds'] // 2)\n            \n        spectogram_data = self.spectograms[row2.spec_id][r:r+300, :400].T.reshape(4, 100, 300)\n\n        # Log transform\n        spectogram_data = np.clip(spectogram_data, np.exp(-4), np.exp(8))\n        spectogram_data = np.log(spectogram_data)\n\n        # Standardize per image\n        mu = np.nanmean(spectogram_data, axis=(1, 2))\n        std = np.nanstd(spectogram_data, axis=(1, 2))\n        spectogram_data = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + 1e-6)\n        spectogram_data = np.nan_to_num(spectogram_data, nan=0.0)\n\n\n        # Update X\n        X[14:-14, :, 8:12] = spectogram_data.transpose(1,2,0)[:, 22:-22, :] / 2.0\n        img = self.eeg_spectograms[row2.eeg_id]\n        X[:, :, 12:16] = img        \n   \n\n        if self.mode=='test': \n            r = 0\n        else: \n            r = int(row3['spectrogram_label_offset_seconds'] // 2)\n                \n        spectogram_data = self.spectograms[row3.spec_id][r:r+300, :400].T.reshape(4, 100, 300)\n\n        # Log transform\n        spectogram_data = np.clip(spectogram_data, np.exp(-4), np.exp(8))\n        spectogram_data = np.log(spectogram_data)\n\n        # Standardize per image\n        mu = np.nanmean(spectogram_data, axis=(1, 2))\n        std = np.nanstd(spectogram_data, axis=(1, 2))\n        spectogram_data = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + 1e-6)\n        spectogram_data = np.nan_to_num(spectogram_data, nan=0.0)\n\n\n        # Update X\n        X[14:-14, :, 16:20] = spectogram_data.transpose(1,2,0)[:, 22:-22, :] / 2.0\n        img = self.eeg_spectograms[row3.eeg_id]\n        X[:, :, 20:24] = img    \n            \n            \n        if self.mode=='test': \n            r = 0\n        else: \n            r = int(row4['spectrogram_label_offset_seconds'] // 2)\n\n        spectogram_data = self.spectograms[row4.spec_id][r:r+300, :400].T.reshape(4, 100, 300)\n\n        # Log transform\n        spectogram_data = np.clip(spectogram_data, np.exp(-4), np.exp(8))\n        spectogram_data = np.log(spectogram_data)\n\n        # Standardize per image\n        mu = np.nanmean(spectogram_data, axis=(1, 2))\n        std = np.nanstd(spectogram_data, axis=(1, 2))\n        spectogram_data = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + 1e-6)\n        spectogram_data = np.nan_to_num(spectogram_data, nan=0.0)\n\n\n        # Update X\n        X[14:-14, :, 24:28] = spectogram_data.transpose(1,2,0)[:, 22:-22, :] / 2.0\n        img = self.eeg_spectograms[row4.eeg_id]\n        X[:, :, 28:32] = img    \n            \n  \n\n        if self.mode=='test': \n            r = 0\n        else: \n            r = int(row5['spectrogram_label_offset_seconds'] // 2)\n                \n          # 提取spectrogram数据并重新排布为三维数组\n        spectogram_data = self.spectograms[row5.spec_id][r:r+300, :400].T.reshape(4, 100, 300)\n\n        # Log transform\n        spectogram_data = np.clip(spectogram_data, np.exp(-4), np.exp(8))\n        spectogram_data = np.log(spectogram_data)\n\n        # Standardize per image\n        mu = np.nanmean(spectogram_data, axis=(1, 2))\n        std = np.nanstd(spectogram_data, axis=(1, 2))\n        spectogram_data = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + 1e-6)\n        spectogram_data = np.nan_to_num(spectogram_data, nan=0.0)\n\n\n        # Update X\n        X[14:-14, :, 32:36] = spectogram_data.transpose(1,2,0)[:, 22:-22, :] / 2.0\n        img = self.eeg_spectograms[row5.eeg_id]\n        X[:, :, 36:40] = img    \n            \n            \n            \n        if self.mode != 'test':\n            y[:-1] = row[TARGETS].values.astype(np.float32)\n            y[-1] = row['total_evaluators']\n            \n        return X, y`",
      "votes": null
    },
    {
      "id": "2775336",
      "postDate": "04/25/2024 16:17:47",
      "content": "<p>Great work!</p>",
      "rawMarkdown": "Great work!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2743793,
      "author_name": "kdmitrie",
      "author_url": "",
      "post_date": "04/09/2024 16:09:30",
      "content": "<p>I used a similar idea. </p>\n<p>First, the model was trained to predict one of the 6 classes, but then I cut off the final classifiers and predicted embedding of each item.</p>\n<p>Second, all the items with the same patient_id were grouped, and their embeddings were averaged. </p>\n<p>Third, I trained a new classifier, which takes both item embedding and averaged embedding as its input.</p>\n<p>This approach allows to deal with any number of items in each group. Also it takes into account both the information about what diagnosis is usual for the patient, and what is specific in each particular eeg/sg.</p>",
      "votes": null,
      "replies": [
        {
          "id": 2744587,
          "author_name": "xianhellg",
          "author_url": "",
          "post_date": "04/10/2024 02:21:14",
          "content": "<p>Thank you for your sharing.😀Your approach is quite innovative! You achieve a more comprehensive feature representation.<br>\nThis is what I did:<br>\n`    <br>\ndef __data_generation(self, index):<br>\n        \"\"\"<br>\n        Generates data containing batch_size samples.<br>\n        \"\"\"<br>\n        X = np.zeros((128, 256, 40), dtype='float32')<br>\n        y = np.zeros(7, dtype='float32')<br>\n        img = np.ones((128,256), dtype='float32')<br>\n        row = self.df.iloc[index]<br>\n        patient_id = row['patient_id']<br>\n        ddf = self.df[self.df['patient_id'] == patient_id]<br>\n        if ddf.shape[0] &gt;= 4:<br>\n            rows = ddf.sample(n=4,random_state=42)<br>\n        else:<br>\n            rows = ddf.sample(n=4, replace=True,random_state=42)<br>\n        row2 = rows.iloc[0]<br>\n        row3 = rows.iloc[1]<br>\n        row4 = rows.iloc[2]<br>\n        row5 = rows.iloc[3]<br>\n        if self.mode=='test': <br>\n            r = 0<br>\n        else: <br>\n            r = int(row['spectrogram_label_offset_seconds'] // 2)</p>\n<pre><code>     = self.spectograms[row.spec_id][r:r+, :].T.reshape(, , )\n\n    \n     = np.clip(spectogram_data, np.exp(-), np.exp())\n     = np.log(spectogram_data)\n\n    \n     = np.nanmean(spectogram_data, axis=(, ))\n     = np.nanstd(spectogram_data, axis=(, ))\n    = spectogram_data.transpose(,,)\n     = (spectogram_data - mu[ None, None,:]) / (std[ None, None,:] + e-)\n     = np.nan_to_num(spectogram_data, nan=.)\n\n    \n    [:-, :, :] = spectogram_data[:, :-, :] / .\n     = self.eeg_spectograms[row.eeg_id]\n    [:, :, :] = img\n\n\n\n     self.mode=='test': \n         = \n    : \n         = int(row2['spectrogram_label_offset_seconds'] // )\n\n     = self.spectograms[row2.spec_id][r:r+, :].T.reshape(, , )\n\n    \n     = np.clip(spectogram_data, np.exp(-), np.exp())\n     = np.log(spectogram_data)\n\n    \n     = np.nanmean(spectogram_data, axis=(, ))\n     = np.nanstd(spectogram_data, axis=(, ))\n     = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + e-)\n     = np.nan_to_num(spectogram_data, nan=.)\n\n\n    \n    [:-, :, :] = spectogram_data.transpose(,,)[:, :-, :] / .\n     = self.eeg_spectograms[row2.eeg_id]\n    [:, :, :] = img        \n\n\n     self.mode=='test': \n         = \n    : \n         = int(row3['spectrogram_label_offset_seconds'] // )\n\n     = self.spectograms[row3.spec_id][r:r+, :].T.reshape(, , )\n\n    \n     = np.clip(spectogram_data, np.exp(-), np.exp())\n     = np.log(spectogram_data)\n\n    \n     = np.nanmean(spectogram_data, axis=(, ))\n     = np.nanstd(spectogram_data, axis=(, ))\n     = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + e-)\n     = np.nan_to_num(spectogram_data, nan=.)\n\n\n    \n    [:-, :, :] = spectogram_data.transpose(,,)[:, :-, :] / .\n     = self.eeg_spectograms[row3.eeg_id]\n    [:, :, :] = img    \n\n\n     self.mode=='test': \n         = \n    : \n         = int(row4['spectrogram_label_offset_seconds'] // )\n\n     = self.spectograms[row4.spec_id][r:r+, :].T.reshape(, , )\n\n    \n     = np.clip(spectogram_data, np.exp(-), np.exp())\n     = np.log(spectogram_data)\n\n    \n     = np.nanmean(spectogram_data, axis=(, ))\n     = np.nanstd(spectogram_data, axis=(, ))\n     = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + e-)\n     = np.nan_to_num(spectogram_data, nan=.)\n\n\n    \n    [:-, :, :] = spectogram_data.transpose(,,)[:, :-, :] / .\n     = self.eeg_spectograms[row4.eeg_id]\n    [:, :, :] = img    \n\n\n\n     self.mode=='test': \n         = \n    : \n         = int(row5['spectrogram_label_offset_seconds'] // )\n\n      \n     = self.spectograms[row5.spec_id][r:r+, :].T.reshape(, , )\n\n    \n     = np.clip(spectogram_data, np.exp(-), np.exp())\n     = np.log(spectogram_data)\n\n    \n     = np.nanmean(spectogram_data, axis=(, ))\n     = np.nanstd(spectogram_data, axis=(, ))\n     = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + e-)\n     = np.nan_to_num(spectogram_data, nan=.)\n\n\n    \n    [:-, :, :] = spectogram_data.transpose(,,)[:, :-, :] / .\n     = self.eeg_spectograms[row5.eeg_id]\n    [:, :, :] = img    \n\n\n\n     self.mode != 'test':\n        [:-] = row[TARGETS].values.astype(np.float32)\n        [-] = row['total_evaluators']\n\n     X, y`\n</code></pre>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 2775336,
      "author_name": "llf4puppy",
      "author_url": "",
      "post_date": "04/25/2024 16:17:47",
      "content": "<p>Great work!</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2743687": "I'd like to share a little trick that can boost scores slightly. I've noticed that a single patient often corresponds to multiple eeg_id and spectrogram_id, yet the final expert_consensus and the labels to be predicted for the same patient are indeed very similar. So, when loading the data, I load four other sets of similar data for one patient to predict the final result together. This approach can increase scores by 0.01 to 0.02.",
    "2743793": "I used a similar idea. \n\nFirst, the model was trained to predict one of the 6 classes, but then I cut off the final classifiers and predicted embedding of each item.\n\nSecond, all the items with the same patient_id were grouped, and their embeddings were averaged. \n\nThird, I trained a new classifier, which takes both item embedding and averaged embedding as its input.\n\nThis approach allows to deal with any number of items in each group. Also it takes into account both the information about what diagnosis is usual for the patient, and what is specific in each particular eeg/sg.",
    "2744587": "Thank you for your sharing.😀Your approach is quite innovative! You achieve a more comprehensive feature representation.\nThis is what I did:\n`    \ndef __data_generation(self, index):\n        \"\"\"\n        Generates data containing batch_size samples.\n        \"\"\"\n        X = np.zeros((128, 256, 40), dtype='float32')\n        y = np.zeros(7, dtype='float32')\n        img = np.ones((128,256), dtype='float32')\n        row = self.df.iloc[index]\n        patient_id = row['patient_id']\n        ddf = self.df[self.df['patient_id'] == patient_id]\n        if ddf.shape[0] >= 4:\n            rows = ddf.sample(n=4,random_state=42)\n        else:\n            rows = ddf.sample(n=4, replace=True,random_state=42)\n        row2 = rows.iloc[0]\n        row3 = rows.iloc[1]\n        row4 = rows.iloc[2]\n        row5 = rows.iloc[3]\n        if self.mode=='test': \n            r = 0\n        else: \n            r = int(row['spectrogram_label_offset_seconds'] // 2)\n            \n        spectogram_data = self.spectograms[row.spec_id][r:r+300, :400].T.reshape(4, 100, 300)\n\n        # Log transform\n        spectogram_data = np.clip(spectogram_data, np.exp(-4), np.exp(8))\n        spectogram_data = np.log(spectogram_data)\n\n        # Standardize per image\n        mu = np.nanmean(spectogram_data, axis=(1, 2))\n        std = np.nanstd(spectogram_data, axis=(1, 2))\n        spectogram_data= spectogram_data.transpose(1,2,0)\n        spectogram_data = (spectogram_data - mu[ None, None,:]) / (std[ None, None,:] + 1e-6)\n        spectogram_data = np.nan_to_num(spectogram_data, nan=0.0)\n\n        # Update X\n        X[14:-14, :, :4] = spectogram_data[:, 22:-22, :] / 2.0\n        img = self.eeg_spectograms[row.eeg_id]\n        X[:, :, 4:8] = img\n\n            \n            \n        if self.mode=='test': \n            r = 0\n        else: \n            r = int(row2['spectrogram_label_offset_seconds'] // 2)\n            \n        spectogram_data = self.spectograms[row2.spec_id][r:r+300, :400].T.reshape(4, 100, 300)\n\n        # Log transform\n        spectogram_data = np.clip(spectogram_data, np.exp(-4), np.exp(8))\n        spectogram_data = np.log(spectogram_data)\n\n        # Standardize per image\n        mu = np.nanmean(spectogram_data, axis=(1, 2))\n        std = np.nanstd(spectogram_data, axis=(1, 2))\n        spectogram_data = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + 1e-6)\n        spectogram_data = np.nan_to_num(spectogram_data, nan=0.0)\n\n\n        # Update X\n        X[14:-14, :, 8:12] = spectogram_data.transpose(1,2,0)[:, 22:-22, :] / 2.0\n        img = self.eeg_spectograms[row2.eeg_id]\n        X[:, :, 12:16] = img        \n   \n\n        if self.mode=='test': \n            r = 0\n        else: \n            r = int(row3['spectrogram_label_offset_seconds'] // 2)\n                \n        spectogram_data = self.spectograms[row3.spec_id][r:r+300, :400].T.reshape(4, 100, 300)\n\n        # Log transform\n        spectogram_data = np.clip(spectogram_data, np.exp(-4), np.exp(8))\n        spectogram_data = np.log(spectogram_data)\n\n        # Standardize per image\n        mu = np.nanmean(spectogram_data, axis=(1, 2))\n        std = np.nanstd(spectogram_data, axis=(1, 2))\n        spectogram_data = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + 1e-6)\n        spectogram_data = np.nan_to_num(spectogram_data, nan=0.0)\n\n\n        # Update X\n        X[14:-14, :, 16:20] = spectogram_data.transpose(1,2,0)[:, 22:-22, :] / 2.0\n        img = self.eeg_spectograms[row3.eeg_id]\n        X[:, :, 20:24] = img    \n            \n            \n        if self.mode=='test': \n            r = 0\n        else: \n            r = int(row4['spectrogram_label_offset_seconds'] // 2)\n\n        spectogram_data = self.spectograms[row4.spec_id][r:r+300, :400].T.reshape(4, 100, 300)\n\n        # Log transform\n        spectogram_data = np.clip(spectogram_data, np.exp(-4), np.exp(8))\n        spectogram_data = np.log(spectogram_data)\n\n        # Standardize per image\n        mu = np.nanmean(spectogram_data, axis=(1, 2))\n        std = np.nanstd(spectogram_data, axis=(1, 2))\n        spectogram_data = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + 1e-6)\n        spectogram_data = np.nan_to_num(spectogram_data, nan=0.0)\n\n\n        # Update X\n        X[14:-14, :, 24:28] = spectogram_data.transpose(1,2,0)[:, 22:-22, :] / 2.0\n        img = self.eeg_spectograms[row4.eeg_id]\n        X[:, :, 28:32] = img    \n            \n  \n\n        if self.mode=='test': \n            r = 0\n        else: \n            r = int(row5['spectrogram_label_offset_seconds'] // 2)\n                \n          # 提取spectrogram数据并重新排布为三维数组\n        spectogram_data = self.spectograms[row5.spec_id][r:r+300, :400].T.reshape(4, 100, 300)\n\n        # Log transform\n        spectogram_data = np.clip(spectogram_data, np.exp(-4), np.exp(8))\n        spectogram_data = np.log(spectogram_data)\n\n        # Standardize per image\n        mu = np.nanmean(spectogram_data, axis=(1, 2))\n        std = np.nanstd(spectogram_data, axis=(1, 2))\n        spectogram_data = (spectogram_data - mu[:, None, None]) / (std[:, None, None] + 1e-6)\n        spectogram_data = np.nan_to_num(spectogram_data, nan=0.0)\n\n\n        # Update X\n        X[14:-14, :, 32:36] = spectogram_data.transpose(1,2,0)[:, 22:-22, :] / 2.0\n        img = self.eeg_spectograms[row5.eeg_id]\n        X[:, :, 36:40] = img    \n            \n            \n            \n        if self.mode != 'test':\n            y[:-1] = row[TARGETS].values.astype(np.float32)\n            y[-1] = row['total_evaluators']\n            \n        return X, y`",
    "2775336": "Great work!"
  },
  "source": "meta"
}