{
  "id": 352597,
  "title": "How do you resize test images?",
  "url": "/competitions/hubmap-organ-segmentation/discussion/352597",
  "author_name": "",
  "post_date": "2022-09-15T05:43:43.988691Z",
  "votes": 7,
  "comment_count": 14,
  "views": 0,
  "content": "<p>In my view, we should resize the test image adaptively by it's pixel size, however, I found this way performs worse than just resize to fixed size. How do you resize the test images?</p>",
  "messages": [
    {
      "id": "1939896",
      "postDate": "09/15/2022 05:43:43",
      "content": "<p>In my view, we should resize the test image adaptively by it's pixel size, however, I found this way performs worse than just resize to fixed size. How do you resize the test images?</p>",
      "rawMarkdown": "In my view, we should resize the test image adaptively by it's pixel size, however, I found this way performs worse than just resize to fixed size. How do you resize the test images?",
      "votes": null
    },
    {
      "id": "1939985",
      "postDate": "09/15/2022 06:27:23",
      "content": "<p>Interesting, I do it by pixel size…</p>",
      "rawMarkdown": "Interesting, I do it by pixel size...",
      "votes": null
    },
    {
      "id": "1939997",
      "postDate": "09/15/2022 06:32:30",
      "content": "<p>Resize to fixed size but I use pixel size augmentations during training.</p>",
      "rawMarkdown": "Resize to fixed size but I use pixel size augmentations during training.",
      "votes": null
    },
    {
      "id": "1940019",
      "postDate": "09/15/2022 06:43:37",
      "content": "<p>Even for prostate, where the HuBMAP pixel size is 15x larger than HPA?</p>",
      "rawMarkdown": "Even for prostate, where the HuBMAP pixel size is 15x larger than HPA?",
      "votes": null
    },
    {
      "id": "1940137",
      "postDate": "09/15/2022 07:41:38",
      "content": "<p>Yes, quite interesting.</p>",
      "rawMarkdown": "Yes, quite interesting.",
      "votes": null
    },
    {
      "id": "1940354",
      "postDate": "09/15/2022 10:02:13",
      "content": "<p>be aware that some encoder or decoder requires size to be multiple of k, eg 32.<br>\nthis is important in reversing results for tta</p>",
      "rawMarkdown": "be aware that some encoder or decoder requires size to be multiple of k, eg 32.\nthis is important in reversing results for tta",
      "votes": null
    },
    {
      "id": "1940382",
      "postDate": "09/15/2022 10:20:17",
      "content": "<p>I've also noticed this, thanks for your reminder. Maybe I can try to adjust organ threshold.</p>",
      "rawMarkdown": "I've also noticed this, thanks for your reminder. Maybe I can try to adjust organ threshold.",
      "votes": null
    },
    {
      "id": "1940467",
      "postDate": "09/15/2022 11:24:59",
      "content": "<p>\"I found this way performs worse than just resize to fixed size.\"<br>\ni have mixed results. some are better, some are worse</p>\n<p>\"In my view, we should resize the test image adaptively by it's pixel size, \"<br>\nthis is assume that the pixel size is correctly recorded (i.e. no error of pixel size in csv file) and the cell has same physical size (which can be violated)</p>\n<p>if we have too little train samples, we may be have represented the size variation incorrectly and gives rise to contradictions to our \"prior knowledge\" .</p>\n<p>for me i would just do both experiments and take the better results between adaptive or fixed size</p>",
      "rawMarkdown": "\"I found this way performs worse than just resize to fixed size.\"\ni have mixed results. some are better, some are worse\n\n\"In my view, we should resize the test image adaptively by it's pixel size, \"\nthis is assume that the pixel size is correctly recorded (i.e. no error of pixel size in csv file) and the cell has same physical size (which can be violated)\n\nif we have too little train samples, we may be have represented the size variation incorrectly and gives rise to contradictions to our \"prior knowledge\" .\n\nfor me i would just do both experiments and take the better results between adaptive or fixed size",
      "votes": null
    },
    {
      "id": "1940589",
      "postDate": "09/15/2022 12:57:11",
      "content": "<p>May I ask what is pixel size augmentation?</p>",
      "rawMarkdown": "May I ask what is pixel size augmentation?",
      "votes": null
    },
    {
      "id": "1940744",
      "postDate": "09/15/2022 14:24:02",
      "content": "<p>It seems that you have done more detailed experiments than me, thanks a lot for your sharing!</p>",
      "rawMarkdown": "It seems that you have done more detailed experiments than me, thanks a lot for your sharing!",
      "votes": null
    },
    {
      "id": "1943327",
      "postDate": "09/17/2022 13:07:56",
      "content": "<p>I resize all test images to 1024×1024. <br>\nI tried to do pixel size, but didn't get improvement in LB, only drop a little. <br>\nI don't know if I did it right. I did it as the <a href=\"https://www.kaggle.com/competitions/hubmap-organ-segmentation/discussion/333552\" target=\"_blank\">discussion</a> showed:<br>\nsay I trained with resized 3000 -&gt; 1024 whole images,</p>\n<pre><code>TRAINING_SCALE = 1024 / 3000.\nfor index, row in test_df.iterrows():\n    PIXEL_SIZE = row['pixel_size']\n    image_file = PIL.Image.open(image_path)\n\n    ADAPT_SCALE = PIXEL_SIZE / 0.4 * TRAINING_SCALE\n\n    image_arr = cv2.resize(np.array(image_file), dsize=None,\n                           fx=ADAPT_SCALE, fy=ADAPT_SCALE,\n                           interpolation=cv2.INTER_LINEAR)\n</code></pre>\n<p>then tile image_arr with 1024×1024 and predict, then patched masks back ,resized back …</p>",
      "rawMarkdown": "I resize all test images to 1024×1024. \nI tried to do pixel size, but didn't get improvement in LB, only drop a little. \nI don't know if I did it right. I did it as the [discussion](https://www.kaggle.com/competitions/hubmap-organ-segmentation/discussion/333552) showed:\nsay I trained with resized 3000 -> 1024 whole images,\n\n\n    TRAINING_SCALE = 1024 / 3000.\n    for index, row in test_df.iterrows():\n        PIXEL_SIZE = row['pixel_size']\n        image_file = PIL.Image.open(image_path)\n    \n        ADAPT_SCALE = PIXEL_SIZE / 0.4 * TRAINING_SCALE\n    \n        image_arr = cv2.resize(np.array(image_file), dsize=None,\n                               fx=ADAPT_SCALE, fy=ADAPT_SCALE,\n                               interpolation=cv2.INTER_LINEAR)\n\n\n then tile image_arr with 1024×1024 and predict, then patched masks back ,resized back ...",
      "votes": null
    },
    {
      "id": "1943341",
      "postDate": "09/17/2022 13:15:03",
      "content": "<p>I reworked my pipeline to do fixed sizing and I got a drop of ~0.02 versus pixel size scaling. If I ensemble them 1:1 it closes the gap but pixel size scaling is still better.</p>",
      "rawMarkdown": "I reworked my pipeline to do fixed sizing and I got a drop of ~0.02 versus pixel size scaling. If I ensemble them 1:1 it closes the gap but pixel size scaling is still better.",
      "votes": null
    },
    {
      "id": "1943406",
      "postDate": "09/17/2022 13:56:29",
      "content": "<p>Thanks, that's an interesting result, maybe different model setting or different training pipeline suits for different resize operation. I'll do more experiments and try to figure out why this happens.</p>",
      "rawMarkdown": "Thanks, that's an interesting result, maybe different model setting or different training pipeline suits for different resize operation. I'll do more experiments and try to figure out why this happens.",
      "votes": null
    },
    {
      "id": "1943438",
      "postDate": "09/17/2022 14:09:21",
      "content": "<p>Isn't pixel size scaling basically a resizing process? I've thought that cv2.resize(fx, fy) simply means the ratio of either upsampling or downsampling. I've run the following code for prostate image from trainset:</p>\n<pre><code>&gt;&gt;&gt; code\nimport cv2\ndf = pd.read_csv('../input/hubmap-organ-segmentation/train.csv')\nfor i, d in df.iterrows():\n    id = d['id']\n    image = cv2.imread('../input/hubmap-organ-segmentation/train_images/%d.tiff'%id, cv2.IMREAD_COLOR)\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    print(image.shape)\n    image_resized = cv2.resize(image, dsize=None, fx=0.4/6.263, fy=0.4/6.263, interpolation=cv2.INTER_CUBIC)\n    print(image_resized.shape)\n    image_resized = cv2.resize(image_resized, dsize=(3000,3000))    \n    print(image_resized.shape)\n    pixel_total = image.shape[0]*image.shape[1] * 3\n    print(pixel_total)\n    print((pixel_total - (image != image_resized).sum())/pixel_total * 100)\n    break\n\n&gt;&gt;&gt; output\nOriginal image size: (3000, 3000, 3)\nResized image size: (192, 192, 3)\nUpscaled image size: (3000, 3000, 3) \nTotal # of pixels in image: 27000000\n% of difference b/w original and resize upscaled image: 24.112% \n</code></pre>\n<p>It says the resized image is 24% different from the original. I used to think it's information loss from downscale and upscale but am I misunderstanding the pixel size scaling? Does 24% difference mean something else, other than data loss?</p>",
      "rawMarkdown": "Isn't pixel size scaling basically a resizing process? I've thought that cv2.resize(fx, fy) simply means the ratio of either upsampling or downsampling. I've run the following code for prostate image from trainset:\n```\n>>> code\nimport cv2\ndf = pd.read_csv('../input/hubmap-organ-segmentation/train.csv')\nfor i, d in df.iterrows():\n    id = d['id']\n    image = cv2.imread('../input/hubmap-organ-segmentation/train_images/%d.tiff'%id, cv2.IMREAD_COLOR)\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    print(image.shape)\n    image_resized = cv2.resize(image, dsize=None, fx=0.4/6.263, fy=0.4/6.263, interpolation=cv2.INTER_CUBIC)\n    print(image_resized.shape)\n    image_resized = cv2.resize(image_resized, dsize=(3000,3000))    \n    print(image_resized.shape)\n    pixel_total = image.shape[0]*image.shape[1] * 3\n    print(pixel_total)\n    print((pixel_total - (image != image_resized).sum())/pixel_total * 100)\n    break\n\n>>> output\nOriginal image size: (3000, 3000, 3)\nResized image size: (192, 192, 3)\nUpscaled image size: (3000, 3000, 3) \nTotal # of pixels in image: 27000000\n% of difference b/w original and resize upscaled image: 24.112% \n```\nIt says the resized image is 24% different from the original. I used to think it's information loss from downscale and upscale but am I misunderstanding the pixel size scaling? Does 24% difference mean something else, other than data loss?",
      "votes": null
    },
    {
      "id": "1946646",
      "postDate": "09/20/2022 01:51:23",
      "content": "<p>I found that pixel size scaling performs better than fixed size scaling after ensembing more models, maybe this happens randomly when inference setup changes.</p>",
      "rawMarkdown": "I found that pixel size scaling performs better than fixed size scaling after ensembing more models, maybe this happens randomly when inference setup changes.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1939985,
      "author_name": "jamesphoward",
      "author_url": "",
      "post_date": "09/15/2022 06:27:23",
      "content": "<p>Interesting, I do it by pixel size…</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1939997,
      "author_name": "gunesevitan",
      "author_url": "",
      "post_date": "09/15/2022 06:32:30",
      "content": "<p>Resize to fixed size but I use pixel size augmentations during training.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1940589,
          "author_name": "electro",
          "author_url": "",
          "post_date": "09/15/2022 12:57:11",
          "content": "<p>May I ask what is pixel size augmentation?</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1940019,
      "author_name": "jamesphoward",
      "author_url": "",
      "post_date": "09/15/2022 06:43:37",
      "content": "<p>Even for prostate, where the HuBMAP pixel size is 15x larger than HPA?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1940137,
          "author_name": "rock139",
          "author_url": "",
          "post_date": "09/15/2022 07:41:38",
          "content": "<p>Yes, quite interesting.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1940354,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "09/15/2022 10:02:13",
      "content": "<p>be aware that some encoder or decoder requires size to be multiple of k, eg 32.<br>\nthis is important in reversing results for tta</p>",
      "votes": null,
      "replies": [
        {
          "id": 1940382,
          "author_name": "rock139",
          "author_url": "",
          "post_date": "09/15/2022 10:20:17",
          "content": "<p>I've also noticed this, thanks for your reminder. Maybe I can try to adjust organ threshold.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1940467,
          "author_name": "hengck23",
          "author_url": "",
          "post_date": "09/15/2022 11:24:59",
          "content": "<p>\"I found this way performs worse than just resize to fixed size.\"<br>\ni have mixed results. some are better, some are worse</p>\n<p>\"In my view, we should resize the test image adaptively by it's pixel size, \"<br>\nthis is assume that the pixel size is correctly recorded (i.e. no error of pixel size in csv file) and the cell has same physical size (which can be violated)</p>\n<p>if we have too little train samples, we may be have represented the size variation incorrectly and gives rise to contradictions to our \"prior knowledge\" .</p>\n<p>for me i would just do both experiments and take the better results between adaptive or fixed size</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1940744,
          "author_name": "rock139",
          "author_url": "",
          "post_date": "09/15/2022 14:24:02",
          "content": "<p>It seems that you have done more detailed experiments than me, thanks a lot for your sharing!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1943327,
      "author_name": "electro",
      "author_url": "",
      "post_date": "09/17/2022 13:07:56",
      "content": "<p>I resize all test images to 1024×1024. <br>\nI tried to do pixel size, but didn't get improvement in LB, only drop a little. <br>\nI don't know if I did it right. I did it as the <a href=\"https://www.kaggle.com/competitions/hubmap-organ-segmentation/discussion/333552\" target=\"_blank\">discussion</a> showed:<br>\nsay I trained with resized 3000 -&gt; 1024 whole images,</p>\n<pre><code>TRAINING_SCALE = 1024 / 3000.\nfor index, row in test_df.iterrows():\n    PIXEL_SIZE = row['pixel_size']\n    image_file = PIL.Image.open(image_path)\n\n    ADAPT_SCALE = PIXEL_SIZE / 0.4 * TRAINING_SCALE\n\n    image_arr = cv2.resize(np.array(image_file), dsize=None,\n                           fx=ADAPT_SCALE, fy=ADAPT_SCALE,\n                           interpolation=cv2.INTER_LINEAR)\n</code></pre>\n<p>then tile image_arr with 1024×1024 and predict, then patched masks back ,resized back …</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1943341,
      "author_name": "jamesphoward",
      "author_url": "",
      "post_date": "09/17/2022 13:15:03",
      "content": "<p>I reworked my pipeline to do fixed sizing and I got a drop of ~0.02 versus pixel size scaling. If I ensemble them 1:1 it closes the gap but pixel size scaling is still better.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1943406,
          "author_name": "rock139",
          "author_url": "",
          "post_date": "09/17/2022 13:56:29",
          "content": "<p>Thanks, that's an interesting result, maybe different model setting or different training pipeline suits for different resize operation. I'll do more experiments and try to figure out why this happens.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1943438,
          "author_name": "cheulkay",
          "author_url": "",
          "post_date": "09/17/2022 14:09:21",
          "content": "<p>Isn't pixel size scaling basically a resizing process? I've thought that cv2.resize(fx, fy) simply means the ratio of either upsampling or downsampling. I've run the following code for prostate image from trainset:</p>\n<pre><code>&gt;&gt;&gt; code\nimport cv2\ndf = pd.read_csv('../input/hubmap-organ-segmentation/train.csv')\nfor i, d in df.iterrows():\n    id = d['id']\n    image = cv2.imread('../input/hubmap-organ-segmentation/train_images/%d.tiff'%id, cv2.IMREAD_COLOR)\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    print(image.shape)\n    image_resized = cv2.resize(image, dsize=None, fx=0.4/6.263, fy=0.4/6.263, interpolation=cv2.INTER_CUBIC)\n    print(image_resized.shape)\n    image_resized = cv2.resize(image_resized, dsize=(3000,3000))    \n    print(image_resized.shape)\n    pixel_total = image.shape[0]*image.shape[1] * 3\n    print(pixel_total)\n    print((pixel_total - (image != image_resized).sum())/pixel_total * 100)\n    break\n\n&gt;&gt;&gt; output\nOriginal image size: (3000, 3000, 3)\nResized image size: (192, 192, 3)\nUpscaled image size: (3000, 3000, 3) \nTotal # of pixels in image: 27000000\n% of difference b/w original and resize upscaled image: 24.112% \n</code></pre>\n<p>It says the resized image is 24% different from the original. I used to think it's information loss from downscale and upscale but am I misunderstanding the pixel size scaling? Does 24% difference mean something else, other than data loss?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1946646,
          "author_name": "rock139",
          "author_url": "",
          "post_date": "09/20/2022 01:51:23",
          "content": "<p>I found that pixel size scaling performs better than fixed size scaling after ensembing more models, maybe this happens randomly when inference setup changes.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1939896": "In my view, we should resize the test image adaptively by it's pixel size, however, I found this way performs worse than just resize to fixed size. How do you resize the test images?",
    "1939985": "Interesting, I do it by pixel size...",
    "1939997": "Resize to fixed size but I use pixel size augmentations during training.",
    "1940019": "Even for prostate, where the HuBMAP pixel size is 15x larger than HPA?",
    "1940137": "Yes, quite interesting.",
    "1940354": "be aware that some encoder or decoder requires size to be multiple of k, eg 32.\nthis is important in reversing results for tta",
    "1940382": "I've also noticed this, thanks for your reminder. Maybe I can try to adjust organ threshold.",
    "1940467": "\"I found this way performs worse than just resize to fixed size.\"\ni have mixed results. some are better, some are worse\n\n\"In my view, we should resize the test image adaptively by it's pixel size, \"\nthis is assume that the pixel size is correctly recorded (i.e. no error of pixel size in csv file) and the cell has same physical size (which can be violated)\n\nif we have too little train samples, we may be have represented the size variation incorrectly and gives rise to contradictions to our \"prior knowledge\" .\n\nfor me i would just do both experiments and take the better results between adaptive or fixed size",
    "1940589": "May I ask what is pixel size augmentation?",
    "1940744": "It seems that you have done more detailed experiments than me, thanks a lot for your sharing!",
    "1943327": "I resize all test images to 1024×1024. \nI tried to do pixel size, but didn't get improvement in LB, only drop a little. \nI don't know if I did it right. I did it as the [discussion](https://www.kaggle.com/competitions/hubmap-organ-segmentation/discussion/333552) showed:\nsay I trained with resized 3000 -> 1024 whole images,\n\n\n    TRAINING_SCALE = 1024 / 3000.\n    for index, row in test_df.iterrows():\n        PIXEL_SIZE = row['pixel_size']\n        image_file = PIL.Image.open(image_path)\n    \n        ADAPT_SCALE = PIXEL_SIZE / 0.4 * TRAINING_SCALE\n    \n        image_arr = cv2.resize(np.array(image_file), dsize=None,\n                               fx=ADAPT_SCALE, fy=ADAPT_SCALE,\n                               interpolation=cv2.INTER_LINEAR)\n\n\n then tile image_arr with 1024×1024 and predict, then patched masks back ,resized back ...",
    "1943341": "I reworked my pipeline to do fixed sizing and I got a drop of ~0.02 versus pixel size scaling. If I ensemble them 1:1 it closes the gap but pixel size scaling is still better.",
    "1943406": "Thanks, that's an interesting result, maybe different model setting or different training pipeline suits for different resize operation. I'll do more experiments and try to figure out why this happens.",
    "1943438": "Isn't pixel size scaling basically a resizing process? I've thought that cv2.resize(fx, fy) simply means the ratio of either upsampling or downsampling. I've run the following code for prostate image from trainset:\n```\n>>> code\nimport cv2\ndf = pd.read_csv('../input/hubmap-organ-segmentation/train.csv')\nfor i, d in df.iterrows():\n    id = d['id']\n    image = cv2.imread('../input/hubmap-organ-segmentation/train_images/%d.tiff'%id, cv2.IMREAD_COLOR)\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    print(image.shape)\n    image_resized = cv2.resize(image, dsize=None, fx=0.4/6.263, fy=0.4/6.263, interpolation=cv2.INTER_CUBIC)\n    print(image_resized.shape)\n    image_resized = cv2.resize(image_resized, dsize=(3000,3000))    \n    print(image_resized.shape)\n    pixel_total = image.shape[0]*image.shape[1] * 3\n    print(pixel_total)\n    print((pixel_total - (image != image_resized).sum())/pixel_total * 100)\n    break\n\n>>> output\nOriginal image size: (3000, 3000, 3)\nResized image size: (192, 192, 3)\nUpscaled image size: (3000, 3000, 3) \nTotal # of pixels in image: 27000000\n% of difference b/w original and resize upscaled image: 24.112% \n```\nIt says the resized image is 24% different from the original. I used to think it's information loss from downscale and upscale but am I misunderstanding the pixel size scaling? Does 24% difference mean something else, other than data loss?",
    "1946646": "I found that pixel size scaling performs better than fixed size scaling after ensembing more models, maybe this happens randomly when inference setup changes."
  },
  "source": "meta"
}