{
  "id": 463121,
  "title": "The issue with the albumentations library",
  "url": "/competitions/blood-vessel-segmentation/discussion/463121",
  "author_name": "siwooyong",
  "post_date": "2023-12-23T10:16:29.377000",
  "votes": 9,
  "comment_count": 16,
  "views": 0,
  "content": "<p>It seems there might be an issue when applying size-scale transformations (such as resize, shiftscalerotate, etc.) using the albumentations library(perhaps due to a problem in quantization process)</p>\n<p>In the attached images, the left line shows a mask resized through the  \"albumentations.Resize\", while the right line exhibits a mask resized using \"cv2.resize\" without quantization. (Those pictures are the result of reducing the original size by a factor of x4.) <br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F8251891%2Fc7e4ca43c5f5418583983bbb1ec0a08c%2F(1).png?generation=1703326345488635&amp;alt=media\" alt=\"\"></p>\n<p>The left mask was obtained using the code:</p>\n<pre><code>A.Resize(h, w)(=img, =mask)\n</code></pre>\n<p>While the right mask was obtained using the code: </p>\n<pre><code>cv2(, (w, h))\ncv2(, (w, h))\n</code></pre>\n<p>Could it be that I've used the code incorrectly?</p>",
  "messages": [
    {
      "id": 2571547,
      "postDate": "2023-12-23T10:16:29.377Z",
      "content": "<p>It seems there might be an issue when applying size-scale transformations (such as resize, shiftscalerotate, etc.) using the albumentations library(perhaps due to a problem in quantization process)</p>\n<p>In the attached images, the left line shows a mask resized through the  \"albumentations.Resize\", while the right line exhibits a mask resized using \"cv2.resize\" without quantization. (Those pictures are the result of reducing the original size by a factor of x4.) <br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F8251891%2Fc7e4ca43c5f5418583983bbb1ec0a08c%2F(1).png?generation=1703326345488635&amp;alt=media\" alt=\"\"></p>\n<p>The left mask was obtained using the code:</p>\n<pre><code>A.Resize(h, w)(=img, =mask)\n</code></pre>\n<p>While the right mask was obtained using the code: </p>\n<pre><code>cv2(, (w, h))\ncv2(, (w, h))\n</code></pre>\n<p>Could it be that I've used the code incorrectly?</p>",
      "rawMarkdown": "It seems there might be an issue when applying size-scale transformations (such as resize, shiftscalerotate, etc.) using the albumentations library(perhaps due to a problem in quantization process)\n\nIn the attached images, the left line shows a mask resized through the  \"albumentations.Resize\", while the right line exhibits a mask resized using \"cv2.resize\" without quantization. (Those pictures are the result of reducing the original size by a factor of x4.) \n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F8251891%2Fc7e4ca43c5f5418583983bbb1ec0a08c%2F(1).png?generation=1703326345488635&alt=media)\n\nThe left mask was obtained using the code:\n\n    A.Resize(h, w)(image=img, mask=mask)\n\nWhile the right mask was obtained using the code: \n    \n    cv2.resize(img, (w, h))\n    cv2.resize(mask, (w, h))\n\nCould it be that I've used the code incorrectly?",
      "votes": 9
    },
    {
      "id": 2571999,
      "postDate": "2023-12-23T19:22:01.220Z",
      "content": "<p>Resizing is the key in winning the private dataset.</p>",
      "rawMarkdown": "Resizing is the key in winning the private dataset.",
      "votes": 3,
      "replies": [
        {
          "id": 2572202,
          "postDate": "2023-12-24T02:10:11.510Z",
          "content": "<p>I really think so too! <br>\nIn this competition, precisely segmenting small details is crucial.</p>",
          "rawMarkdown": "I really think so too! \nIn this competition, precisely segmenting small details is crucial.",
          "replies": [
            {
              "id": 2572292,
              "postDate": "2023-12-24T05:18:57.670Z",
              "content": "<p>No. Private test data is of different resolution. How to use resize correctly to ensure your model is robust against resolution is the key</p>",
              "rawMarkdown": "No. Private test data is of different resolution. How to use resize correctly to ensure your model is robust against resolution is the key",
              "votes": 5
            },
            {
              "id": 2572697,
              "postDate": "2023-12-24T13:18:32.680Z",
              "content": "<p>Ah, I see. So you meant “resize” in that sense. Indeed, creating a model that's robust to resolution could significantly impact achieving good results in private. Thank you for the valuable insight.</p>",
              "rawMarkdown": "Ah, I see. So you meant “resize” in that sense. Indeed, creating a model that's robust to resolution could significantly impact achieving good results in private. Thank you for the valuable insight."
            }
          ]
        }
      ]
    },
    {
      "id": 2571681,
      "postDate": "2023-12-23T12:58:16.137Z",
      "content": "<p>I think the interpolation methods are different. For Albumentations' resize applied to masks, cv2.INTER_NEAREST is used.</p>",
      "rawMarkdown": "I think the interpolation methods are different. For Albumentations' resize applied to masks, cv2.INTER_NEAREST is used.",
      "votes": 3,
      "replies": [
        {
          "id": 2571699,
          "postDate": "2023-12-23T13:24:12.807Z",
          "content": "<p>Thank you! <br>\nSetting it as cv2.resize(mask, (w, h), interpolation=cv2.INTER_NEAREST) produced the same result!</p>",
          "rawMarkdown": "Thank you! \nSetting it as cv2.resize(mask, (w, h), interpolation=cv2.INTER_NEAREST) produced the same result!",
          "replies": [
            {
              "id": 2571728,
              "postDate": "2023-12-23T14:02:25.987Z",
              "content": "<p>Did you correctly set the arguments?<br>\nIs it possible that you forgot \"interpolation=\"?<br>\n<code>cv2.resize(mask, (w, h), interpolation = cv2.INTER_NEAREST)</code> is correct.</p>",
              "rawMarkdown": "Did you correctly set the arguments?\nIs it possible that you forgot \"interpolation=\"?\n`cv2.resize(mask, (w, h), interpolation = cv2.INTER_NEAREST)` is correct."
            },
            {
              "id": 2571732,
              "postDate": "2023-12-23T14:07:15.080Z",
              "content": "<p>I meant to say that your statement was correct - A.Resize and cv2.resize produce the same result.<br>\nThanks!😃</p>",
              "rawMarkdown": "I meant to say that your statement was correct - A.Resize and cv2.resize produce the same result.\nThanks!😃",
              "votes": 1
            },
            {
              "id": 2571742,
              "postDate": "2023-12-23T14:23:17.603Z",
              "content": "<p>I misunderstood. Glad to hear it's resolved!</p>",
              "rawMarkdown": "I misunderstood. Glad to hear it's resolved!"
            }
          ]
        }
      ]
    },
    {
      "id": 2571585,
      "postDate": "2023-12-23T10:56:19.790Z",
      "content": "<p>cv2.resize expects (w, h) :<br>\n <code>cv2.resize(img, (w, h) )</code></p>",
      "rawMarkdown": "cv2.resize expects (w, h) :\n `cv2.resize(img, (w, h) )`",
      "votes": 1,
      "replies": [
        {
          "id": 2571610,
          "postDate": "2023-12-23T11:23:48.847Z",
          "content": "<p>Ah, right! Thank you. 😀<br>\nHowever, in this case where h=w=16, it still seems there is an issue.</p>",
          "rawMarkdown": "Ah, right! Thank you. 😀\nHowever, in this case where h=w=16, it still seems there is an issue.",
          "replies": [
            {
              "id": 2571701,
              "postDate": "2023-12-23T13:26:03.280Z",
              "content": "<p>Hmm, then that's weird because Albumentations uses cv2 under the hood, and both employ bilinear interpolation by default.</p>",
              "rawMarkdown": "Hmm, then that's weird because Albumentations uses cv2 under the hood, and both employ bilinear interpolation by default."
            }
          ]
        }
      ]
    },
    {
      "id": 2573355,
      "postDate": "2023-12-24T23:04:01.007Z",
      "rawMarkdown": "",
      "isDeleted": true,
      "replies": [
        {
          "id": 2573421,
          "postDate": "2023-12-25T03:27:35.810Z",
          "content": "<p>When I tried augmenting with the mask resolution(Resize, ShiftScaleRotate, …), I found through several experiments that it actually worsened the performance.</p>\n<p>I think it’s because of using cv2.INTER_NEAREST for mask interpolation in the Albumentations library.</p>\n<p>Indeed, using interpolation=cv2.INTER_LINEAR for mask yielded better results.</p>",
          "rawMarkdown": "When I tried augmenting with the mask resolution(Resize, ShiftScaleRotate, …), I found through several experiments that it actually worsened the performance.\n\nI think it’s because of using cv2.INTER_NEAREST for mask interpolation in the Albumentations library.\n\nIndeed, using interpolation=cv2.INTER_LINEAR for mask yielded better results.",
          "votes": 3,
          "replies": [
            {
              "id": 2573424,
              "postDate": "2023-12-25T03:36:00.023Z",
              "content": "<p>Noted! I will share if I find anything helpful in further research </p>",
              "rawMarkdown": "Noted! I will share if I find anything helpful in further research ",
              "votes": 2
            }
          ]
        },
        {
          "id": 2573649,
          "postDate": "2023-12-25T08:49:03.420Z",
          "content": "<p>What resolution do you use to train the model?</p>",
          "rawMarkdown": "What resolution do you use to train the model?"
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 2571999,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "2023-12-23T19:22:01.220000",
      "content": "<p>Resizing is the key in winning the private dataset.</p>",
      "votes": 3,
      "replies": [
        {
          "id": 2572202,
          "author_name": "siwooyong",
          "author_url": "",
          "post_date": "2023-12-24T02:10:11.510000",
          "content": "<p>I really think so too! <br>\nIn this competition, precisely segmenting small details is crucial.</p>",
          "votes": 0,
          "replies": [
            {
              "id": 2572292,
              "author_name": "hengck23",
              "author_url": "",
              "post_date": "2023-12-24T05:18:57.670000",
              "content": "<p>No. Private test data is of different resolution. How to use resize correctly to ensure your model is robust against resolution is the key</p>",
              "votes": 5,
              "replies": []
            },
            {
              "id": 2572697,
              "author_name": "siwooyong",
              "author_url": "",
              "post_date": "2023-12-24T13:18:32.680000",
              "content": "<p>Ah, I see. So you meant “resize” in that sense. Indeed, creating a model that's robust to resolution could significantly impact achieving good results in private. Thank you for the valuable insight.</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2571681,
      "author_name": "Takayuki Higuchi",
      "author_url": "",
      "post_date": "2023-12-23T12:58:16.137000",
      "content": "<p>I think the interpolation methods are different. For Albumentations' resize applied to masks, cv2.INTER_NEAREST is used.</p>",
      "votes": 3,
      "replies": [
        {
          "id": 2571699,
          "author_name": "siwooyong",
          "author_url": "",
          "post_date": "2023-12-23T13:24:12.807000",
          "content": "<p>Thank you! <br>\nSetting it as cv2.resize(mask, (w, h), interpolation=cv2.INTER_NEAREST) produced the same result!</p>",
          "votes": 0,
          "replies": [
            {
              "id": 2571728,
              "author_name": "Takayuki Higuchi",
              "author_url": "",
              "post_date": "2023-12-23T14:02:25.987000",
              "content": "<p>Did you correctly set the arguments?<br>\nIs it possible that you forgot \"interpolation=\"?<br>\n<code>cv2.resize(mask, (w, h), interpolation = cv2.INTER_NEAREST)</code> is correct.</p>",
              "votes": 0,
              "replies": []
            },
            {
              "id": 2571732,
              "author_name": "siwooyong",
              "author_url": "",
              "post_date": "2023-12-23T14:07:15.080000",
              "content": "<p>I meant to say that your statement was correct - A.Resize and cv2.resize produce the same result.<br>\nThanks!😃</p>",
              "votes": 1,
              "replies": []
            },
            {
              "id": 2571742,
              "author_name": "Takayuki Higuchi",
              "author_url": "",
              "post_date": "2023-12-23T14:23:17.603000",
              "content": "<p>I misunderstood. Glad to hear it's resolved!</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2571585,
      "author_name": "Reacher",
      "author_url": "",
      "post_date": "2023-12-23T10:56:19.790000",
      "content": "<p>cv2.resize expects (w, h) :<br>\n <code>cv2.resize(img, (w, h) )</code></p>",
      "votes": 1,
      "replies": [
        {
          "id": 2571610,
          "author_name": "siwooyong",
          "author_url": "",
          "post_date": "2023-12-23T11:23:48.847000",
          "content": "<p>Ah, right! Thank you. 😀<br>\nHowever, in this case where h=w=16, it still seems there is an issue.</p>",
          "votes": 0,
          "replies": [
            {
              "id": 2571701,
              "author_name": "Reacher",
              "author_url": "",
              "post_date": "2023-12-23T13:26:03.280000",
              "content": "<p>Hmm, then that's weird because Albumentations uses cv2 under the hood, and both employ bilinear interpolation by default.</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2573355,
      "author_name": "",
      "author_url": "",
      "post_date": "2023-12-24T23:04:01.007000",
      "content": "",
      "votes": 0,
      "replies": [
        {
          "id": 2573421,
          "author_name": "siwooyong",
          "author_url": "",
          "post_date": "2023-12-25T03:27:35.810000",
          "content": "<p>When I tried augmenting with the mask resolution(Resize, ShiftScaleRotate, …), I found through several experiments that it actually worsened the performance.</p>\n<p>I think it’s because of using cv2.INTER_NEAREST for mask interpolation in the Albumentations library.</p>\n<p>Indeed, using interpolation=cv2.INTER_LINEAR for mask yielded better results.</p>",
          "votes": 3,
          "replies": [
            {
              "id": 2573424,
              "author_name": "Cody_Null",
              "author_url": "",
              "post_date": "2023-12-25T03:36:00.023000",
              "content": "<p>Noted! I will share if I find anything helpful in further research </p>",
              "votes": 2,
              "replies": []
            }
          ]
        },
        {
          "id": 2573649,
          "author_name": "Arunodhayan",
          "author_url": "",
          "post_date": "2023-12-25T08:49:03.420000",
          "content": "<p>What resolution do you use to train the model?</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2571547": "It seems there might be an issue when applying size-scale transformations (such as resize, shiftscalerotate, etc.) using the albumentations library(perhaps due to a problem in quantization process)\n\nIn the attached images, the left line shows a mask resized through the  \"albumentations.Resize\", while the right line exhibits a mask resized using \"cv2.resize\" without quantization. (Those pictures are the result of reducing the original size by a factor of x4.) \n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F8251891%2Fc7e4ca43c5f5418583983bbb1ec0a08c%2F(1).png?generation=1703326345488635&alt=media)\n\nThe left mask was obtained using the code:\n\n    A.Resize(h, w)(image=img, mask=mask)\n\nWhile the right mask was obtained using the code: \n    \n    cv2.resize(img, (w, h))\n    cv2.resize(mask, (w, h))\n\nCould it be that I've used the code incorrectly?",
    "2571999": "Resizing is the key in winning the private dataset.",
    "2571681": "I think the interpolation methods are different. For Albumentations' resize applied to masks, cv2.INTER_NEAREST is used.",
    "2571585": "cv2.resize expects (w, h) :\n `cv2.resize(img, (w, h) )`",
    "2573355": ""
  }
}