{
  "id": 76665,
  "title": "cnn with image patches (lb 0.619)",
  "url": "/competitions/human-protein-atlas-image-classification/discussion/76665",
  "author_name": "Appian",
  "post_date": "2019-01-05T11:41:17.450000",
  "votes": 48,
  "comment_count": 40,
  "views": 0,
  "content": "<p>I train cnn with image patches of original tif. I share some information just in case someone is interested. Your input is welcome.</p>\n\n<ul>\n<li>272x272 input (resized from 512x512 image patch)</li>\n<li>batch size 32</li>\n<li>kaggle data and HPAv18 (without uncertain)</li>\n<li>oversample uncommon classes x2 (8,9,10,15,16,17,20,24,26,27)</li>\n<li>bcewithlogitsloss</li>\n<li>fliplr, flipud, scale, rotate, shear, contrast, multiply</li>\n<li>5 folds</li>\n<li>ensemble</li>\n<li>no tta</li>\n</ul>\n\n<p>First each of original tif images are split into to more than 20 patches. After training, outputs of cnn are used as confidence which tells you how much the corresponding patch represents labels of the original image. I use patches with high confidence to train a new model for better accuray. At last I apply weighted average on cnn outputs of image patches to predict labels of the original image.</p>",
  "messages": [
    {
      "id": 450614,
      "postDate": "2019-01-05T11:41:17.450Z",
      "content": "<p>I train cnn with image patches of original tif. I share some information just in case someone is interested. Your input is welcome.</p>\n\n<ul>\n<li>272x272 input (resized from 512x512 image patch)</li>\n<li>batch size 32</li>\n<li>kaggle data and HPAv18 (without uncertain)</li>\n<li>oversample uncommon classes x2 (8,9,10,15,16,17,20,24,26,27)</li>\n<li>bcewithlogitsloss</li>\n<li>fliplr, flipud, scale, rotate, shear, contrast, multiply</li>\n<li>5 folds</li>\n<li>ensemble</li>\n<li>no tta</li>\n</ul>\n\n<p>First each of original tif images are split into to more than 20 patches. After training, outputs of cnn are used as confidence which tells you how much the corresponding patch represents labels of the original image. I use patches with high confidence to train a new model for better accuray. At last I apply weighted average on cnn outputs of image patches to predict labels of the original image.</p>",
      "rawMarkdown": "I train cnn with image patches of original tif. I share some information just in case someone is interested. Your input is welcome.\n\n- 272x272 input (resized from 512x512 image patch)\n- batch size 32\n- kaggle data and HPAv18 (without uncertain)\n- oversample uncommon classes x2 (8,9,10,15,16,17,20,24,26,27)\n- bcewithlogitsloss\n- fliplr, flipud, scale, rotate, shear, contrast, multiply\n- 5 folds\n- ensemble\n- no tta\n\nFirst each of original tif images are split into to more than 20 patches. After training, outputs of cnn are used as confidence which tells you how much the corresponding patch represents labels of the original image. I use patches with high confidence to train a new model for better accuray. At last I apply weighted average on cnn outputs of image patches to predict labels of the original image.",
      "votes": 48
    },
    {
      "id": 451261,
      "postDate": "2019-01-06T18:23:09.863Z",
      "content": "<p>Thanks for sharing! I wanted to ask a few questions: \nThe workflow is:\n1. Create crops from original tif images\n2. Train network on crops</p>\n\n<p>After network is finished training\n1. Calculate confidence of each image crop and keep the images with high probability for second rounding training. \n2. Train network on the image crops with high confidence.</p>\n\n<p>I have two questions:\n1. What do you mean by confidence? Is this the probability calculated by the CNN for the correct classes?\n2. What is used to calculate the weights for each image crop?</p>\n\n<p>Thanks again for sharing!</p>",
      "rawMarkdown": "Thanks for sharing! I wanted to ask a few questions: \nThe workflow is:\n1. Create crops from original tif images\n2. Train network on crops\n\nAfter network is finished training\n1. Calculate confidence of each image crop and keep the images with high probability for second rounding training. \n2. Train network on the image crops with high confidence.\n\nI have two questions:\n1. What do you mean by confidence? Is this the probability calculated by the CNN for the correct classes?\n2. What is used to calculate the weights for each image crop?\n\nThanks again for sharing!\n",
      "votes": 3,
      "replies": [
        {
          "id": 452000,
          "postDate": "2019-01-08T02:45:17.717Z",
          "content": "<p>Thank you for summarzing.</p>\n\n<ol>\n<li><p>Yes, it is outputs from cnn after softmax. Using softmax might be wrong for multilabel problem though. </p></li>\n<li><p>Blue channel intensity is used for weights.</p></li>\n</ol>\n\n<blockquote>\n  <ol>\n  <li>Calculate confidence of each image crop and keep the images with high probability for second rounding training.</li>\n  <li>Train network on the image crops with high confidence.</li>\n  </ol>\n</blockquote>\n\n<p>This part can be repeated for better accuracy by the way.</p>",
          "rawMarkdown": "Thank you for summarzing.\n\n1. Yes, it is outputs from cnn after softmax. Using softmax might be wrong for multilabel problem though. \n\n2. Blue channel intensity is used for weights.\n\n&gt; 1. Calculate confidence of each image crop and keep the images with high probability for second rounding training.\n&gt; 2. Train network on the image crops with high confidence.\n\nThis part can be repeated for better accuracy by the way."
        },
        {
          "id": 452236,
          "postDate": "2019-01-08T11:57:09.537Z",
          "content": "<p>Hi Appian, are you label the patch which means whether can represent the original tiff image manually？</p>",
          "rawMarkdown": "Hi Appian, are you label the patch which means whether can represent the original tiff image manually？"
        },
        {
          "id": 452315,
          "postDate": "2019-01-08T14:58:07.443Z",
          "content": "<blockquote>\n  <p>Blockquote 2. Blue channel intensity is used for weights.</p>\n</blockquote>\n\n<p>by that I think you actually mean green channel intensity right?</p>",
          "rawMarkdown": "&gt; Blockquote 2. Blue channel intensity is used for weights.\n\nby that I think you actually mean green channel intensity right?"
        },
        {
          "id": 452639,
          "postDate": "2019-01-09T01:21:21.817Z",
          "content": "<p><a href=\"/shangweichen\">@shangweichen</a>\nDo you mean by hand? No, there are too many to label by hand. Labels of each patch are given by labels of original image and outputs of cnn.</p>\n\n<p><a href=\"/bastini\">@bastini</a>\nYes, the green channel is right. Thank you for correcting.</p>",
          "rawMarkdown": "@shangweichen\nDo you mean by hand? No, there are too many to label by hand. Labels of each patch are given by labels of original image and outputs of cnn.\n\n@bastini\nYes, the green channel is right. Thank you for correcting."
        },
        {
          "id": 452757,
          "postDate": "2019-01-09T05:55:47.773Z",
          "content": "<p>Hi Appian, I have a question about calculate confidence of each image crop. Do you mean predict the confidence score for training set with the trained model, or predict the confidence score for validation set with 5 fold to obtain the confidence score for whole train data? </p>",
          "rawMarkdown": "Hi Appian, I have a question about calculate confidence of each image crop. Do you mean predict the confidence score for training set with the trained model, or predict the confidence score for validation set with 5 fold to obtain the confidence score for whole train data? ",
          "votes": 1
        },
        {
          "id": 452773,
          "postDate": "2019-01-09T06:21:35.347Z",
          "content": "<p>I use 5 folds to obtain scores for train data in oof manner.</p>",
          "rawMarkdown": "I use 5 folds to obtain scores for train data in oof manner.",
          "votes": 1
        },
        {
          "id": 452818,
          "postDate": "2019-01-09T07:40:11.650Z",
          "content": "<p>Thsnks for your reply! what do you mean in oof manner? By the way, How did you split your 5 folds? random?</p>",
          "rawMarkdown": "Thsnks for your reply! what do you mean in oof manner? By the way, How did you split your 5 folds? random?"
        }
      ]
    },
    {
      "id": 452387,
      "postDate": "2019-01-08T16:53:25.570Z",
      "content": "<p>Thanks for sharing this! The Idea of removeing bad images was crucial for me.\nI have two questions that I don't have enough time left answering myself or need for reference:</p>\n\n<ol>\n<li>What LR did you use? For me 1e-5 works best but seems to be really low. Maybe I should start with a higher one and decrease it after a few Epochs. </li>\n<li>How many Epochs dose a typical training take you? With my LR and letting training finish it takes 50-80 Epochs.</li>\n</ol>\n\n<p>Thanks again!</p>",
      "rawMarkdown": "Thanks for sharing this! The Idea of removeing bad images was crucial for me.\nI have two questions that I don't have enough time left answering myself or need for reference:\n\n1. What LR did you use? For me 1e-5 works best but seems to be really low. Maybe I should start with a higher one and decrease it after a few Epochs. \n2. How many Epochs dose a typical training take you? With my LR and letting training finish it takes 50-80 Epochs.\n\nThanks again!",
      "votes": 1,
      "replies": [
        {
          "id": 452637,
          "postDate": "2019-01-09T01:20:29.503Z",
          "content": "<ol>\n<li><p>I use 8e-4 with 0.9 decay per epoch and batch size 32. I can not say much about your lr is low or not. The proper lr is not easy to find for me too and affected by many things such as batch size.</p></li>\n<li><p>A single model can reach ~0.6 public lb and ~0.66 local cv in several epochs from pretrained imagenet. I now train a few more epochs to see what happens.</p></li>\n</ol>",
          "rawMarkdown": "1. I use 8e-4 with 0.9 decay per epoch and batch size 32. I can not say much about your lr is low or not. The proper lr is not easy to find for me too and affected by many things such as batch size.\n\n2. A single model can reach ~0.6 public lb and ~0.66 local cv in several epochs from pretrained imagenet. I now train a few more epochs to see what happens.",
          "votes": 1
        }
      ]
    },
    {
      "id": 451592,
      "postDate": "2019-01-07T10:21:47.927Z",
      "content": "<p>Very interesting idea, it's like detection but the region of interest is picked by hand. I was wandering that can we build a proposal network to first pickup the region of interest and then feed that region to a classification network.</p>",
      "rawMarkdown": "Very interesting idea, it's like detection but the region of interest is picked by hand. I was wandering that can we build a proposal network to first pickup the region of interest and then feed that region to a classification network.",
      "votes": 1
    },
    {
      "id": 451281,
      "postDate": "2019-01-06T19:03:21.787Z",
      "content": "<p>Congratulations on your success. I started something similar a while back but did not pursue it as I wondered whether the signal would survive cropping. Perhaps only parts of the image lead to the correct label. Looks like that doesn't happen.</p>",
      "rawMarkdown": "Congratulations on your success. I started something similar a while back but did not pursue it as I wondered whether the signal would survive cropping. Perhaps only parts of the image lead to the correct label. Looks like that doesn't happen.",
      "votes": 1
    },
    {
      "id": 451217,
      "postDate": "2019-01-06T16:04:52.887Z",
      "content": "<p>Thanks for sharing your ideas. May I ask how you create the patches? I am a total beginner so any hints would be very much appreciated! \nBest</p>",
      "rawMarkdown": "Thanks for sharing your ideas. May I ask how you create the patches? I am a total beginner so any hints would be very much appreciated! \nBest",
      "votes": 1,
      "replies": [
        {
          "id": 452004,
          "postDate": "2019-01-08T02:49:05.953Z",
          "content": "<p>Generating 25 patches from 2048x2048 image is like</p>\n\n<p><code>\nsize = 512 \noverlap = 128\nx_split = 5\ny_split = 5\nfor i in range(x_split):\n    for j in range(y_split):\n        patch = image[\n            i*size - i*overlap: (i+1)*size - i*overlap,\n            j*size - j*overlap: (j+1)*size - j*overlap\n        ]\n        dst = os.path.join(dstdir, f'{name}_x{i}_y{j}.png')\n        cv2.imwrite(dst, patch)\n</code></p>",
          "rawMarkdown": "Generating 25 patches from 2048x2048 image is like\n\n```\nsize = 512 \noverlap = 128\nx_split = 5\ny_split = 5\nfor i in range(x_split):\n    for j in range(y_split):\n        patch = image[\n            i*size - i*overlap: (i+1)*size - i*overlap,\n            j*size - j*overlap: (j+1)*size - j*overlap\n\t\t]\n        dst = os.path.join(dstdir, f'{name}_x{i}_y{j}.png')\n        cv2.imwrite(dst, patch)\n```",
          "votes": 5
        },
        {
          "id": 452238,
          "postDate": "2019-01-08T12:03:37.827Z",
          "content": "<p>Thankyou!</p>",
          "rawMarkdown": "Thankyou!"
        },
        {
          "id": 453006,
          "postDate": "2019-01-09T13:47:32.187Z",
          "content": "<p>Probably a silly question but may I check if I understand it correctly:</p>\n\n<p>1) train with crops of high confidence images: this helps speed up 2nd stage classification as it focuses on most informative regions and doesn't have to learn to discard the relatively uninformative regions (these were discarded / given low weights before 2nd stage)</p>\n\n<p>2) These crops were created as a weighted combination of the green channel intensity (similar effect I  guess can be created by doing a dimensionality reduction, say using autoencoders / PCA)</p>\n\n<p>3) how did you come to pick the size of the particular crop? Would it not be the case that for different pictures with different cell sizes (although i understand the magnification of these images are assumed constant) require crops of different sizes to ensure all details are captured?</p>\n\n<p>Thanks a lot for any help!!</p>\n\n<p>Best</p>",
          "rawMarkdown": "Probably a silly question but may I check if I understand it correctly:\n\n1) train with crops of high confidence images: this helps speed up 2nd stage classification as it focuses on most informative regions and doesn't have to learn to discard the relatively uninformative regions (these were discarded / given low weights before 2nd stage)\n\n2) These crops were created as a weighted combination of the green channel intensity (similar effect I  guess can be created by doing a dimensionality reduction, say using autoencoders / PCA)\n\n3) how did you come to pick the size of the particular crop? Would it not be the case that for different pictures with different cell sizes (although i understand the magnification of these images are assumed constant) require crops of different sizes to ensure all details are captured?\n\nThanks a lot for any help!!\n\nBest"
        }
      ]
    },
    {
      "id": 450977,
      "postDate": "2019-01-06T07:29:19.053Z",
      "content": "<p>Thanks for the share. I just joined this competition, can I ask which model you are using?</p>",
      "rawMarkdown": "Thanks for the share. I just joined this competition, can I ask which model you are using?",
      "votes": 1,
      "replies": [
        {
          "id": 451047,
          "postDate": "2019-01-06T10:55:56.823Z",
          "content": "<p>se_resnext50 from <a href=\"https://github.com/creafz/pytorch-cnn-finetune\">https://github.com/creafz/pytorch-cnn-finetune</a> with a bit of tuning.</p>",
          "rawMarkdown": "se_resnext50 from https://github.com/creafz/pytorch-cnn-finetune with a bit of tuning.",
          "votes": 4
        }
      ]
    },
    {
      "id": 450912,
      "postDate": "2019-01-06T04:30:36.983Z",
      "content": "<p>Thanks for your share ,which is your lb with single model?</p>",
      "rawMarkdown": "Thanks for your share ,which is your lb with single model?",
      "votes": 1
    },
    {
      "id": 450906,
      "postDate": "2019-01-06T03:52:42.327Z",
      "content": "<p>I tried exactly the same approach on the original data (384x384 crops selected quisirandomly based on the intensity of the green channel to produce ~250k images), but it failed miserably. Probably, <strong>the key is using the external data</strong>.</p>",
      "rawMarkdown": "I tried exactly the same approach on the original data (384x384 crops selected quisirandomly based on the intensity of the green channel to produce ~250k images), but it failed miserably. Probably, **the key is using the external data**.",
      "votes": 1,
      "replies": [
        {
          "id": 451046,
          "postDate": "2019-01-06T10:55:04.153Z",
          "content": "<p>Not all of patches are useful for training. You probably get a better result by classifying which patch is useful for training and which patch confuses the model on top of green channel intensity. And yes HPAv18 helps.</p>",
          "rawMarkdown": "Not all of patches are useful for training. You probably get a better result by classifying which patch is useful for training and which patch confuses the model on top of green channel intensity. And yes HPAv18 helps.",
          "votes": 2
        },
        {
          "id": 451230,
          "postDate": "2019-01-06T16:41:08.453Z",
          "content": "<p>used the same approach without external data, large 896 x 896 patches because of label noise to get as much of the label in patches but lb score is not great. I did not use green channel to guide patch selection too lazy unfortunately.</p>",
          "rawMarkdown": "used the same approach without external data, large 896 x 896 patches because of label noise to get as much of the label in patches but lb score is not great. I did not use green channel to guide patch selection too lazy unfortunately.",
          "votes": 1
        },
        {
          "id": 452317,
          "postDate": "2019-01-08T15:02:26.597Z",
          "content": "<p>Same here, kind of the same approach but using blue channel to detect cell positions first and then made a crop around them. I also failed miserably, even when using external data. I think using AlexNet was not the best choice even though it got the best results so far (0.376 publicLB).</p>",
          "rawMarkdown": "Same here, kind of the same approach but using blue channel to detect cell positions first and then made a crop around them. I also failed miserably, even when using external data. I think using AlexNet was not the best choice even though it got the best results so far (0.376 publicLB)."
        }
      ]
    },
    {
      "id": 450879,
      "postDate": "2019-01-06T01:55:19.553Z",
      "content": "<p>Thanks for the informative article, but I'm a bit of confused. Original TIF have diverse of sizes(2048, 3k, ...) and also HPAv18 have 512x512 images. Do you resize them to the same sizes before training?</p>",
      "rawMarkdown": "Thanks for the informative article, but I'm a bit of confused. Original TIF have diverse of sizes(2048, 3k, ...) and also HPAv18 have 512x512 images. Do you resize them to the same sizes before training?\n\n",
      "votes": 1,
      "replies": [
        {
          "id": 451045,
          "postDate": "2019-01-06T10:53:20.557Z",
          "content": "<p>HPAv18 actually has 2048x2048 and something like 1768x1768 and I resized them to 1768x1768. Original tif images are resized to 2048x2048. The size of patch is always 512x512 but with different overlap values.</p>",
          "rawMarkdown": "HPAv18 actually has 2048x2048 and something like 1768x1768 and I resized them to 1768x1768. Original tif images are resized to 2048x2048. The size of patch is always 512x512 but with different overlap values.",
          "votes": 1
        }
      ]
    },
    {
      "id": 450709,
      "postDate": "2019-01-05T14:58:23.350Z",
      "content": "<p>Thanks Appian.<br>\nI have one question.<br>\nwhat is publicLB for a single model?</p>",
      "rawMarkdown": "Thanks Appian.<br>\nI have one question.<br>\nwhat is publicLB for a single model?",
      "votes": 1,
      "replies": [
        {
          "id": 450748,
          "postDate": "2019-01-05T16:50:49.317Z",
          "content": "<p>A single fold: ~0.6\n5-folds average: ~0.61</p>",
          "rawMarkdown": "A single fold: ~0.6\n5-folds average: ~0.61",
          "votes": 2
        },
        {
          "id": 450751,
          "postDate": "2019-01-05T17:03:33.337Z",
          "content": "<p>you are amazing, thanks!</p>",
          "rawMarkdown": "you are amazing, thanks!"
        }
      ]
    },
    {
      "id": 451829,
      "postDate": "2019-01-07T18:30:51.493Z",
      "content": "<p>cool</p>",
      "rawMarkdown": "cool",
      "votes": 2
    },
    {
      "id": 450652,
      "postDate": "2019-01-05T13:24:29.590Z",
      "content": "<p>Good work !\nI did something similar but only reach ~0.56, may I ask some question ?\nDid you use green channel to indicate the area to crop ? \nif not,  why using fixed patch instead of random crop on the fly  ?</p>",
      "rawMarkdown": "Good work !\nI did something similar but only reach ~0.56, may I ask some question ?\nDid you use green channel to indicate the area to crop ? \nif not,  why using fixed patch instead of random crop on the fly  ?",
      "votes": 2,
      "replies": [
        {
          "id": 450671,
          "postDate": "2019-01-05T14:05:09.713Z",
          "content": "<p>Thanks. Good to hear someone tried a similar approach.</p>\n\n<p>I use green channel to tell which patch is more informative than others. Patches with relatively small green channel value are discarded before training for example.</p>\n\n<p>Random crop should work as well but you need to keep track of how you cropped that image anyway. Because you later use trained cnn to give confidence score on each of cropped images to determine you use that image for training or not. In my case fixed patch was just more convinient.</p>",
          "rawMarkdown": "Thanks. Good to hear someone tried a similar approach.\n\nI use green channel to tell which patch is more informative than others. Patches with relatively small green channel value are discarded before training for example.\n\nRandom crop should work as well but you need to keep track of how you cropped that image anyway. Because you later use trained cnn to give confidence score on each of cropped images to determine you use that image for training or not. In my case fixed patch was just more convinient.",
          "votes": 4
        },
        {
          "id": 450683,
          "postDate": "2019-01-05T14:24:00.817Z",
          "content": "<p>Thanks for your reply, very informative ! </p>",
          "rawMarkdown": "Thanks for your reply, very informative ! ",
          "votes": 1
        }
      ]
    },
    {
      "id": 451596,
      "postDate": "2019-01-07T10:27:46.267Z",
      "content": "<p>My First Comment</p>",
      "rawMarkdown": "My First Comment",
      "votes": -3,
      "replies": [
        {
          "id": 452005,
          "postDate": "2019-01-08T02:51:13.200Z",
          "content": "<p>Have fun kaggling!</p>",
          "rawMarkdown": "Have fun kaggling!"
        }
      ]
    },
    {
      "id": 456876,
      "postDate": "2019-01-16T17:27:50.610Z",
      "content": "<p>hi appian\nthanks for posting in solution... could you share the script to use the external data,preprocessng,download </p>",
      "rawMarkdown": "hi appian\nthanks for posting in solution... could you share the script to use the external data,preprocessng,download "
    },
    {
      "id": 455081,
      "postDate": "2019-01-12T23:28:24.223Z",
      "content": "<p>Did you get a chance to try this approach with diverse models? Either way, cool approach. I like how you saw beyond the label not captured in smaller crop assumption. An elegant countermeasure.</p>",
      "rawMarkdown": "Did you get a chance to try this approach with diverse models? Either way, cool approach. I like how you saw beyond the label not captured in smaller crop assumption. An elegant countermeasure."
    },
    {
      "id": 454823,
      "postDate": "2019-01-12T09:35:40.037Z",
      "content": "<p>Thanks for sharing.\nand can you share your details code in data augmentation.\nmy code is just applied affine,fliplr,flipud.and my best private score is  0.45512.</p>",
      "rawMarkdown": "Thanks for sharing.\nand can you share your details code in data augmentation.\nmy code is just applied affine,fliplr,flipud.and my best private score is  0.45512."
    },
    {
      "id": 452151,
      "postDate": "2019-01-08T09:20:17.617Z",
      "content": "<p>Awesome</p>",
      "rawMarkdown": "Awesome"
    },
    {
      "id": 450669,
      "postDate": "2019-01-05T14:03:12.957Z",
      "rawMarkdown": "",
      "isDeleted": true
    },
    {
      "id": 453674,
      "postDate": "2019-01-10T15:38:08.460Z",
      "content": "<p>Thanks for the informative article</p>",
      "rawMarkdown": "Thanks for the informative article"
    }
  ],
  "comments": [
    {
      "id": 451261,
      "author_name": "Kevin Lu",
      "author_url": "",
      "post_date": "2019-01-06T18:23:09.863000",
      "content": "<p>Thanks for sharing! I wanted to ask a few questions: \nThe workflow is:\n1. Create crops from original tif images\n2. Train network on crops</p>\n\n<p>After network is finished training\n1. Calculate confidence of each image crop and keep the images with high probability for second rounding training. \n2. Train network on the image crops with high confidence.</p>\n\n<p>I have two questions:\n1. What do you mean by confidence? Is this the probability calculated by the CNN for the correct classes?\n2. What is used to calculate the weights for each image crop?</p>\n\n<p>Thanks again for sharing!</p>",
      "votes": 3,
      "replies": [
        {
          "id": 452000,
          "author_name": "Appian",
          "author_url": "",
          "post_date": "2019-01-08T02:45:17.717000",
          "content": "<p>Thank you for summarzing.</p>\n\n<ol>\n<li><p>Yes, it is outputs from cnn after softmax. Using softmax might be wrong for multilabel problem though. </p></li>\n<li><p>Blue channel intensity is used for weights.</p></li>\n</ol>\n\n<blockquote>\n  <ol>\n  <li>Calculate confidence of each image crop and keep the images with high probability for second rounding training.</li>\n  <li>Train network on the image crops with high confidence.</li>\n  </ol>\n</blockquote>\n\n<p>This part can be repeated for better accuracy by the way.</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 452236,
          "author_name": "README",
          "author_url": "",
          "post_date": "2019-01-08T11:57:09.537000",
          "content": "<p>Hi Appian, are you label the patch which means whether can represent the original tiff image manually？</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 452315,
          "author_name": "Basti",
          "author_url": "",
          "post_date": "2019-01-08T14:58:07.443000",
          "content": "<blockquote>\n  <p>Blockquote 2. Blue channel intensity is used for weights.</p>\n</blockquote>\n\n<p>by that I think you actually mean green channel intensity right?</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 452639,
          "author_name": "Appian",
          "author_url": "",
          "post_date": "2019-01-09T01:21:21.817000",
          "content": "<p><a href=\"/shangweichen\">@shangweichen</a>\nDo you mean by hand? No, there are too many to label by hand. Labels of each patch are given by labels of original image and outputs of cnn.</p>\n\n<p><a href=\"/bastini\">@bastini</a>\nYes, the green channel is right. Thank you for correcting.</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 452757,
          "author_name": "Zhen Cao",
          "author_url": "",
          "post_date": "2019-01-09T05:55:47.773000",
          "content": "<p>Hi Appian, I have a question about calculate confidence of each image crop. Do you mean predict the confidence score for training set with the trained model, or predict the confidence score for validation set with 5 fold to obtain the confidence score for whole train data? </p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 452773,
          "author_name": "Appian",
          "author_url": "",
          "post_date": "2019-01-09T06:21:35.347000",
          "content": "<p>I use 5 folds to obtain scores for train data in oof manner.</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 452818,
          "author_name": "Zhen Cao",
          "author_url": "",
          "post_date": "2019-01-09T07:40:11.650000",
          "content": "<p>Thsnks for your reply! what do you mean in oof manner? By the way, How did you split your 5 folds? random?</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 452387,
      "author_name": "Basti",
      "author_url": "",
      "post_date": "2019-01-08T16:53:25.570000",
      "content": "<p>Thanks for sharing this! The Idea of removeing bad images was crucial for me.\nI have two questions that I don't have enough time left answering myself or need for reference:</p>\n\n<ol>\n<li>What LR did you use? For me 1e-5 works best but seems to be really low. Maybe I should start with a higher one and decrease it after a few Epochs. </li>\n<li>How many Epochs dose a typical training take you? With my LR and letting training finish it takes 50-80 Epochs.</li>\n</ol>\n\n<p>Thanks again!</p>",
      "votes": 1,
      "replies": [
        {
          "id": 452637,
          "author_name": "Appian",
          "author_url": "",
          "post_date": "2019-01-09T01:20:29.503000",
          "content": "<ol>\n<li><p>I use 8e-4 with 0.9 decay per epoch and batch size 32. I can not say much about your lr is low or not. The proper lr is not easy to find for me too and affected by many things such as batch size.</p></li>\n<li><p>A single model can reach ~0.6 public lb and ~0.66 local cv in several epochs from pretrained imagenet. I now train a few more epochs to see what happens.</p></li>\n</ol>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 451592,
      "author_name": "Chenglu",
      "author_url": "",
      "post_date": "2019-01-07T10:21:47.927000",
      "content": "<p>Very interesting idea, it's like detection but the region of interest is picked by hand. I was wandering that can we build a proposal network to first pickup the region of interest and then feed that region to a classification network.</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 451281,
      "author_name": "pete",
      "author_url": "",
      "post_date": "2019-01-06T19:03:21.787000",
      "content": "<p>Congratulations on your success. I started something similar a while back but did not pursue it as I wondered whether the signal would survive cropping. Perhaps only parts of the image lead to the correct label. Looks like that doesn't happen.</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 451217,
      "author_name": "Heisenger",
      "author_url": "",
      "post_date": "2019-01-06T16:04:52.887000",
      "content": "<p>Thanks for sharing your ideas. May I ask how you create the patches? I am a total beginner so any hints would be very much appreciated! \nBest</p>",
      "votes": 1,
      "replies": [
        {
          "id": 452004,
          "author_name": "Appian",
          "author_url": "",
          "post_date": "2019-01-08T02:49:05.953000",
          "content": "<p>Generating 25 patches from 2048x2048 image is like</p>\n\n<p><code>\nsize = 512 \noverlap = 128\nx_split = 5\ny_split = 5\nfor i in range(x_split):\n    for j in range(y_split):\n        patch = image[\n            i*size - i*overlap: (i+1)*size - i*overlap,\n            j*size - j*overlap: (j+1)*size - j*overlap\n        ]\n        dst = os.path.join(dstdir, f'{name}_x{i}_y{j}.png')\n        cv2.imwrite(dst, patch)\n</code></p>",
          "votes": 5,
          "replies": []
        },
        {
          "id": 452238,
          "author_name": "Heisenger",
          "author_url": "",
          "post_date": "2019-01-08T12:03:37.827000",
          "content": "<p>Thankyou!</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 453006,
          "author_name": "Heisenger",
          "author_url": "",
          "post_date": "2019-01-09T13:47:32.187000",
          "content": "<p>Probably a silly question but may I check if I understand it correctly:</p>\n\n<p>1) train with crops of high confidence images: this helps speed up 2nd stage classification as it focuses on most informative regions and doesn't have to learn to discard the relatively uninformative regions (these were discarded / given low weights before 2nd stage)</p>\n\n<p>2) These crops were created as a weighted combination of the green channel intensity (similar effect I  guess can be created by doing a dimensionality reduction, say using autoencoders / PCA)</p>\n\n<p>3) how did you come to pick the size of the particular crop? Would it not be the case that for different pictures with different cell sizes (although i understand the magnification of these images are assumed constant) require crops of different sizes to ensure all details are captured?</p>\n\n<p>Thanks a lot for any help!!</p>\n\n<p>Best</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 450977,
      "author_name": "Master",
      "author_url": "",
      "post_date": "2019-01-06T07:29:19.053000",
      "content": "<p>Thanks for the share. I just joined this competition, can I ask which model you are using?</p>",
      "votes": 1,
      "replies": [
        {
          "id": 451047,
          "author_name": "Appian",
          "author_url": "",
          "post_date": "2019-01-06T10:55:56.823000",
          "content": "<p>se_resnext50 from <a href=\"https://github.com/creafz/pytorch-cnn-finetune\">https://github.com/creafz/pytorch-cnn-finetune</a> with a bit of tuning.</p>",
          "votes": 4,
          "replies": []
        }
      ]
    },
    {
      "id": 450912,
      "author_name": "spectre",
      "author_url": "",
      "post_date": "2019-01-06T04:30:36.983000",
      "content": "<p>Thanks for your share ,which is your lb with single model?</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 450906,
      "author_name": "Iafoss",
      "author_url": "",
      "post_date": "2019-01-06T03:52:42.327000",
      "content": "<p>I tried exactly the same approach on the original data (384x384 crops selected quisirandomly based on the intensity of the green channel to produce ~250k images), but it failed miserably. Probably, <strong>the key is using the external data</strong>.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 451046,
          "author_name": "Appian",
          "author_url": "",
          "post_date": "2019-01-06T10:55:04.153000",
          "content": "<p>Not all of patches are useful for training. You probably get a better result by classifying which patch is useful for training and which patch confuses the model on top of green channel intensity. And yes HPAv18 helps.</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 451230,
          "author_name": "DavidGbodiOdaibo",
          "author_url": "",
          "post_date": "2019-01-06T16:41:08.453000",
          "content": "<p>used the same approach without external data, large 896 x 896 patches because of label noise to get as much of the label in patches but lb score is not great. I did not use green channel to guide patch selection too lazy unfortunately.</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 452317,
          "author_name": "Basti",
          "author_url": "",
          "post_date": "2019-01-08T15:02:26.597000",
          "content": "<p>Same here, kind of the same approach but using blue channel to detect cell positions first and then made a crop around them. I also failed miserably, even when using external data. I think using AlexNet was not the best choice even though it got the best results so far (0.376 publicLB).</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 450879,
      "author_name": "Ildoo Kim",
      "author_url": "",
      "post_date": "2019-01-06T01:55:19.553000",
      "content": "<p>Thanks for the informative article, but I'm a bit of confused. Original TIF have diverse of sizes(2048, 3k, ...) and also HPAv18 have 512x512 images. Do you resize them to the same sizes before training?</p>",
      "votes": 1,
      "replies": [
        {
          "id": 451045,
          "author_name": "Appian",
          "author_url": "",
          "post_date": "2019-01-06T10:53:20.557000",
          "content": "<p>HPAv18 actually has 2048x2048 and something like 1768x1768 and I resized them to 1768x1768. Original tif images are resized to 2048x2048. The size of patch is always 512x512 but with different overlap values.</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 450709,
      "author_name": "phalanx",
      "author_url": "",
      "post_date": "2019-01-05T14:58:23.350000",
      "content": "<p>Thanks Appian.<br>\nI have one question.<br>\nwhat is publicLB for a single model?</p>",
      "votes": 1,
      "replies": [
        {
          "id": 450748,
          "author_name": "Appian",
          "author_url": "",
          "post_date": "2019-01-05T16:50:49.317000",
          "content": "<p>A single fold: ~0.6\n5-folds average: ~0.61</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 450751,
          "author_name": "phalanx",
          "author_url": "",
          "post_date": "2019-01-05T17:03:33.337000",
          "content": "<p>you are amazing, thanks!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 451829,
      "author_name": "mariadata",
      "author_url": "",
      "post_date": "2019-01-07T18:30:51.493000",
      "content": "<p>cool</p>",
      "votes": 2,
      "replies": []
    },
    {
      "id": 450652,
      "author_name": "tkuanlun350",
      "author_url": "",
      "post_date": "2019-01-05T13:24:29.590000",
      "content": "<p>Good work !\nI did something similar but only reach ~0.56, may I ask some question ?\nDid you use green channel to indicate the area to crop ? \nif not,  why using fixed patch instead of random crop on the fly  ?</p>",
      "votes": 2,
      "replies": [
        {
          "id": 450671,
          "author_name": "Appian",
          "author_url": "",
          "post_date": "2019-01-05T14:05:09.713000",
          "content": "<p>Thanks. Good to hear someone tried a similar approach.</p>\n\n<p>I use green channel to tell which patch is more informative than others. Patches with relatively small green channel value are discarded before training for example.</p>\n\n<p>Random crop should work as well but you need to keep track of how you cropped that image anyway. Because you later use trained cnn to give confidence score on each of cropped images to determine you use that image for training or not. In my case fixed patch was just more convinient.</p>",
          "votes": 4,
          "replies": []
        },
        {
          "id": 450683,
          "author_name": "tkuanlun350",
          "author_url": "",
          "post_date": "2019-01-05T14:24:00.817000",
          "content": "<p>Thanks for your reply, very informative ! </p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 451596,
      "author_name": "Karthik",
      "author_url": "",
      "post_date": "2019-01-07T10:27:46.267000",
      "content": "<p>My First Comment</p>",
      "votes": -3,
      "replies": [
        {
          "id": 452005,
          "author_name": "Appian",
          "author_url": "",
          "post_date": "2019-01-08T02:51:13.200000",
          "content": "<p>Have fun kaggling!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 456876,
      "author_name": "Jaideep",
      "author_url": "",
      "post_date": "2019-01-16T17:27:50.610000",
      "content": "<p>hi appian\nthanks for posting in solution... could you share the script to use the external data,preprocessng,download </p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 455081,
      "author_name": "Gabriel",
      "author_url": "",
      "post_date": "2019-01-12T23:28:24.223000",
      "content": "<p>Did you get a chance to try this approach with diverse models? Either way, cool approach. I like how you saw beyond the label not captured in smaller crop assumption. An elegant countermeasure.</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 454823,
      "author_name": "Harleys Zhang",
      "author_url": "",
      "post_date": "2019-01-12T09:35:40.037000",
      "content": "<p>Thanks for sharing.\nand can you share your details code in data augmentation.\nmy code is just applied affine,fliplr,flipud.and my best private score is  0.45512.</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 452151,
      "author_name": "gzsong",
      "author_url": "",
      "post_date": "2019-01-08T09:20:17.617000",
      "content": "<p>Awesome</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 450669,
      "author_name": "",
      "author_url": "",
      "post_date": "2019-01-05T14:03:12.957000",
      "content": "",
      "votes": 0,
      "replies": []
    },
    {
      "id": 453674,
      "author_name": "ABHISHEK ARYA",
      "author_url": "",
      "post_date": "2019-01-10T15:38:08.460000",
      "content": "<p>Thanks for the informative article</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "450614": "I train cnn with image patches of original tif. I share some information just in case someone is interested. Your input is welcome.\n\n- 272x272 input (resized from 512x512 image patch)\n- batch size 32\n- kaggle data and HPAv18 (without uncertain)\n- oversample uncommon classes x2 (8,9,10,15,16,17,20,24,26,27)\n- bcewithlogitsloss\n- fliplr, flipud, scale, rotate, shear, contrast, multiply\n- 5 folds\n- ensemble\n- no tta\n\nFirst each of original tif images are split into to more than 20 patches. After training, outputs of cnn are used as confidence which tells you how much the corresponding patch represents labels of the original image. I use patches with high confidence to train a new model for better accuray. At last I apply weighted average on cnn outputs of image patches to predict labels of the original image.",
    "451261": "Thanks for sharing! I wanted to ask a few questions: \nThe workflow is:\n1. Create crops from original tif images\n2. Train network on crops\n\nAfter network is finished training\n1. Calculate confidence of each image crop and keep the images with high probability for second rounding training. \n2. Train network on the image crops with high confidence.\n\nI have two questions:\n1. What do you mean by confidence? Is this the probability calculated by the CNN for the correct classes?\n2. What is used to calculate the weights for each image crop?\n\nThanks again for sharing!\n",
    "452387": "Thanks for sharing this! The Idea of removeing bad images was crucial for me.\nI have two questions that I don't have enough time left answering myself or need for reference:\n\n1. What LR did you use? For me 1e-5 works best but seems to be really low. Maybe I should start with a higher one and decrease it after a few Epochs. \n2. How many Epochs dose a typical training take you? With my LR and letting training finish it takes 50-80 Epochs.\n\nThanks again!",
    "451592": "Very interesting idea, it's like detection but the region of interest is picked by hand. I was wandering that can we build a proposal network to first pickup the region of interest and then feed that region to a classification network.",
    "451281": "Congratulations on your success. I started something similar a while back but did not pursue it as I wondered whether the signal would survive cropping. Perhaps only parts of the image lead to the correct label. Looks like that doesn't happen.",
    "451217": "Thanks for sharing your ideas. May I ask how you create the patches? I am a total beginner so any hints would be very much appreciated! \nBest",
    "450977": "Thanks for the share. I just joined this competition, can I ask which model you are using?",
    "450912": "Thanks for your share ,which is your lb with single model?",
    "450906": "I tried exactly the same approach on the original data (384x384 crops selected quisirandomly based on the intensity of the green channel to produce ~250k images), but it failed miserably. Probably, **the key is using the external data**.",
    "450879": "Thanks for the informative article, but I'm a bit of confused. Original TIF have diverse of sizes(2048, 3k, ...) and also HPAv18 have 512x512 images. Do you resize them to the same sizes before training?\n\n",
    "450709": "Thanks Appian.<br>\nI have one question.<br>\nwhat is publicLB for a single model?",
    "451829": "cool",
    "450652": "Good work !\nI did something similar but only reach ~0.56, may I ask some question ?\nDid you use green channel to indicate the area to crop ? \nif not,  why using fixed patch instead of random crop on the fly  ?",
    "451596": "My First Comment",
    "456876": "hi appian\nthanks for posting in solution... could you share the script to use the external data,preprocessng,download ",
    "455081": "Did you get a chance to try this approach with diverse models? Either way, cool approach. I like how you saw beyond the label not captured in smaller crop assumption. An elegant countermeasure.",
    "454823": "Thanks for sharing.\nand can you share your details code in data augmentation.\nmy code is just applied affine,fliplr,flipud.and my best private score is  0.45512.",
    "452151": "Awesome",
    "450669": "",
    "453674": "Thanks for the informative article"
  }
}