{
  "id": 37314,
  "title": "RLE encoding axes order",
  "url": "/competitions/carvana-image-masking-challenge/discussion/37314",
  "author_name": "",
  "post_date": "2017-07-31T06:40:10.089391500Z",
  "votes": 8,
  "comment_count": 3,
  "views": 0,
  "content": "<p>Hi!\nI think there is discrepancy between the competition rules and the actual way to submissions are checked. In the most popular kernels for mask-to-RLE encoding (<a href=\"https://www.kaggle.com/stainsby/fast-tested-rle\">https://www.kaggle.com/stainsby/fast-tested-rle</a>, <a href=\"https://www.kaggle.com/paulorzp/fast-run-length-encode\">https://www.kaggle.com/paulorzp/fast-run-length-encode</a>) the competitors use <code>.flatten()</code> method on a mask which concatenates rows ([r0, r1, r2, ...]). So the order of elements is (1, 1), (1, 2), etc. And it seems that is working for them perfectly fine.\nFor example, from Sam's kernel:</p>\n\n<pre><code>est_mask = np.asarray(\n [[0, 0, 0, 0],\n  [0, 0, 1, 1],\n  [0, 0, 1, 1],\n  [0, 0, 0, 0]])\nassert rle_to_string(rle_encode(test_mask)) == '7 2 11 2'\n</code></pre>\n\n<p>On the other hand, the competition rules say <code>The pixels are numbered from top to bottom, then left to right: 1 is pixel (1,1), 2 is pixel (2,1), etc.</code>, i.e. the above is not correct, as the RLE codes are expected to be built in a <em>column-first</em> manner: [c0, c1, c2, ...].</p>\n\n<p>So, the correct RLE for the example above has to be <code>10 2 14 2</code>.</p>\n\n<p>I've tried both methods, but my submissions fail on the second one due to a timeout.\nCould someone, please, clarify the correct format? If I'm right, the competition rules has to be fixed.</p>",
  "messages": [
    {
      "id": "208817",
      "postDate": "07/31/2017 06:40:10",
      "content": "<p>Hi!\nI think there is discrepancy between the competition rules and the actual way to submissions are checked. In the most popular kernels for mask-to-RLE encoding (<a href=\"https://www.kaggle.com/stainsby/fast-tested-rle\">https://www.kaggle.com/stainsby/fast-tested-rle</a>, <a href=\"https://www.kaggle.com/paulorzp/fast-run-length-encode\">https://www.kaggle.com/paulorzp/fast-run-length-encode</a>) the competitors use <code>.flatten()</code> method on a mask which concatenates rows ([r0, r1, r2, ...]). So the order of elements is (1, 1), (1, 2), etc. And it seems that is working for them perfectly fine.\nFor example, from Sam's kernel:</p>\n\n<pre><code>est_mask = np.asarray(\n [[0, 0, 0, 0],\n  [0, 0, 1, 1],\n  [0, 0, 1, 1],\n  [0, 0, 0, 0]])\nassert rle_to_string(rle_encode(test_mask)) == '7 2 11 2'\n</code></pre>\n\n<p>On the other hand, the competition rules say <code>The pixels are numbered from top to bottom, then left to right: 1 is pixel (1,1), 2 is pixel (2,1), etc.</code>, i.e. the above is not correct, as the RLE codes are expected to be built in a <em>column-first</em> manner: [c0, c1, c2, ...].</p>\n\n<p>So, the correct RLE for the example above has to be <code>10 2 14 2</code>.</p>\n\n<p>I've tried both methods, but my submissions fail on the second one due to a timeout.\nCould someone, please, clarify the correct format? If I'm right, the competition rules has to be fixed.</p>",
      "rawMarkdown": "Hi!\nI think there is discrepancy between the competition rules and the actual way to submissions are checked. In the most popular kernels for mask-to-RLE encoding (https://www.kaggle.com/stainsby/fast-tested-rle, https://www.kaggle.com/paulorzp/fast-run-length-encode) the competitors use `.flatten()` method on a mask which concatenates rows ([r0, r1, r2, ...]). So the order of elements is (1, 1), (1, 2), etc. And it seems that is working for them perfectly fine.\nFor example, from Sam's kernel:\n\n    est_mask = np.asarray(\n     [[0, 0, 0, 0],\n      [0, 0, 1, 1],\n      [0, 0, 1, 1],\n      [0, 0, 0, 0]])\n    assert rle_to_string(rle_encode(test_mask)) == '7 2 11 2'\n\nOn the other hand, the competition rules say `The pixels are numbered from top to bottom, then left to right: 1 is pixel (1,1), 2 is pixel (2,1), etc.`, i.e. the above is not correct, as the RLE codes are expected to be built in a _column-first_ manner: [c0, c1, c2, ...].\n\nSo, the correct RLE for the example above has to be `10 2 14 2`.\n\nI've tried both methods, but my submissions fail on the second one due to a timeout.\nCould someone, please, clarify the correct format? If I'm right, the competition rules has to be fixed.",
      "votes": null
    },
    {
      "id": "208819",
      "postDate": "07/31/2017 06:45:15",
      "content": "<p>Agreed, I've been using this kernel and got good results, not to mention it actually verifies the train masks. I think the wording should be \"The pixels are numbered from left to right, then top to bottom: 1 is pixel (1,1), 2 is pixel (1,2), etc.\"</p>",
      "rawMarkdown": "Agreed, I've been using this kernel and got good results, not to mention it actually verifies the train masks. I think the wording should be \"The pixels are numbered from left to right, then top to bottom: 1 is pixel (1,1), 2 is pixel (1,2), etc.\"",
      "votes": null
    },
    {
      "id": "208882",
      "postDate": "07/31/2017 13:44:40",
      "content": "<p>A few days ago I came across the same issue when I saw the rules, because I thought \"hey its not good to use column-wise computation, since we have more mask pixels row-wise.\" Than I started to check the rle/flatten calls as well:</p>\n\n<p>If you look at the shape after ndimage.imread and PIL.open, you will see the matrix is transposed. The shape is (h,w) and thus flatten(default=row-wise) will be column-wise for (w,h) and so, comply with the competition rules.</p>\n\n<p>But I am still confused, something is weird :))</p>",
      "rawMarkdown": "A few days ago I came across the same issue when I saw the rules, because I thought \"hey its not good to use column-wise computation, since we have more mask pixels row-wise.\" Than I started to check the rle/flatten calls as well:\n\nIf you look at the shape after ndimage.imread and PIL.open, you will see the matrix is transposed. The shape is (h,w) and thus flatten(default=row-wise) will be column-wise for (w,h) and so, comply with the competition rules.\n\nBut I am still confused, something is weird :))",
      "votes": null
    },
    {
      "id": "208888",
      "postDate": "07/31/2017 14:05:14",
      "content": "<p>Ah, indeed, I've missed this part of the kernel.\nAccording to the docs of <code>scipy.ndimage.imread</code> - <code>When flatten is True, the image is converted using mode ‘F’.</code>. So it is column-wise after all...</p>",
      "rawMarkdown": "Ah, indeed, I've missed this part of the kernel.\nAccording to the docs of `scipy.ndimage.imread` - `When flatten is True, the image is converted using mode ‘F’.`. So it is column-wise after all...",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 208819,
      "author_name": "vilmar",
      "author_url": "",
      "post_date": "07/31/2017 06:45:15",
      "content": "<p>Agreed, I've been using this kernel and got good results, not to mention it actually verifies the train masks. I think the wording should be \"The pixels are numbered from left to right, then top to bottom: 1 is pixel (1,1), 2 is pixel (1,2), etc.\"</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 208882,
      "author_name": "firolino",
      "author_url": "",
      "post_date": "07/31/2017 13:44:40",
      "content": "<p>A few days ago I came across the same issue when I saw the rules, because I thought \"hey its not good to use column-wise computation, since we have more mask pixels row-wise.\" Than I started to check the rle/flatten calls as well:</p>\n\n<p>If you look at the shape after ndimage.imread and PIL.open, you will see the matrix is transposed. The shape is (h,w) and thus flatten(default=row-wise) will be column-wise for (w,h) and so, comply with the competition rules.</p>\n\n<p>But I am still confused, something is weird :))</p>",
      "votes": null,
      "replies": [
        {
          "id": 208888,
          "author_name": "panfilov",
          "author_url": "",
          "post_date": "07/31/2017 14:05:14",
          "content": "<p>Ah, indeed, I've missed this part of the kernel.\nAccording to the docs of <code>scipy.ndimage.imread</code> - <code>When flatten is True, the image is converted using mode ‘F’.</code>. So it is column-wise after all...</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "208817": "Hi!\nI think there is discrepancy between the competition rules and the actual way to submissions are checked. In the most popular kernels for mask-to-RLE encoding (https://www.kaggle.com/stainsby/fast-tested-rle, https://www.kaggle.com/paulorzp/fast-run-length-encode) the competitors use `.flatten()` method on a mask which concatenates rows ([r0, r1, r2, ...]). So the order of elements is (1, 1), (1, 2), etc. And it seems that is working for them perfectly fine.\nFor example, from Sam's kernel:\n\n    est_mask = np.asarray(\n     [[0, 0, 0, 0],\n      [0, 0, 1, 1],\n      [0, 0, 1, 1],\n      [0, 0, 0, 0]])\n    assert rle_to_string(rle_encode(test_mask)) == '7 2 11 2'\n\nOn the other hand, the competition rules say `The pixels are numbered from top to bottom, then left to right: 1 is pixel (1,1), 2 is pixel (2,1), etc.`, i.e. the above is not correct, as the RLE codes are expected to be built in a _column-first_ manner: [c0, c1, c2, ...].\n\nSo, the correct RLE for the example above has to be `10 2 14 2`.\n\nI've tried both methods, but my submissions fail on the second one due to a timeout.\nCould someone, please, clarify the correct format? If I'm right, the competition rules has to be fixed.",
    "208819": "Agreed, I've been using this kernel and got good results, not to mention it actually verifies the train masks. I think the wording should be \"The pixels are numbered from left to right, then top to bottom: 1 is pixel (1,1), 2 is pixel (1,2), etc.\"",
    "208882": "A few days ago I came across the same issue when I saw the rules, because I thought \"hey its not good to use column-wise computation, since we have more mask pixels row-wise.\" Than I started to check the rle/flatten calls as well:\n\nIf you look at the shape after ndimage.imread and PIL.open, you will see the matrix is transposed. The shape is (h,w) and thus flatten(default=row-wise) will be column-wise for (w,h) and so, comply with the competition rules.\n\nBut I am still confused, something is weird :))",
    "208888": "Ah, indeed, I've missed this part of the kernel.\nAccording to the docs of `scipy.ndimage.imread` - `When flatten is True, the image is converted using mode ‘F’.`. So it is column-wise after all..."
  },
  "source": "meta"
}