{
  "id": 459639,
  "title": "87th Place solution, 2D Object Detection",
  "url": "/competitions/child-mind-institute-detect-sleep-states/discussion/459639",
  "author_name": "",
  "post_date": "2023-12-06T04:31:49.636210500Z",
  "votes": 24,
  "comment_count": 1,
  "views": 0,
  "content": "<p>I thank all those who organized this competition. I believe that I and many other competitors learned a lot.</p>\n<h1>source codes</h1>\n<p><a href=\"https://github.com/itsuki8914/Child-Mind-Institute---Detect-Sleep-States-87th-Place-Codes\" target=\"_blank\">You can find my solution source code here</a>.</p>\n<h1>TL;DR</h1>\n<ul>\n<li>My solution is <strong>2D object detection</strong>.</li>\n<li><strong>Creating pseudo images</strong> using transposed convolutions.</li>\n<li>Detecting events with <strong>Faster R-CNN</strong>.</li>\n</ul>\n<p>My solution is to create an image with a height of 384 and a width of 2880 and perform object detection. My solution is a little long and may be wasteful😥</p>\n<h1>Data preparing</h1>\n<ol>\n<li>Extract anglez, enmo, and hour features for each step and output to csv.</li>\n<li>Output events to csv for each sample.</li>\n</ol>\n<h1>Feature Engineering</h1>\n<p>anglez is divided by 90 so that it falls within the range [-1, 1]. enmo is normalized using mean and std. and I used <strong>log1p for raw emno</strong>.<br>\nFor these three features, I performed basic feature engineering of time series data and created 79 features.</p>\n<h1>Labelling</h1>\n<p>To accommodate the object detection task, make the label a rectangle. The label is <strong>120 points before and after the event point</strong>. For example, if there is an event point at position 4992, the label would be (0, 4872, 384, 5112).</p>\n<h1>Basic strategy</h1>\n<p>randomly sampled a chunk of 2880 steps (4 hours) and used it as input. The input shape is now (Batch_size, 79 <strong>+1</strong>, 2880). <strong>+1</strong> indicates hour feature. This was converted into a pseudo-image for object detection.</p>\n<h1>Model architecture</h1>\n<p>Models can be divided into two main categories. </p>\n<ul>\n<li>The first is a network that creates pseudo-images</li>\n<li>The second is a network that performs object detection on them. I used Faster R-CNN for this.</li>\n</ul>\n<p>The first one looks like this. The shape is channel first.</p>\n<table>\n<thead>\n<tr>\n<th>block name</th>\n<th>input shape</th>\n<th>output shape</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>hour_emb</td>\n<td>(1, 2880)</td>\n<td>(32, 2880)</td>\n</tr>\n<tr>\n<td>inter_conv</td>\n<td>(79+32, 2880)</td>\n<td>(2048, 2880)</td>\n</tr>\n<tr>\n<td>upsample_resblocks * 8</td>\n<td>(2048, 1, 2880)</td>\n<td>(3, 384, 2880)</td>\n</tr>\n</tbody>\n</table>\n<p>In addition, resblock consists of the following.</p>\n<table>\n<thead>\n<tr>\n<th>operation</th>\n<th>-</th>\n<th>skip</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>BN</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>LReLU(0.2)</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>TransposedConv2d</td>\n<td></td>\n<td>TransposedConv2d</td>\n</tr>\n<tr>\n<td>BN</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>LReLU(0.2)</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>Conv2d</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>👉</td>\n<td>element-wise sum</td>\n<td>👈</td>\n</tr>\n</tbody>\n</table>\n<p>The second is the general Faster R-CNN. I used timm's <strong>convnextv2_base.fcmae_ft_in22k_in1k_384</strong> as the backbone.</p>\n<h1>Training</h1>\n<p>All data was used as training data, as there was not enough time to ensemble this model within the submission.<br>\nI used RAdam optimizer. lr=Batch_size * 1.25e-5, weight_decay=1e-6.<br>\nThe learning rate was set to decay exponentially by a factor of 0.95 every epoch.<br>\nI use <a href=\"https://github.com/pytorch/vision/tree/main/references/detection\" target=\"_blank\">TorchVision's helper functions</a> for the training loop to make it easier.</p>\n<h1>Inference and Postprocess</h1>\n<p>Only a single model is used because inference is time consuming.<br>\nFor each sequence, a window of 2880 points and a stride of 1440 points were used for inference. <strong>Only the center 1440 points of the window are used.</strong> <br>\nTake the average of the time axis of the rectangle detected by inference. Simply divide by 2. No other kind of post-processing was done.</p>\n<p>When folded into 5 folds, the CV was about 0.770.<br>\nAnd in the final submission model, Public LB was 0.730, and Private LB was 0.781.</p>\n<p>If you have any concerns or questions, feel free to write me!<br>\nThanks for reading this far! Cheers!🍻</p>",
  "messages": [
    {
      "id": "2550492",
      "postDate": "12/06/2023 04:31:49",
      "content": "<p>I thank all those who organized this competition. I believe that I and many other competitors learned a lot.</p>\n<h1>source codes</h1>\n<p><a href=\"https://github.com/itsuki8914/Child-Mind-Institute---Detect-Sleep-States-87th-Place-Codes\" target=\"_blank\">You can find my solution source code here</a>.</p>\n<h1>TL;DR</h1>\n<ul>\n<li>My solution is <strong>2D object detection</strong>.</li>\n<li><strong>Creating pseudo images</strong> using transposed convolutions.</li>\n<li>Detecting events with <strong>Faster R-CNN</strong>.</li>\n</ul>\n<p>My solution is to create an image with a height of 384 and a width of 2880 and perform object detection. My solution is a little long and may be wasteful😥</p>\n<h1>Data preparing</h1>\n<ol>\n<li>Extract anglez, enmo, and hour features for each step and output to csv.</li>\n<li>Output events to csv for each sample.</li>\n</ol>\n<h1>Feature Engineering</h1>\n<p>anglez is divided by 90 so that it falls within the range [-1, 1]. enmo is normalized using mean and std. and I used <strong>log1p for raw emno</strong>.<br>\nFor these three features, I performed basic feature engineering of time series data and created 79 features.</p>\n<h1>Labelling</h1>\n<p>To accommodate the object detection task, make the label a rectangle. The label is <strong>120 points before and after the event point</strong>. For example, if there is an event point at position 4992, the label would be (0, 4872, 384, 5112).</p>\n<h1>Basic strategy</h1>\n<p>randomly sampled a chunk of 2880 steps (4 hours) and used it as input. The input shape is now (Batch_size, 79 <strong>+1</strong>, 2880). <strong>+1</strong> indicates hour feature. This was converted into a pseudo-image for object detection.</p>\n<h1>Model architecture</h1>\n<p>Models can be divided into two main categories. </p>\n<ul>\n<li>The first is a network that creates pseudo-images</li>\n<li>The second is a network that performs object detection on them. I used Faster R-CNN for this.</li>\n</ul>\n<p>The first one looks like this. The shape is channel first.</p>\n<table>\n<thead>\n<tr>\n<th>block name</th>\n<th>input shape</th>\n<th>output shape</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>hour_emb</td>\n<td>(1, 2880)</td>\n<td>(32, 2880)</td>\n</tr>\n<tr>\n<td>inter_conv</td>\n<td>(79+32, 2880)</td>\n<td>(2048, 2880)</td>\n</tr>\n<tr>\n<td>upsample_resblocks * 8</td>\n<td>(2048, 1, 2880)</td>\n<td>(3, 384, 2880)</td>\n</tr>\n</tbody>\n</table>\n<p>In addition, resblock consists of the following.</p>\n<table>\n<thead>\n<tr>\n<th>operation</th>\n<th>-</th>\n<th>skip</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>BN</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>LReLU(0.2)</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>TransposedConv2d</td>\n<td></td>\n<td>TransposedConv2d</td>\n</tr>\n<tr>\n<td>BN</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>LReLU(0.2)</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>Conv2d</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>👉</td>\n<td>element-wise sum</td>\n<td>👈</td>\n</tr>\n</tbody>\n</table>\n<p>The second is the general Faster R-CNN. I used timm's <strong>convnextv2_base.fcmae_ft_in22k_in1k_384</strong> as the backbone.</p>\n<h1>Training</h1>\n<p>All data was used as training data, as there was not enough time to ensemble this model within the submission.<br>\nI used RAdam optimizer. lr=Batch_size * 1.25e-5, weight_decay=1e-6.<br>\nThe learning rate was set to decay exponentially by a factor of 0.95 every epoch.<br>\nI use <a href=\"https://github.com/pytorch/vision/tree/main/references/detection\" target=\"_blank\">TorchVision's helper functions</a> for the training loop to make it easier.</p>\n<h1>Inference and Postprocess</h1>\n<p>Only a single model is used because inference is time consuming.<br>\nFor each sequence, a window of 2880 points and a stride of 1440 points were used for inference. <strong>Only the center 1440 points of the window are used.</strong> <br>\nTake the average of the time axis of the rectangle detected by inference. Simply divide by 2. No other kind of post-processing was done.</p>\n<p>When folded into 5 folds, the CV was about 0.770.<br>\nAnd in the final submission model, Public LB was 0.730, and Private LB was 0.781.</p>\n<p>If you have any concerns or questions, feel free to write me!<br>\nThanks for reading this far! Cheers!🍻</p>",
      "rawMarkdown": "I thank all those who organized this competition. I believe that I and many other competitors learned a lot.\n\n# source codes\n[You can find my solution source code here](https://github.com/itsuki8914/Child-Mind-Institute---Detect-Sleep-States-87th-Place-Codes).\n\n# TL;DR\n- My solution is **2D object detection**.\n- **Creating pseudo images** using transposed convolutions.\n- Detecting events with **Faster R-CNN**.\n\nMy solution is to create an image with a height of 384 and a width of 2880 and perform object detection. My solution is a little long and may be wasteful😥\n\n\n# Data preparing\n1. Extract anglez, enmo, and hour features for each step and output to csv.\n2. Output events to csv for each sample.\n\n# Feature Engineering\nanglez is divided by 90 so that it falls within the range [-1, 1]. enmo is normalized using mean and std. and I used **log1p for raw emno**.\nFor these three features, I performed basic feature engineering of time series data and created 79 features.\n\n# Labelling\nTo accommodate the object detection task, make the label a rectangle. The label is **120 points before and after the event point**. For example, if there is an event point at position 4992, the label would be (0, 4872, 384, 5112).\n\n# Basic strategy\nrandomly sampled a chunk of 2880 steps (4 hours) and used it as input. The input shape is now (Batch_size, 79 **+1**, 2880). **+1** indicates hour feature. This was converted into a pseudo-image for object detection.\n\n# Model architecture\nModels can be divided into two main categories. \n- The first is a network that creates pseudo-images\n- The second is a network that performs object detection on them. I used Faster R-CNN for this.\n\nThe first one looks like this. The shape is channel first.\n\n| block name | input shape | output shape |\n| --- | --- | --- |\n| hour_emb | (1, 2880) | (32, 2880) |\n| inter_conv | (79+32, 2880)  | (2048, 2880) |\n| upsample_resblocks * 8 | (2048, 1, 2880) | (3, 384, 2880) |\n\nIn addition, resblock consists of the following.\n\n| operation | - | skip |\n| --- | --- | --- |\n| BN |  |  |\n| LReLU(0.2) |  |  |\n| TransposedConv2d|  | TransposedConv2d |\n| BN |  |  |\n| LReLU(0.2) |  |  |\n| Conv2d|  |  |\n| 👉 | element-wise sum | 👈 |\n\n\nThe second is the general Faster R-CNN. I used timm's **convnextv2_base.fcmae_ft_in22k_in1k_384** as the backbone.\n\n# Training\nAll data was used as training data, as there was not enough time to ensemble this model within the submission.\nI used RAdam optimizer. lr=Batch_size * 1.25e-5, weight_decay=1e-6.\nThe learning rate was set to decay exponentially by a factor of 0.95 every epoch.\nI use [TorchVision's helper functions](https://github.com/pytorch/vision/tree/main/references/detection) for the training loop to make it easier.\n\n# Inference and Postprocess\nOnly a single model is used because inference is time consuming.\nFor each sequence, a window of 2880 points and a stride of 1440 points were used for inference. **Only the center 1440 points of the window are used.** \nTake the average of the time axis of the rectangle detected by inference. Simply divide by 2. No other kind of post-processing was done.\n\nWhen folded into 5 folds, the CV was about 0.770.\nAnd in the final submission model, Public LB was 0.730, and Private LB was 0.781.\n\nIf you have any concerns or questions, feel free to write me!\nThanks for reading this far! Cheers!🍻",
      "votes": null
    },
    {
      "id": "2551261",
      "postDate": "12/06/2023 15:35:40",
      "content": "<p>An interesting and impressive solution yet again! I was glad to compete with you and see you shake up! You got me this time! Hahaha</p>",
      "rawMarkdown": "An interesting and impressive solution yet again! I was glad to compete with you and see you shake up! You got me this time! Hahaha",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2551261,
      "author_name": "cody11null",
      "author_url": "",
      "post_date": "12/06/2023 15:35:40",
      "content": "<p>An interesting and impressive solution yet again! I was glad to compete with you and see you shake up! You got me this time! Hahaha</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2550492": "I thank all those who organized this competition. I believe that I and many other competitors learned a lot.\n\n# source codes\n[You can find my solution source code here](https://github.com/itsuki8914/Child-Mind-Institute---Detect-Sleep-States-87th-Place-Codes).\n\n# TL;DR\n- My solution is **2D object detection**.\n- **Creating pseudo images** using transposed convolutions.\n- Detecting events with **Faster R-CNN**.\n\nMy solution is to create an image with a height of 384 and a width of 2880 and perform object detection. My solution is a little long and may be wasteful😥\n\n\n# Data preparing\n1. Extract anglez, enmo, and hour features for each step and output to csv.\n2. Output events to csv for each sample.\n\n# Feature Engineering\nanglez is divided by 90 so that it falls within the range [-1, 1]. enmo is normalized using mean and std. and I used **log1p for raw emno**.\nFor these three features, I performed basic feature engineering of time series data and created 79 features.\n\n# Labelling\nTo accommodate the object detection task, make the label a rectangle. The label is **120 points before and after the event point**. For example, if there is an event point at position 4992, the label would be (0, 4872, 384, 5112).\n\n# Basic strategy\nrandomly sampled a chunk of 2880 steps (4 hours) and used it as input. The input shape is now (Batch_size, 79 **+1**, 2880). **+1** indicates hour feature. This was converted into a pseudo-image for object detection.\n\n# Model architecture\nModels can be divided into two main categories. \n- The first is a network that creates pseudo-images\n- The second is a network that performs object detection on them. I used Faster R-CNN for this.\n\nThe first one looks like this. The shape is channel first.\n\n| block name | input shape | output shape |\n| --- | --- | --- |\n| hour_emb | (1, 2880) | (32, 2880) |\n| inter_conv | (79+32, 2880)  | (2048, 2880) |\n| upsample_resblocks * 8 | (2048, 1, 2880) | (3, 384, 2880) |\n\nIn addition, resblock consists of the following.\n\n| operation | - | skip |\n| --- | --- | --- |\n| BN |  |  |\n| LReLU(0.2) |  |  |\n| TransposedConv2d|  | TransposedConv2d |\n| BN |  |  |\n| LReLU(0.2) |  |  |\n| Conv2d|  |  |\n| 👉 | element-wise sum | 👈 |\n\n\nThe second is the general Faster R-CNN. I used timm's **convnextv2_base.fcmae_ft_in22k_in1k_384** as the backbone.\n\n# Training\nAll data was used as training data, as there was not enough time to ensemble this model within the submission.\nI used RAdam optimizer. lr=Batch_size * 1.25e-5, weight_decay=1e-6.\nThe learning rate was set to decay exponentially by a factor of 0.95 every epoch.\nI use [TorchVision's helper functions](https://github.com/pytorch/vision/tree/main/references/detection) for the training loop to make it easier.\n\n# Inference and Postprocess\nOnly a single model is used because inference is time consuming.\nFor each sequence, a window of 2880 points and a stride of 1440 points were used for inference. **Only the center 1440 points of the window are used.** \nTake the average of the time axis of the rectangle detected by inference. Simply divide by 2. No other kind of post-processing was done.\n\nWhen folded into 5 folds, the CV was about 0.770.\nAnd in the final submission model, Public LB was 0.730, and Private LB was 0.781.\n\nIf you have any concerns or questions, feel free to write me!\nThanks for reading this far! Cheers!🍻",
    "2551261": "An interesting and impressive solution yet again! I was glad to compete with you and see you shake up! You got me this time! Hahaha"
  },
  "source": "meta"
}