{
  "id": 75673,
  "title": "Image Convertation",
  "url": "/competitions/human-protein-atlas-image-classification/discussion/75673",
  "author_name": "",
  "post_date": "2018-12-24T19:55:38.767433800Z",
  "votes": null,
  "comment_count": 6,
  "views": 0,
  "content": "<p>I'm thinking, is it ok to assemble image from 4 layers in the following way? </p>\n\n<pre><code>flags = cv2.IMREAD_UNCHANGED\n\nred = cv2.imread(os.path.join(path, id+'_red'+'.png'), flags).astype(np.float32)/255\ngreen = cv2.imread(os.path.join(path, id+'_green'+'.png'), flags).astype(np.float32)/255\nblue = cv2.imread(os.path.join(path, id+'_blue'+'.png'), flags).astype(np.float32)/255\nyellow = cv2.imread(os.path.join(path, id+'_yellow'+'.png'), flags).astype(np.float32)/255\npad = np.zeros((512, 512), dtype=np.float32)\nimg = cv2.merge((red, green, blue)) + cv2.merge((yellow, yellow, pad))\n</code></pre>\n\n<p>As far as I understand it returns nice 3 dimensional image without losing yellow layer.</p>",
  "messages": [
    {
      "id": "444788",
      "postDate": "12/24/2018 19:55:38",
      "content": "<p>I'm thinking, is it ok to assemble image from 4 layers in the following way? </p>\n\n<pre><code>flags = cv2.IMREAD_UNCHANGED\n\nred = cv2.imread(os.path.join(path, id+'_red'+'.png'), flags).astype(np.float32)/255\ngreen = cv2.imread(os.path.join(path, id+'_green'+'.png'), flags).astype(np.float32)/255\nblue = cv2.imread(os.path.join(path, id+'_blue'+'.png'), flags).astype(np.float32)/255\nyellow = cv2.imread(os.path.join(path, id+'_yellow'+'.png'), flags).astype(np.float32)/255\npad = np.zeros((512, 512), dtype=np.float32)\nimg = cv2.merge((red, green, blue)) + cv2.merge((yellow, yellow, pad))\n</code></pre>\n\n<p>As far as I understand it returns nice 3 dimensional image without losing yellow layer.</p>",
      "rawMarkdown": "I'm thinking, is it ok to assemble image from 4 layers in the following way? \n\n\tflags = cv2.IMREAD_UNCHANGED\n\n    red = cv2.imread(os.path.join(path, id+'_red'+'.png'), flags).astype(np.float32)/255\n\tgreen = cv2.imread(os.path.join(path, id+'_green'+'.png'), flags).astype(np.float32)/255\n\tblue = cv2.imread(os.path.join(path, id+'_blue'+'.png'), flags).astype(np.float32)/255\n\tyellow = cv2.imread(os.path.join(path, id+'_yellow'+'.png'), flags).astype(np.float32)/255\n\tpad = np.zeros((512, 512), dtype=np.float32)\n\timg = cv2.merge((red, green, blue)) + cv2.merge((yellow, yellow, pad))\n\nAs far as I understand it returns nice 3 dimensional image without losing yellow layer.",
      "votes": null
    },
    {
      "id": "444790",
      "postDate": "12/24/2018 20:25:49",
      "content": "<p>No, you're adding yellow to red and green channels. My understanding is, you'll mess up some information in those channels. If you want to use 4 channels, change your ConvNet's 1st layer accordingly.</p>",
      "rawMarkdown": "No, you're adding yellow to red and green channels. My understanding is, you'll mess up some information in those channels. If you want to use 4 channels, change your ConvNet's 1st layer accordingly.",
      "votes": null
    },
    {
      "id": "444798",
      "postDate": "12/24/2018 20:51:32",
      "content": "<p>Take a look at the resulting image, please. Is it wrong in some way? Are those 4 separate channels overlap somehow?</p>",
      "rawMarkdown": "Take a look at the resulting image, please. Is it wrong in some way? Are those 4 separate channels overlap somehow?",
      "votes": null
    },
    {
      "id": "444824",
      "postDate": "12/24/2018 23:25:06",
      "content": "<p>@CatEek,</p>\n\n<p>Something you might try:</p>\n\n<p>The way I convert from 4 channels to 3 for input to a pre-trained model (inception_v3 for example) in R + Keras is to insert a 1x1 kernel  2d convolutional layer with 3 output filters (but no activation function) before the inception_v3.  Then training can optimize the parameters of the convolutional layer, which essentially outputs a linear transform of its input.</p>",
      "rawMarkdown": "CatEek,\n\nSomething you might try:\n\nThe way I convert from 4 channels to 3 for input to a pre-trained model (inception_v3 for example) in R + Keras is to insert a 1x1 kernel  2d convolutional layer with 3 output filters (but no activation function) before the inception_v3.  Then training can optimize the parameters of the convolutional layer, which essentially outputs a linear transform of its input.",
      "votes": null
    },
    {
      "id": "444830",
      "postDate": "12/24/2018 23:39:24",
      "content": "<p>Thanks for your answer. I am going to try this approach in the nearest future. But i am particularly interested in different way to combine layers. Maybe just like I posted, or divide resulting image by 2. Or maybe multiply RBG by yellow layer. Just want to understand the principle. By the way, approach that I posted gave 0.300 public LB after several submissions with different threshold on a ResNet34 trained from scratch without any data augmentation.</p>",
      "rawMarkdown": "Thanks for your answer. I am going to try this approach in the nearest future. But i am particularly interested in different way to combine layers. Maybe just like I posted, or divide resulting image by 2. Or maybe multiply RBG by yellow layer. Just want to understand the principle. By the way, approach that I posted gave 0.300 public LB after several submissions with different threshold on a ResNet34 trained from scratch without any data augmentation.",
      "votes": null
    },
    {
      "id": "445059",
      "postDate": "12/25/2018 14:09:01",
      "content": "<p>You're packing 4 channels into 3. Of course, they will overlap.</p>",
      "rawMarkdown": "You're packing 4 channels into 3. Of course, they will overlap.",
      "votes": null
    },
    {
      "id": "445152",
      "postDate": "12/25/2018 19:02:15",
      "content": "<p>Thanks for your reply.  I think I got the point.</p>",
      "rawMarkdown": "Thanks for your reply.  I think I got the point.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 444790,
      "author_name": "artyomp",
      "author_url": "",
      "post_date": "12/24/2018 20:25:49",
      "content": "<p>No, you're adding yellow to red and green channels. My understanding is, you'll mess up some information in those channels. If you want to use 4 channels, change your ConvNet's 1st layer accordingly.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 444798,
      "author_name": "cateek",
      "author_url": "",
      "post_date": "12/24/2018 20:51:32",
      "content": "<p>Take a look at the resulting image, please. Is it wrong in some way? Are those 4 separate channels overlap somehow?</p>",
      "votes": null,
      "replies": [
        {
          "id": 445059,
          "author_name": "artyomp",
          "author_url": "",
          "post_date": "12/25/2018 14:09:01",
          "content": "<p>You're packing 4 channels into 3. Of course, they will overlap.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 445152,
          "author_name": "cateek",
          "author_url": "",
          "post_date": "12/25/2018 19:02:15",
          "content": "<p>Thanks for your reply.  I think I got the point.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 444824,
      "author_name": "dslate",
      "author_url": "",
      "post_date": "12/24/2018 23:25:06",
      "content": "<p>@CatEek,</p>\n\n<p>Something you might try:</p>\n\n<p>The way I convert from 4 channels to 3 for input to a pre-trained model (inception_v3 for example) in R + Keras is to insert a 1x1 kernel  2d convolutional layer with 3 output filters (but no activation function) before the inception_v3.  Then training can optimize the parameters of the convolutional layer, which essentially outputs a linear transform of its input.</p>",
      "votes": null,
      "replies": [
        {
          "id": 444830,
          "author_name": "cateek",
          "author_url": "",
          "post_date": "12/24/2018 23:39:24",
          "content": "<p>Thanks for your answer. I am going to try this approach in the nearest future. But i am particularly interested in different way to combine layers. Maybe just like I posted, or divide resulting image by 2. Or maybe multiply RBG by yellow layer. Just want to understand the principle. By the way, approach that I posted gave 0.300 public LB after several submissions with different threshold on a ResNet34 trained from scratch without any data augmentation.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "444788": "I'm thinking, is it ok to assemble image from 4 layers in the following way? \n\n\tflags = cv2.IMREAD_UNCHANGED\n\n    red = cv2.imread(os.path.join(path, id+'_red'+'.png'), flags).astype(np.float32)/255\n\tgreen = cv2.imread(os.path.join(path, id+'_green'+'.png'), flags).astype(np.float32)/255\n\tblue = cv2.imread(os.path.join(path, id+'_blue'+'.png'), flags).astype(np.float32)/255\n\tyellow = cv2.imread(os.path.join(path, id+'_yellow'+'.png'), flags).astype(np.float32)/255\n\tpad = np.zeros((512, 512), dtype=np.float32)\n\timg = cv2.merge((red, green, blue)) + cv2.merge((yellow, yellow, pad))\n\nAs far as I understand it returns nice 3 dimensional image without losing yellow layer.",
    "444790": "No, you're adding yellow to red and green channels. My understanding is, you'll mess up some information in those channels. If you want to use 4 channels, change your ConvNet's 1st layer accordingly.",
    "444798": "Take a look at the resulting image, please. Is it wrong in some way? Are those 4 separate channels overlap somehow?",
    "444824": "CatEek,\n\nSomething you might try:\n\nThe way I convert from 4 channels to 3 for input to a pre-trained model (inception_v3 for example) in R + Keras is to insert a 1x1 kernel  2d convolutional layer with 3 output filters (but no activation function) before the inception_v3.  Then training can optimize the parameters of the convolutional layer, which essentially outputs a linear transform of its input.",
    "444830": "Thanks for your answer. I am going to try this approach in the nearest future. But i am particularly interested in different way to combine layers. Maybe just like I posted, or divide resulting image by 2. Or maybe multiply RBG by yellow layer. Just want to understand the principle. By the way, approach that I posted gave 0.300 public LB after several submissions with different threshold on a ResNet34 trained from scratch without any data augmentation.",
    "445059": "You're packing 4 channels into 3. Of course, they will overlap.",
    "445152": "Thanks for your reply.  I think I got the point."
  },
  "source": "meta"
}