{
  "id": 238028,
  "title": "what I learnt so far",
  "url": "/competitions/hubmap-kidney-segmentation/discussion/238028",
  "author_name": "Drzhuzhe",
  "post_date": "2021-05-11T02:07:17.799000",
  "votes": 1,
  "comment_count": 0,
  "views": 0,
  "content": "<ol>\n<li>pseudo label (not hand label) define help to robust  <br>\npseudo label give no improve in LB but 0.003 improve on private </li>\n<li>threshold 0.4 is better than 0.3 about 0.003 improve </li>\n<li>data augmentation is critical </li>\n</ol>\n<p>when using TPU, I cannot use ablu np.function </p>\n<p>so this augmentation only get 9.40 on private board and 9.30 on LB</p>\n<pre><code>def _parse_image_function(example_proto, seed, augment = True):\n    image_feature_description = {\n        'image': tf.io.FixedLenFeature([], tf.string),\n        'mask': tf.io.FixedLenFeature([], tf.string)\n    }\n    single_example = tf.io.parse_single_example(example_proto, image_feature_description)\n    image = tf.reshape( tf.io.decode_raw(single_example['image'],out_type=np.dtype('uint8')), (DIM,DIM, 3))\n    mask =  tf.reshape(tf.io.decode_raw(single_example['mask'],out_type='bool'),(DIM,DIM,1))\n\n    if augment:\n        # 这里代码要改一下 和取 tfrecord分开\n        # https://www.tensorflow.org/tutorials/images/data_augmentation#apply_the_preprocessing_layers_to_the_datasets\n\n        if tf.random.uniform(()) &gt; 0.5:\n            image = tf.image.flip_left_right(image)\n            mask = tf.image.flip_left_right(mask)    \n        # shiftscalerotate 0.25\n        if tf.random.uniform(()) &gt; 0.4:            \n            image = tf.image.flip_up_down(image)            #if tf.random.uniform(()) &gt; 0.75:\n            mask = tf.image.flip_up_down(mask)\n\n        #image = tf.image.stateless_random_flip_left_right(image, seed) \n        #mask = tf.image.stateless_random_flip_left_right(mask, seed) \n\n        #image = tf.image.stateless_random_flip_up_down(image, seed)\n        #mask = tf.image.stateless_random_flip_up_down(mask, seed)\n\n        if tf.random.uniform(()) &gt; 0.5:\n            image = tf.image.rot90(image)\n            mask = tf.image.rot90(mask)      \n        # shiftscalerotate 0.25\n\n        #if tf.random.uniform(()) &gt; 0.75:\n        #    image = tf.image.stateless_random_crop(image, size=[cutDIM, cutDIM, 3], seed=seed)\n        #    mask = tf.image.stateless_random_crop(mask, size=[cutDIM, cutDIM, 1], seed=seed)\n\n        #  随机调整色调\n        if tf.random.uniform(()) &gt; 0.75:\n            image = tf.image.stateless_random_hue(image, 0.2, seed=seed)    \n\n        #  图片质量 这个好像会造成反向优化\n        #if tf.random.uniform(()) &gt; 0.7:\n        #    image = tf.image.stateless_random_jpeg_quality(image, 75, 95, seed)\n\n        if tf.random.uniform(()) &gt; 0.75:\n            image = tf.image.stateless_random_saturation(image, 0.7, 1.3, seed=seed)\n\n        if tf.random.uniform(()) &gt; 0.75:\n            image = tf.image.stateless_random_contrast(image, lower=0.8, upper=1.2, seed=seed)\n\n        if tf.random.uniform(()) &gt; 0.75:\n            image = tf.image.stateless_random_brightness(image, max_delta=0.95, seed=seed)\n\n    return tf.cast(image, tf.float32), tf.cast(mask, tf.float32)\n</code></pre>\n<p>but this one get 9.47 on private LB and 9.30 on public LB</p>\n<pre><code>tfms = [\n        alb.OneOf([\n            alb.RandomBrightness(limit=.2, p=1), \n            alb.RandomContrast(limit=.2, p=1), \n            alb.RandomGamma(p=1)\n        ], p=.5),\n        alb.OneOf([\n            alb.Blur(blur_limit=3, p=1),\n            alb.MedianBlur(blur_limit=3, p=1)\n        ], p=.25),\n        alb.OneOf([\n            alb.GaussNoise(0.002, p=.5),\n            alb.IAAAffine(p=.5),\n        ], p=.25),\n        alb.OneOf([\n            alb.ElasticTransform(alpha=120, sigma=120 * .05, alpha_affine=120 * .03, p=.5),\n            alb.GridDistortion(p=.5),\n            alb.OpticalDistortion(distort_limit=2, shift_limit=.5, p=1)                  \n        ], p=.25),\n        alb.RandomRotate90(p=.5),\n        alb.HorizontalFlip(p=.5),\n        alb.VerticalFlip(p=.5),\n        alb.Cutout(num_holes=10, \n                    max_h_size=int(.1 * size), max_w_size=int(.1 * size), \n                    p=.25),\n        alb.ShiftScaleRotate(p=.5)\n    ]\n</code></pre>\n<ol>\n<li>higher resolution to the key to championship</li>\n<li>TTA, stratified k-fold cannot be ignore</li>\n</ol>\n<p>summary</p>\n<ol>\n<li><p>on submit you shall submit one best CV and one best LB </p></li>\n<li><p>a faster baseline with good validation method is better that spend too much time in tuning</p></li>\n</ol>",
  "messages": [
    {
      "id": 1301265,
      "postDate": "2021-05-11T02:07:17.800Z",
      "content": "<ol>\n<li>pseudo label (not hand label) define help to robust  <br>\npseudo label give no improve in LB but 0.003 improve on private </li>\n<li>threshold 0.4 is better than 0.3 about 0.003 improve </li>\n<li>data augmentation is critical </li>\n</ol>\n<p>when using TPU, I cannot use ablu np.function </p>\n<p>so this augmentation only get 9.40 on private board and 9.30 on LB</p>\n<pre><code>def _parse_image_function(example_proto, seed, augment = True):\n    image_feature_description = {\n        'image': tf.io.FixedLenFeature([], tf.string),\n        'mask': tf.io.FixedLenFeature([], tf.string)\n    }\n    single_example = tf.io.parse_single_example(example_proto, image_feature_description)\n    image = tf.reshape( tf.io.decode_raw(single_example['image'],out_type=np.dtype('uint8')), (DIM,DIM, 3))\n    mask =  tf.reshape(tf.io.decode_raw(single_example['mask'],out_type='bool'),(DIM,DIM,1))\n\n    if augment:\n        # 这里代码要改一下 和取 tfrecord分开\n        # https://www.tensorflow.org/tutorials/images/data_augmentation#apply_the_preprocessing_layers_to_the_datasets\n\n        if tf.random.uniform(()) &gt; 0.5:\n            image = tf.image.flip_left_right(image)\n            mask = tf.image.flip_left_right(mask)    \n        # shiftscalerotate 0.25\n        if tf.random.uniform(()) &gt; 0.4:            \n            image = tf.image.flip_up_down(image)            #if tf.random.uniform(()) &gt; 0.75:\n            mask = tf.image.flip_up_down(mask)\n\n        #image = tf.image.stateless_random_flip_left_right(image, seed) \n        #mask = tf.image.stateless_random_flip_left_right(mask, seed) \n\n        #image = tf.image.stateless_random_flip_up_down(image, seed)\n        #mask = tf.image.stateless_random_flip_up_down(mask, seed)\n\n        if tf.random.uniform(()) &gt; 0.5:\n            image = tf.image.rot90(image)\n            mask = tf.image.rot90(mask)      \n        # shiftscalerotate 0.25\n\n        #if tf.random.uniform(()) &gt; 0.75:\n        #    image = tf.image.stateless_random_crop(image, size=[cutDIM, cutDIM, 3], seed=seed)\n        #    mask = tf.image.stateless_random_crop(mask, size=[cutDIM, cutDIM, 1], seed=seed)\n\n        #  随机调整色调\n        if tf.random.uniform(()) &gt; 0.75:\n            image = tf.image.stateless_random_hue(image, 0.2, seed=seed)    \n\n        #  图片质量 这个好像会造成反向优化\n        #if tf.random.uniform(()) &gt; 0.7:\n        #    image = tf.image.stateless_random_jpeg_quality(image, 75, 95, seed)\n\n        if tf.random.uniform(()) &gt; 0.75:\n            image = tf.image.stateless_random_saturation(image, 0.7, 1.3, seed=seed)\n\n        if tf.random.uniform(()) &gt; 0.75:\n            image = tf.image.stateless_random_contrast(image, lower=0.8, upper=1.2, seed=seed)\n\n        if tf.random.uniform(()) &gt; 0.75:\n            image = tf.image.stateless_random_brightness(image, max_delta=0.95, seed=seed)\n\n    return tf.cast(image, tf.float32), tf.cast(mask, tf.float32)\n</code></pre>\n<p>but this one get 9.47 on private LB and 9.30 on public LB</p>\n<pre><code>tfms = [\n        alb.OneOf([\n            alb.RandomBrightness(limit=.2, p=1), \n            alb.RandomContrast(limit=.2, p=1), \n            alb.RandomGamma(p=1)\n        ], p=.5),\n        alb.OneOf([\n            alb.Blur(blur_limit=3, p=1),\n            alb.MedianBlur(blur_limit=3, p=1)\n        ], p=.25),\n        alb.OneOf([\n            alb.GaussNoise(0.002, p=.5),\n            alb.IAAAffine(p=.5),\n        ], p=.25),\n        alb.OneOf([\n            alb.ElasticTransform(alpha=120, sigma=120 * .05, alpha_affine=120 * .03, p=.5),\n            alb.GridDistortion(p=.5),\n            alb.OpticalDistortion(distort_limit=2, shift_limit=.5, p=1)                  \n        ], p=.25),\n        alb.RandomRotate90(p=.5),\n        alb.HorizontalFlip(p=.5),\n        alb.VerticalFlip(p=.5),\n        alb.Cutout(num_holes=10, \n                    max_h_size=int(.1 * size), max_w_size=int(.1 * size), \n                    p=.25),\n        alb.ShiftScaleRotate(p=.5)\n    ]\n</code></pre>\n<ol>\n<li>higher resolution to the key to championship</li>\n<li>TTA, stratified k-fold cannot be ignore</li>\n</ol>\n<p>summary</p>\n<ol>\n<li><p>on submit you shall submit one best CV and one best LB </p></li>\n<li><p>a faster baseline with good validation method is better that spend too much time in tuning</p></li>\n</ol>",
      "rawMarkdown": "1. pseudo label (not hand label) define help to robust  \npseudo label give no improve in LB but 0.003 improve on private \n2. threshold 0.4 is better than 0.3 about 0.003 improve \n3. data augmentation is critical \n\nwhen using TPU, I cannot use ablu np.function \n\nso this augmentation only get 9.40 on private board and 9.30 on LB\n```\ndef _parse_image_function(example_proto, seed, augment = True):\n    image_feature_description = {\n        'image': tf.io.FixedLenFeature([], tf.string),\n        'mask': tf.io.FixedLenFeature([], tf.string)\n    }\n    single_example = tf.io.parse_single_example(example_proto, image_feature_description)\n    image = tf.reshape( tf.io.decode_raw(single_example['image'],out_type=np.dtype('uint8')), (DIM,DIM, 3))\n    mask =  tf.reshape(tf.io.decode_raw(single_example['mask'],out_type='bool'),(DIM,DIM,1))\n        \n    if augment:\n        # 这里代码要改一下 和取 tfrecord分开\n        # https://www.tensorflow.org/tutorials/images/data_augmentation#apply_the_preprocessing_layers_to_the_datasets\n        \n        if tf.random.uniform(()) > 0.5:\n            image = tf.image.flip_left_right(image)\n            mask = tf.image.flip_left_right(mask)    \n        # shiftscalerotate 0.25\n        if tf.random.uniform(()) > 0.4:\t        \n            image = tf.image.flip_up_down(image)\t        #if tf.random.uniform(()) > 0.75:\n            mask = tf.image.flip_up_down(mask)\n            \n        #image = tf.image.stateless_random_flip_left_right(image, seed) \n        #mask = tf.image.stateless_random_flip_left_right(mask, seed) \n\n        #image = tf.image.stateless_random_flip_up_down(image, seed)\n        #mask = tf.image.stateless_random_flip_up_down(mask, seed)\n\n        if tf.random.uniform(()) > 0.5:\n            image = tf.image.rot90(image)\n            mask = tf.image.rot90(mask)      \n        # shiftscalerotate 0.25\n        \n        #if tf.random.uniform(()) > 0.75:\n        #    image = tf.image.stateless_random_crop(image, size=[cutDIM, cutDIM, 3], seed=seed)\n        #    mask = tf.image.stateless_random_crop(mask, size=[cutDIM, cutDIM, 1], seed=seed)\n        \n        #  随机调整色调\n        if tf.random.uniform(()) > 0.75:\n            image = tf.image.stateless_random_hue(image, 0.2, seed=seed)    \n        \n        #  图片质量 这个好像会造成反向优化\n        #if tf.random.uniform(()) > 0.7:\n        #    image = tf.image.stateless_random_jpeg_quality(image, 75, 95, seed)\n            \n        if tf.random.uniform(()) > 0.75:\n            image = tf.image.stateless_random_saturation(image, 0.7, 1.3, seed=seed)\n            \n        if tf.random.uniform(()) > 0.75:\n            image = tf.image.stateless_random_contrast(image, lower=0.8, upper=1.2, seed=seed)\n        \n        if tf.random.uniform(()) > 0.75:\n            image = tf.image.stateless_random_brightness(image, max_delta=0.95, seed=seed)\n        \n    return tf.cast(image, tf.float32), tf.cast(mask, tf.float32)\n```\n\nbut this one get 9.47 on private LB and 9.30 on public LB\n\n```\ntfms = [\n        alb.OneOf([\n            alb.RandomBrightness(limit=.2, p=1), \n            alb.RandomContrast(limit=.2, p=1), \n            alb.RandomGamma(p=1)\n        ], p=.5),\n        alb.OneOf([\n            alb.Blur(blur_limit=3, p=1),\n            alb.MedianBlur(blur_limit=3, p=1)\n        ], p=.25),\n        alb.OneOf([\n            alb.GaussNoise(0.002, p=.5),\n            alb.IAAAffine(p=.5),\n        ], p=.25),\n        alb.OneOf([\n            alb.ElasticTransform(alpha=120, sigma=120 * .05, alpha_affine=120 * .03, p=.5),\n            alb.GridDistortion(p=.5),\n            alb.OpticalDistortion(distort_limit=2, shift_limit=.5, p=1)                  \n        ], p=.25),\n        alb.RandomRotate90(p=.5),\n        alb.HorizontalFlip(p=.5),\n        alb.VerticalFlip(p=.5),\n        alb.Cutout(num_holes=10, \n                    max_h_size=int(.1 * size), max_w_size=int(.1 * size), \n                    p=.25),\n        alb.ShiftScaleRotate(p=.5)\n    ]\n```\n4. higher resolution to the key to championship\n5. TTA, stratified k-fold cannot be ignore\n\n\nsummary\n\n1. on submit you shall submit one best CV and one best LB \n\n2. a faster baseline with good validation method is better that spend too much time in tuning\n\n",
      "votes": 1
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "1301265": "1. pseudo label (not hand label) define help to robust  \npseudo label give no improve in LB but 0.003 improve on private \n2. threshold 0.4 is better than 0.3 about 0.003 improve \n3. data augmentation is critical \n\nwhen using TPU, I cannot use ablu np.function \n\nso this augmentation only get 9.40 on private board and 9.30 on LB\n```\ndef _parse_image_function(example_proto, seed, augment = True):\n    image_feature_description = {\n        'image': tf.io.FixedLenFeature([], tf.string),\n        'mask': tf.io.FixedLenFeature([], tf.string)\n    }\n    single_example = tf.io.parse_single_example(example_proto, image_feature_description)\n    image = tf.reshape( tf.io.decode_raw(single_example['image'],out_type=np.dtype('uint8')), (DIM,DIM, 3))\n    mask =  tf.reshape(tf.io.decode_raw(single_example['mask'],out_type='bool'),(DIM,DIM,1))\n        \n    if augment:\n        # 这里代码要改一下 和取 tfrecord分开\n        # https://www.tensorflow.org/tutorials/images/data_augmentation#apply_the_preprocessing_layers_to_the_datasets\n        \n        if tf.random.uniform(()) > 0.5:\n            image = tf.image.flip_left_right(image)\n            mask = tf.image.flip_left_right(mask)    \n        # shiftscalerotate 0.25\n        if tf.random.uniform(()) > 0.4:\t        \n            image = tf.image.flip_up_down(image)\t        #if tf.random.uniform(()) > 0.75:\n            mask = tf.image.flip_up_down(mask)\n            \n        #image = tf.image.stateless_random_flip_left_right(image, seed) \n        #mask = tf.image.stateless_random_flip_left_right(mask, seed) \n\n        #image = tf.image.stateless_random_flip_up_down(image, seed)\n        #mask = tf.image.stateless_random_flip_up_down(mask, seed)\n\n        if tf.random.uniform(()) > 0.5:\n            image = tf.image.rot90(image)\n            mask = tf.image.rot90(mask)      \n        # shiftscalerotate 0.25\n        \n        #if tf.random.uniform(()) > 0.75:\n        #    image = tf.image.stateless_random_crop(image, size=[cutDIM, cutDIM, 3], seed=seed)\n        #    mask = tf.image.stateless_random_crop(mask, size=[cutDIM, cutDIM, 1], seed=seed)\n        \n        #  随机调整色调\n        if tf.random.uniform(()) > 0.75:\n            image = tf.image.stateless_random_hue(image, 0.2, seed=seed)    \n        \n        #  图片质量 这个好像会造成反向优化\n        #if tf.random.uniform(()) > 0.7:\n        #    image = tf.image.stateless_random_jpeg_quality(image, 75, 95, seed)\n            \n        if tf.random.uniform(()) > 0.75:\n            image = tf.image.stateless_random_saturation(image, 0.7, 1.3, seed=seed)\n            \n        if tf.random.uniform(()) > 0.75:\n            image = tf.image.stateless_random_contrast(image, lower=0.8, upper=1.2, seed=seed)\n        \n        if tf.random.uniform(()) > 0.75:\n            image = tf.image.stateless_random_brightness(image, max_delta=0.95, seed=seed)\n        \n    return tf.cast(image, tf.float32), tf.cast(mask, tf.float32)\n```\n\nbut this one get 9.47 on private LB and 9.30 on public LB\n\n```\ntfms = [\n        alb.OneOf([\n            alb.RandomBrightness(limit=.2, p=1), \n            alb.RandomContrast(limit=.2, p=1), \n            alb.RandomGamma(p=1)\n        ], p=.5),\n        alb.OneOf([\n            alb.Blur(blur_limit=3, p=1),\n            alb.MedianBlur(blur_limit=3, p=1)\n        ], p=.25),\n        alb.OneOf([\n            alb.GaussNoise(0.002, p=.5),\n            alb.IAAAffine(p=.5),\n        ], p=.25),\n        alb.OneOf([\n            alb.ElasticTransform(alpha=120, sigma=120 * .05, alpha_affine=120 * .03, p=.5),\n            alb.GridDistortion(p=.5),\n            alb.OpticalDistortion(distort_limit=2, shift_limit=.5, p=1)                  \n        ], p=.25),\n        alb.RandomRotate90(p=.5),\n        alb.HorizontalFlip(p=.5),\n        alb.VerticalFlip(p=.5),\n        alb.Cutout(num_holes=10, \n                    max_h_size=int(.1 * size), max_w_size=int(.1 * size), \n                    p=.25),\n        alb.ShiftScaleRotate(p=.5)\n    ]\n```\n4. higher resolution to the key to championship\n5. TTA, stratified k-fold cannot be ignore\n\n\nsummary\n\n1. on submit you shall submit one best CV and one best LB \n\n2. a faster baseline with good validation method is better that spend too much time in tuning\n\n"
  }
}